Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 7 Java Palette : Java Custom Function

Java Custom Function
Shared Configuration
The Java Custom Function resource allows you to create custom functions to use when mapping data in an activity’s input tab. These functions are also displayed when using the XPath Editor to build an XPath expression.
To create a custom function, you must write the function as a method of a Java class and compile the code into a Java class file. You then load that class file into the project using this resource.
When the class is loaded using this resource, TIBCO ActiveMatrix BusinessWorks inspects the contents of the class and only the class methods that meet the following restrictions are made available in XPath:
Only methods declared as public and static are loaded.
TIBCO ActiveMatrix BusinessWorks provides detailed online help for each XPath function. To provide online help for Java Custom Functions, create a two-dimensional array named HELP_STRINGS in your class. The element containing a string matching the function name is used as the help for that function. See Example Java Function for an example of creating the HELP_STRINGS array.
 
If there are different classes that have methods with the same names, the Prefix field allows you to specify a prefix for qualifying which method you want to use in an XPath function. See the description of the Prefix field below for more information.
See TIBCO ActiveMatrix BusinessWorks Process Design for more information about building XPath expressions and using the XPath editor.
Configuration
The Configuration tab has the following fields.
For example, if you have class1.method1 and class2.method1, you will need to specify class1 in the Suggested Prefix field when you load class1 into a Java Custom Resource. You would specify class2 in the Suggested Prefix field when loading class2. When using method1 in XPath expressions, you must qualify which method1 you are using by specifying class1:method1 or class2:method1 in the XPath expression.
Note: This field is used to locate the file initially, but the file is actually loaded and stored in the repository. Once the file is loaded, it can be removed from its original location in the file system. If you want to change the file stored in the repository, you can use this field to reload a changed file or load a new file for this resource.
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 will not be 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 will not be 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 will not be availabe because it
      * returns nothing: its void.
      */
      public static void returnsNothing(String s)
      {
         System.out.println(s);
      }
 
      /**
      * The following method will not be available because it
      * is not static.
      */
      public int add(int rhs)
      {
         return mInternalValue + rhs;
      }
 
      /**
      * The following method will not be 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)"},
}
 

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved