XPath in BPEL processes
The BPEL 2.0 spec requires support of XPath 1.0 as the query and expression language of BPEL processes. It provides extension points to support other languages as well.
The XPath 1.0 spec defines a core function library that implementations must always include in the context of evaluation. It further allows custom functions to be available as well. BPEL 2.0 itself specifies a few functions to aid in describing business process behavior. It is common for BPEL implementations to provide extension functions and devise a mechanism for users to add their own functions. The next section describes such mechanism for jBPM BPEL.
Introducing Jaxen
jBPM BPEL uses the Jaxen engine for XPath expression evaluation. The Jaxen documentation includes a guide to writing extension functions. The guide has two parts. The first part tells how to write a class that represents a function. The second tells about installing the function into Jaxen programatically.
Both parts apply to jBPM BPEL, although the product provides an alternate, declarative way to install functions into Jaxen. To use it, examine the jbpm.cfg.xml file supplied with the jBPM BPEL distro (1.1 GA and later). Notice the following entries:
<string name="resource.expression.functions" value="org/jbpm/bpel/sublang/xpath/expression.functions.xml" ></string> <string name="resource.join.condition.functions" value="org/jbpm/bpel/sublang/xpath/join.condition.functions.xml" ></string> <string name="resource.query.functions" value="org/jbpm/bpel/sublang/xpath/query.functions.xml" ></string>
These entries point to classpath resources within jbpm-bpel.jar which enumerate the functions available to expressions, join conditions and queries. To install additional functions:
copy the functions resource you want to extend to a new file
declare the function in the new file
put the new file in the classpath
point to the new classpath resource from jbpm.cfg.xml
The functions XML file
Let's take expression.functions.xml as example.
<functionContext class="org.jaxen.XPathFunctionContext" xmlns:bpel11="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpel2="http://schemas.xmlsoap.org/ws/2004/03/business-process/"> <function name="bpel11:getVariableData" class="org.jbpm.bpel.sublang.xpath.GetVariableDataFunction" ></function> <function name="bpel11:getVariableProperty" class="org.jbpm.bpel.sublang.xpath.GetVariablePropertyFunction" ></function> <function name="bpel2:getVariableProperty" class="org.jbpm.bpel.sublang.xpath.GetVariablePropertyFunction" ></function> </functionContext>
The table below describes the relevant information items in the file above.
Information Item | Description |
---|---|
/functionContext/@class | The org.jaxen.FunctionContext implementation to instantiate. The implementation used here, org.jaxen.XPathFunctionContext, provides the XPath core function library. |
/functionContext/function/@name | The qualified name that identifies a function. |
/functionContext/function/@class | The Java class that implements a function. As described in the Jaxen guide, this class must implement org.jaxen.Function. |
Comments