Вы находитесь на странице: 1из 3

Creating Custom Xpath Functions in BPEL

steps to do custom xpath function in Oracle BPEL Process Manager 10.1.3.x. This
is very usefull for basic things (Generate Unique Id ID/Custom DateTime Format
etc ) or more complex things as XML operation).

Step 1 - Make a class which implements the IXPathFunction interface


Create a class (UniqueTransactionId) which generates UniqueNumber which doesn't
requires any paramteres:

package com.bpel.xpath;
import java.util.List;
import org.w3c.dom.Node;
import
import
import
import
public

com.collaxa.cube.xml.dom.DOMUtil;
com.oracle.bpel.xml.xpath.IXPathContext;
com.oracle.bpel.xml.xpath.IXPathFunction;
com.oracle.bpel.xml.xpath.XPathFunctionException;
class UniqueTransactionId implements IXPathFunction {

public Object call(IXPathContext context, List args)


throws XPathFunctionException {
// call the business method
return GenerateUniqueNumber();
}

public static synchronized double GenerateUniqueNumber()


{
double uniqueNumber = 0;
String uniqueStr = null;
try {
Thread.sleep(1);
}
catch (Exception exc) {
}
myCurrentTimeUnique = System.currentTimeMillis();
if (myCurrentTimeUnique != myPreviousTimeUnique) {
// this method was not called within the same millisecond
// so we are fine with the time in milliseconds itself
// being unique
localVarUnique = 0;
// reset it (because we entered the a diff ms)
myPreviousTimeUnique = myCurrentTimeUnique;
}
else {
// this means that this method was indeed invoked
// more than once (by concurrent threads) at the same
// millisecond. So, suffix some running number starting from 1
// to this millisecond to make it unique
localVarUnique++;

}
uniqueStr = Long.toString(myCurrentTimeUnique) + localVarUnique;
uniqueNumber = Double.parseDouble(uniqueStr);
return (uniqueNumber);
}

private static long localVarUnique = 0;


private static long myCurrentTimeUnique = 0;
private static long myPreviousTimeUnique = 0;

Step 2 - Register the xpath function to your BPEL domain


Edit the xpath-functions.xml file in the $BPEL_HOME/domains/<<domainName>>/confi
g directory.
Add these following lines into the bpel-xpath-functions tags.
<function id="GenerateUniqueNumber" arity="0">
<classname>com.bpel.xpath.UniqueTransactionId</classname>
<property id="namespace-uri">
<value>http://www.oracle.com/XSL/Transform/java/com.bpel.xpath.UniqueTran
sactionId</value>
<comment>Namespace URI for this function</comment>
</property>
<property id="namespace-prefix">
<value>xpfunc1</value>
<comment>Namespace prefix for this function</comment>
</property>
</function>

Step 3 - Genarate UniqueTransactionId.class file and place the classfile to the


bpel classpath
Create package hirarcy and place the generared class file in $OH/bpel/system/cla
sses/com/bpel/xpath
Similarly generate UniqueTransactionId.jar file and place the jar file in $OH/j2
ee/oc4j_soa/applib/
Now edit the shared library of your application server
* OC4J : $ORACLE_HOME/j2ee/oc4j_soa/config/server.xml

-> locate the shared library called oracle.bpel.common


-> add a tag code-source with your classpath as the others code-source tags.
-> when editing the shared library, simply add your jar file with the others.
Step 4 - Using your new custom xpath function in a BPEL process

To make the Custom Xpath available in jdeveloper we need to unjar the bpm.ide.co
mmon.jar(you can find it under JDEV-HOME/Integration/lib) and update the file or
acle.tib.tools.ide.common.resource.PreBuildExtenstionFunctions.xml and add below
entry at the end.
<functions xmlns:xpfunc1='http://www.oracle.com/XSL/Transform/java/com.bpel
.xpath.UniqueTransactionId'>
<function name="xpfunc1:GenerateUniqueNumb
er" as="string" >
<param name="input" as="string" required
="no"/>
<pcui:ui>
<pcui:mapper palettePage='Advanced Fun
ctions'/>
</pcui:ui>
</function>
</functions>
Now jar bpm.ide.common which includes the updated PreBuildExtenstionFunctions.xm
l file and restart your jdeveloper to use the custom xpath to deploy.
A custom xpath function can be used as any xpath functions. It has to be in an e
xpression field from an assign activity (copy, append, insert after/before, etc.
).
<assign name="UniqueNumber">
<copy>
<from expression="xpfunc1:GenerateUniqueNumber()"/>
<to variable="UniqueID"/>
</copy>
</assign>