|
This note has been tested with Tibco Designer 5.6 and Tibco BusinessWorks 5.8.
Tibco BusinessWorks has a very powerful xslt based visual mapper in each task. One can create complex transformations just by dragging lines between input and output elements. Attached to each line one can apply an additional xpath function transformating the input value before mapping it to the output element.
Tibco adds a number of extra functions to the available xpath functions, such that almost any mapping can be done with BusinessWorks out of the box. But very rarely you might have the need to use a function that does not ship with BusinessWorks. In that case it is still possible to write your own custom xpath function, actually that is very easy.
Such a custom function is a special java class that can be attached to your BusinessWorks project by creating a Java Custom Function in BW and supplying the compiled java class to it. See also the java class below. The function concatNtimes concatenates an input field N times separated by a delimiter. Note that I have added a main method to be able to test the function outside BusinessWorks.
package bw.xpath;
public class StringFunctions {
public StringFunctions() {}
public static String concatNtimes(int n, String token, String delim)
{
String result = "";
for (int i=0; i<n; i++) {
result += token +delim;
}
if (n>0) result = result.substring(0, result.length() -delim.length());
return result;
}
public static final String[][] HELP_STRINGS = {
{
"concatNtimes",
"Concatenate the input string a given number of times separated by the input delimiter",
"concat(3, \"xyz\", \"|\")", "xyz|xyz|xyz"
}
};
public static void main(String args[])
{
System.out.println(StringFunctions.concatNtimes(3, "xyz", "|"));
}
}
Recently I had to implement a more complex java custom function. The implementation of this custom function actually took more than one java class. Unfortunately the Java Custom Function resource in BW only takes a single class. To use extra classes in a custom function do the following:
- Package the extra classes in a jar file. The extra classes should be in a different java package than the class for the java custom function.
- Create a resource File Alias in my BW project. Check the boxes classpath and deploy in the File Alias.
- In the menu Designer, Edit, Preferences, tab File Aliases enter the correct file location for the new file alias.
- The previous steps enabled the jar file when deploying the code in an ear file. To enable the jar file in Designer put the jar file in the lib directory of the Tibco Designer installation. Restart Designer.
- Create the Custom Java Function resource in Designer and import the compiled java class defining the "xpath" function into it.
|