Implementing the Function Context and Adding Annotations
The Process Server uses a Java framework that supports custom function extensions. This framework is a set of Java interfaces and classes made available for your use. IAeFunction and IAeFunctionContext are implemented to create the objects that are accessible to the engine at run-time. AeFunctionCallException and AeUnresolvableException are used to signal fault conditions. These types are resolved using the org.activebpel.rt.bpel package in ae_rtbpel.jar. Additionally, AeUnresolvableException extends AeException provided in ae_rt.jar.
You can use custom functions in any expression language.
Step 1: Create a Function Context
Your first task is to create a function context that is a new class that implements the IAeFunctionContext interface.
This class exposes one public method: getFunction(String). It returns an object of a type that implements the IAeFunction interface. The method uses the String argument to indicate the local name of the function and then select that object.You can implement multiple custom functions via one function context class. getFunction() throws an AeUnresolvableException if it is unable to locate the desired function by name.
Annotations
You add the @AeFunctionContext annotation to annotate the class at class level.
Add the @AeFunctionUnit annotation at the method level, for each function unit that you want to display in the Expression Builder function list.
The following example shows the function context:
@AeFunctionContext(name="myContext", namespace="myns")
public class CustomContext implements IAeFunctionContext
{
@AeFunctionUnit(
prefix = "ld",
display = "MyLDAP",
hoverText = "My LDAP Functions",
functions = {
@AeFunction(
syntax = "${prefix}:getOrgUnit(${caret})",
display = "getOrgUnit(id)",
hoverText = "Returns OU details"),
@AeFunction(
syntax = "${prefix}:getSiblings(${caret})",
display = "getSiblings(id)",
hoverText = "Returns siblings nodes"),
}
)
public IAeFunction getFunction(String aFunctionName)
throws AeUnresolvableException
{
}
}
where:
- •@AeFunctionContext name is the display name of the function context in the Process Console Catalog
- • @AeFunctionUnit represents a group of functions
- - prefix is used for all functions in the unit
- - display is the unit name in the Expression Builder function list
- - hoverText is the unit's hover help
- - functions is the list of functions
- • @AeFunction represents the function
- - syntax is the syntax of the function added to the Expression text box when the function is double-clicked. Note that the syntax includes the ${prefix} and the ${caret}. The cursor appears in the column set by the caret token.
- - display is the function name in the Expression Builder function list
- - hoverText is the function's hover help
Step 2: Create the Custom Function
Your second task is to create the actual custom functions, each of which implements the IAeFunction interface. These also expose one single public method: call(IAeFunctionExecutionContext, List); it performs the function's task that you create. The function's argument list (if any) is passed to the call method using the List argument. This function may optionally use the function execution IAeFunctionExecutionContext as needed. Individual custom functions should throw AeFunctionCallException, constructed to contain the root exception message, if they encounter a problem that prevents them from finishing their task.
Step3: Create the Package
Once you have created your function context and function classes, and tested the classes that do the actual custom function work, you can create a contribution. All the function contexts in the project are automatically packaged when you create a deployment contribution.
The custom functions are available only to the BPEL files in the contribution or in a contribution in another project that references this project. Note that the custom functions are listed on the Catalog Resources page of the Export Business Process Archive, either as project resource dependencies, referenced dependencies, or if they are not referenced, they are listed as additional resources. For details, see
Deploying Project Dependencies and Viewing Excluded Dependencies.