Define your custom XPath extension functions by creating
an XPath function Java™ archive
(JAR) file that contains a Java service
provider plug-in.
About this task
XPath extension functions are implemented as static Java methods. These Java methods are exposed to the process runtime
environment through a Java service
provider plug-in. XPath extension functions can be used only in business
object lazy parsing mode.
Procedure
- In the Java perspective,
create a Java project.
- Add the bpc_apis.jar external JAR
file from the install_root/runtimes/bi_v8_stub/runtimes directory
to your build path, where install_root is the directory
in which IBM® Integration
Designer is
installed.
This JAR file contains the com.ibm.bpe.xpath.spi.XPathExtensionFunctionPlugin interface
and the com.ibm.bpe.xpath.spi.XPathExtensionFunctionDescriptor class,
which are required to create the plug-in.
- Write a public static method that implements the XPath
function.
Each XPath function is implemented as a static Java method, where the following
type mapping applies:
Table 1. XPath to Java type mapping
| XPath type |
Java type |
| string |
java.lang.String |
| number |
java.lang.Number |
| boolean |
java.lang.Boolean or boolean |
| object |
commonj.sdo.DataObject |
| node-set |
java.util.List |
For example, the following Java method implements an XPath function that
takes a node-set and a string as parameters and returns a string.
public static String createDelimitedString(List list, String del) {
StringBuilder sb = new StringBuilder();
if (list.size()< 0) {
sb.append(list.get(0));
for (int i=1; i<list.size(); i++) {
sb.append(del);
sb.append(list.get(i));
}
}
return sb.toString();
}
- To expose your extension functions, implement com.ibm.bpe.xpath.spi.XPathExtensionFunctionPlugin.
Override the
getXPathFunctions method, which
returns a function descriptor for each function that you provide.
For
information about implementing the Java service provider interface, see the Javadoc for the XPathExtensionFunctionPlugin interface in the com.ibm.bpm.xpath.spi package at Reference: Java APIs and SPIs.
The
following sample exposes the
createDelimitedString method
from the previous example, making the method available for all expressions
and conditions.
import com.ibm.bpe.xpath.spi.XPathExtensionFunctionDescriptor;
import com.ibm.bpe.xpath.spi.XPathExtensionFunctionPlugin;
public class MyXPathExtensionFunctionPlugin implements XPathExtensionFunctionPlugin {
@Override
public XPathExtensionFunctionDescriptor[] getXPathFunctions() {
return new XPathExtensionFunctionDescriptor[]{
new XPathExtensionFunctionDescriptor("createDelimitedString",
"http://org.custom.xpath",
"abc",
"org.custom.xpath.XPathExtensionFunctions",
new XPathExtensionFunctionDescriptor.ParameterType[]{XPathExtensionFunctionDescriptor.ParameterType.NODE_SET,
XPathExtensionFunctionDescriptor.ParameterType.STRING},
XPathExtensionFunctionDescriptor.ParameterType.STRING,
XPathExtensionFunctionDescriptor.ALL_EXPRESSION_TYPES)
};
}
}
- Create a service provider configuration file for the plug-in
in the META-INF/services/ directory of your JAR
file.
The configuration file provides the mechanism for
the runtime environment to identify and load the plug-in. This file
conforms to the Java service
provider interface specification.
- Create a file named com.ibm.bpe.xpath.spi.XPathExtensionFunctionPlugin.
- In the first line of the file that is not a comment
line or a blank line, specify the fully qualified name of the plug-in
class that you previously created.
For example, if your
plug-in class is called MyXPathExtensionFunctionPlugin and
is in the org.custom.xpath package, the first
line of the configuration file must be org.custom.xpath.MyXPathExtensionFunctionPlugin.
- Export the JAR file.
What to do next
After you create the XPath function JAR file, you must register
the plug-in with IBM Integration
Designer for
use in the process editor. For more information, see BPEL processes: Registering an XPath function JAR file with IBM Integration Designer.
This topic only applies to BAW, and is located in the BAW repository. Last updated on 2025-03-13 12:15