Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 18 Functions : Custom Functions

Custom Functions
You can also create custom functions. Custom functions appear in the Custom Function catalog.
Adding Custom Functions
TIBCO BusinessEvents allows you to write your own custom functions in Java and add them to the function registry. When you have added the custom functions to TIBCO BusinessEvents Studio, their catalog appears automatically in the Catalog Functions view, along with the built-in function catalogs.
TIBCO BusinessEvents documentation does not contain detailed instructions for creating custom functions or programming in Java. It is assumed that you are already familiar with programming in Java, and have at a minimum already implemented a class and a static function.
See also:
Task Summary
The steps below summarize the tasks required to integrate your own custom functions with TIBCO BusinessEvents Studio. An additional action is required to make the functions available at runtime.
1.
2.
Create a file called functions.catalog, an XML file that makes it possible to access your custom functions from TIBCO BusinessEvents Studio. You can also include information for a tool tip for each function. See Structure of a Function Catalog for details.
3.
Create a .jar file that includes the static function class files for the implementation and the function catalog file.
4.
The functions are then available for use in any rule editor. (It is not necessary to restart TIBCO BusinessEvents Studio before you can use your functions.)
The locations of the custom function jars are stored in the .beproject configuration file, which is located at the root level of the TIBCO BusinessEvents Studio project. You can check this configuration file into a version control system so that it can be shared with other project developers.
Note that the .beproject file contains other information as well, such as the location of project libraries and so on.
Restrictions on Use of Custom Functions
Note the following restrictions that pertain to using custom functions:
Static and Non-Static Functions
Custom functions must be written in Java and have public static modifiers. As a workaround, encapsulate a non-static function in a static function and compile the encapsulating class to get the .class file.
Return Types
TIBCO BusinessEvents custom functions support the following return types:
Java types supported are: Object, String, Calendar (which displays in TIBCO BusinessEvents as DateTime), Integer, Long, Double, Boolean, int, long, double, and boolean (but not byte, short, float, or char).
Name Overloading
The functions.catalog file makes functions available for use in TIBCO BusinessEvents Studio. The structure of the file requires each function within a class to have a unique name. Because of this structure, you cannot refer to an overloaded function in functions.catalog.
For example, the standard Java library has several String.valueOf() functions overloaded for each primitive type (String.valueOf(int i), String.valueOf(double d) and so on). However, the TIBCO BusinessEvents standard function catalog has a separate function name for each data type: valueOfBoolean(), valueOfDouble(), valueOfInt(), and valueOfLong().
See Structure of a Function Catalog, for more about the functions.catalog file.
Editing Custom Functions
If you need to edit custom functions, you must do so in a Java editor or project, and then re-export them to a custom function JAR. Add the JAR to the TIBCO BusinessEvents project, as explained in Structure of a Function Catalog.
Example Custom Function with Tooltips
The following very simple example of a custom function illustrates the required structure of a function called add, with the Java annotation that displays the tooltip for the function (beginning at @FunctionJavadoc in the example below).

 
package com.acme.functions.string;
   
import com.tibco.be.model.functions.FunctionJavaDoc;
import com.tibco.be.model.functions.FunctionParamDescriptor;
public class StringFunctions {
 
   public @FunctionJavaDoc (
      name="add",
      synopsis="Returns the concatenation of two strings.",
      signature="String add (String a, String b)",
      params={
         @FunctionParamDescriptor(
                     name="a",
                     type="String",
                     desc="param 1"),
         @FunctionParamDescriptor(
                     name="b",
                     type="String",
                     desc="param 2")},
      freturn = @FunctionParamDescriptor
               name="",
               type="String",
               desc="The concatenation of the parameter string"),
 
      version="5.1.0",
      see="",
      mapper=false,
      cautions="none",
      domain={"action","condition","query"},
      example="<br/> " +
            "String result = concatenate(\"a\",\"b\");" +
            "<br/><br/> Result is: result contains: \"ab\"."
   )
   static String add(String a, String b) {
      return a+b; // default impl.
   }

 
The sample above should provide enough guidance. A few additional notes follow.
synopsis  Add the description of the function in the synopsis parameter.
domain  Shows where the function can be used. This text is informational only. It does not appear in the tooltip. The code controlling where the function can be used (and the decorations that appear) is in the function catalog. See <isActionOnly>, <isValidInQuery>, <isValidInBUI> in Table 31, Function Catalog Elements.
version  Specify the version of TIBCO BusinessEvents that this function supports. Informational only.
see  Provide a URL for additional information.
mapper  Set to true if the function uses the XSLT Mapper feature. The Mapper decoration is added if the function catalog has a <mapper> element. In the function catalog file is more detailed code to support use of functions in the XSLT Mapper.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved