Modifying pattern instances by using the IBM Integration API

Add Java™ code to a code plug-in project to modify a pattern instance when the pattern instance is generated by a pattern user.

Before you begin

Before you can complete this task, you must have completed the following tasks:

About this task

You can add Java code to a code plug-in project so that it runs when a pattern instance is generated. To add the Java code, select the Java class that you want to run.
The Java class you select can be created in the following ways:
  • If you added a Java class when you created the code plug-in, then a template Java class is created and added to the project. This class is based on the Pattern Authoring Class template and contains the basic structure required to function correctly.
  • When you follow the steps in this topic to select a Java class, you can optionally create a new Java class. A class created in this way is based on the Pattern Authoring Class template and contains the basic structure required to function correctly.
  • You can write your own Java class. This class must implement the GeneratePatternInstanceTransform interface.
Regardless of how the class is created, you must add your own code within the class to complete the steps you require when the pattern instance is generated. For examples of IBM® Integration API code for completing common tasks, see Developing applications using the IBM Integration API: Example code. For reference information about the IBM Integration API, see IBM Integration API.

Procedure

To select a Java class to run when a pattern instance is generated:

  1. If the Add Java or PHP Code window is not open, in the Pattern Configuration tab of the Pattern Authoring editor, click Add.
    The Add Java or PHP Code window opens.
  2. In the Type of code list, select Java.
  3. In the Class name list, select the name of the class that you want to run when a pattern instance is generated.
    A class is shown in the Class name list if it is in the current workspace and if it implements the GeneratePatternInstanceTransform interface.
  4. Optional: You can create a new Java class:
    1. Click New Java Class.
      The New Pattern Authoring Java Class window opens.
    2. In the Source folder field, click Browse and select the folder in which to store the new Java class file.
    3. Optional: In the Package field, enter the name of the Java package for the new class.
      If you leave this field blank, the default package is used.
    4. Optional: Select Enclosing type and enter an enclosing type in the Enclosing type field.
    5. Enter a name for the new Java class in the Name field.
    6. Optional: Change the Superclass for the new Java class in the Superclass field.
    7. Optional: To add an interface for the new Java class, click Add. The Implemented Interfaces Selection window opens. In the Choose interfaces field, enter the name of the interface that you want to add, select the interface in the Matching items list and click OK. The Implemented Interfaces Selection window closes.
    8. Optional: To remove an interface for the Java class, select the interface in the Interfaces list and click Remove.
    9. Optional: Click Next to view information about the Pattern Authoring Class template, which is used to create the Java class.
    10. Click Finish.
  5. Click OK.
    The Add Java or PHP Code window closes and the Java class is shown in the Java and PHP Code section of the Pattern Configuration tab.
  6. Optional: The Java and PHP code listed in the Java and PHP Code section of the Pattern Configuration tab runs from top to bottom when a pattern instance is generated. To change the order in which the code is run, select the entry you want to move in the Java and PHP Code section and click the Up or Down button to change the position of the entry in the list.

What to do next

In the Java class that you selected to run when the pattern instance is generated, you must now write the code to perform the steps you require. For examples of IBM Integration API code for completing common tasks, see Developing applications using the IBM Integration API: Example code. For information about the Java development views and editors within the IBM App Connect Enterprise Toolkit, see Java Development User Guide - Views and Editors.