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
- 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.
- In the Java perspective, right-click the Java project, and select Properties.
- Select Java Build Path.
- Select the Libraries tab.
- Click Add Variable.
- Select the variable JCN_HOME and click Extend.
- Select jplugin2.jar, and click OK.
- 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.
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)
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;
}