Modifying pattern instances by using Java or PHP

Use Java™ or PHP code to modify pattern instances when the pattern user generates an instance of a user-defined pattern. For example, you can use Java or PHP code to modify the structure of a message flow based on the values of pattern parameters.

When you author user-defined patterns, you can include Java or PHP code to modify pattern instances. This code is run when the pattern user generates an instance of a user-defined pattern and can be used to carry out a number of actions on the pattern.

By using the IBM® Integration API, you can access all the nodes, connections, and pattern parameters in a user-defined pattern. Examples of changes that you can make by using Java code are:

  • Adding, removing, and copying nodes
  • Changing connections between nodes
  • Renaming nodes
  • Changing pattern parameter values and user-defined property values
  • Renaming message flows

By using the PHP API for user-defined patterns, you can access the pattern parameters and the pattern instance name of a user-defined pattern. Examples of changes that you can make by using PHP code are:

  • Marking up ESQL files to change the operation of the ESQL file depending on the value of pattern parameters
  • Taking values from an XML file and using them as pattern parameters
  • Changing pattern parameter values
  • Renaming message flows
  • Running other PHP scripts or Java code

Do not use Java or PHP API code to set the WSDL file name property, or any of the properties set by the WSDL file, on a SOAPInput, SOAPRequest, or SOAPAsyncRequest node in your user-defined pattern. To set the WSDL file name property, see Configuring SOAP nodes for user-defined patterns. To modify other properties on these nodes, select the properties as target properties when you create your user-defined pattern. To select target properties, see Defining the target properties.

Choosing between Java and PHP

IBM Integration Bus contains a Java to PHP bridge, therefore you can complete some pattern authoring tasks by using either Java or PHP. You can choose which language to use based on the existing skills, assets, or libraries within your organization. The IBM Integration Toolkit includes code completion and a debugger for Java, which make Java a good choice for longer or more complex code. PHP written in the IBM Integration Toolkit can be changed and tested without relaunching the workbench, which makes PHP a good choice if you want to change your code and view the results quickly. If you do not have a preference between Java and PHP after considering the skills and assets of your organization and the testing approach, use Java for changes to the structure of the message flow and use PHP to modify text files.

Plug-in packaging

The code you write to modify pattern instances is contained in a separate plug-in from the user-defined pattern. When you create a pattern archive, your code plug-ins are automatically packaged with the generated pattern plug-ins. For more information about packaging user-defined patterns, see Packaging and distributing pattern plug-ins.

Sequence of actions when a pattern user generates a pattern instance

When a pattern user generates an instance of a user-defined pattern, the following actions occur in sequence:
  1. The pattern instance projects are created and all non-message flow files are copied into the workspace.
  2. The message flows in the pattern plug-ins are loaded into memory.
  3. Pattern parameters that are transformed by using XPath expressions are evaluated. If a pattern parameter is disabled by using an XPath expression, its parameter values are not changed. All target properties are set in all message flows within the user-defined pattern based on pattern parameter values.
  4. The Java and PHP code targets are run in top-to-bottom order as they are listed in the Pattern Authoring editor.
  5. The message flows are saved into the pattern instance projects.