Processing complex or repeating elements in a Custom Java transform

You can use the Java™ MbElement class for mapping inputs and outputs that are not simple types with a Custom Java transform.

Using the MbElement class

To use the MbElement class in the Java code that you use in a map, complete the following tasks:
  1. Add the MbElement plug-in (jplugin2.jar) to the build path of the Java project.

    The plug-in is a JAR file that is provided with the IBM® App Connect Enterprise Toolkit. The jplugin2.jar is also available in the classes directory of the server installation.

    1. In the Java perspective, right-click the Java project, and select Properties.
    2. Select Java Build Path.
    3. Select the Libraries tab.
    4. Click Add Variable.
    5. Select the variable JCN_HOME and click Extend.
    6. Select jplugin2.jar, and click OK.
  2. Import the MbElement class into your Java source.
    You must add the following code:
    import com.ibm.broker.plugin.MbElement;

Using the Java DOM API

You can use the Node class from the standard Java DOM API to process complex or repeating elements in a Custom Java transform.

For example, the following code shows a Java method that uses the Node class:

public static Node nodeMove(Node inEl) 

Reusing Java code

If your Java code is likely to be used by multiple solutions, store it in a shared library. You can store the Java code in the same shared library as a message map. Alternatively, you can store the Java code separately in a referenced shared library.

When you define transformations in your map that use Java code, you can define a map in a static library project, a shared library project, an application project, or an integration project. You can define the Java code in one or more Java projects. Your map project must reference these Java projects.
Note: When the map uses Java code available in a shared library, you must create the map in the shared library project where the Java code is available.

Mapping a single non-repeating element

When you map a single non-repeating element input to a single non-repeating element output, you can use a Java method with the following signature:

public static MbElement mbElMove(MbElement inEl)

For example, the following code shows a Java method that copies a sub tree:

public static MbElement mbElMove(MbElement inEl)
      {
		MbElement outEl = null;
		try {
			outEl = inEl.copy();
			outEl.copyElementTree(inEl);
		} catch (MbException e) {
			throw (new RuntimeException(e));
		}
		return outEl;
	}

Mapping a single repeating element

When you map a single repeating element input to an output repeating element, you can use a Java method with the following signature:

public static List<MbElement>; customCompleTypeMove(List<MbElement>; inEls)
For example:
public static List<MbElement> customCompleTypeMove(List<MbElement> inEls)
      {
		List<MbElement> outEls = new ArrayList<MbElement>();
		try {
			Iterator<MbElement> i = inEls.iterator();
			while (i.hasNext()) {
				MbElement inEl = i.next();
				MbElement outEl = inEl.copy();
				// Do some processing of outEl
				outEls.add(outEl);
			}
		} catch (MbException e) {
			throw (new RuntimeException(e));
		}
		return outEls;
	}