Example Java Function
The following Java code implements custom Java functions. The example illustrates which methods of the class meet the restrictions and are therefore available as custom functions in XPath. The example also illustrates methods which do not meet the restrictions, and therefore are not available as custom functions.
package com.tibco;
public class Sample
{
protected int mInternalValue;
/**
* The following method is not available because it is
* a constructor.
*/
public Sample(int value)
{
mInternalValue = value;
}
/**
* This method is used to concat two strings together. It
* must be declared as public static to be made available in
* TIBCO ActiveMatrix BusinessWorks.
*/
public static String stringConcat(String s1, String s2)
{
return s1 + s2;
}
/**
* This method is used to add two ints together. Note, that
* it takes both an int type and an Integer object.
*/
public static int intAdd(int lhs, Integer rhs)
{
return lhs + rhs.intValue();
}
/**
* The following method is not available because it
* throws an exception.
*/
public static int badAdd(int lhs, int rhs)
throws Exception
{
long result = lhs + rhs;
if (result > Integer.MAX_VALUE) {
throw new ArithmeticException();
}
return new Long(result).intValue();
}
/**
* The following method is not availabe because it
* returns nothing: its void.
*/
public static void returnsNothing(String s)
{
System.out.println(s);
}
/**
* The following method is not available because it
* is not static.
*/
public int add(int rhs)
{
return mInternalValue + rhs;
}
/**
* The following method is not available becauses it
* is not public.
*/
protected static int protectedAdd(int lhs, int rhs)
{
return lhs + rhs;
}
/**
* The following is a two-dimensional array that provides the
* online help for functions in this class. Declare an array
* named HELP_STRINGS.
*/
public static final String[][] HELP_STRINGS ={
{"stringConcat", "Joins two strings.",
"Example", "stringConcat(\"test/testDict\",
$input/key)"},
{"intAdd", "Adds two integers.",
"Example", "intAdd(5, $input/myInt)"},
}