Version 10

    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:


    1. copy the functions resource you want to extend to a new file

    2. declare the function in the new file

    3. put the new file in the classpath

    4. 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"
      <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>


    The table below describes the relevant information items in the file above.


    Information Item



    The org.jaxen.FunctionContext implementation to instantiate. The implementation used here, org.jaxen.XPathFunctionContext, provides the XPath core function library.


    The qualified name that identifies a function.


    The Java class that implements a function. As described in the Jaxen guide, this class must implement org.jaxen.Function.