You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ka...@apache.org on 2009/01/23 23:20:41 UTC
svn commit: r737207 - in /ode/branches/APACHE_ODE_1.X:
bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerImpl.java
bpel-test/src/test/resources/bpel/2.0/TestAssignActivity2/TestAssign.bpel
Author: karthick
Date: Fri Jan 23 14:20:40 2009
New Revision: 737207
URL: http://svn.apache.org/viewvc?rev=737207&view=rev
Log:
ODE-498 Compile all XPath variable references, no matter where they appear.
Modified:
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerImpl.java
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestAssignActivity2/TestAssign.bpel
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerImpl.java?rev=737207&r1=737206&r2=737207&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerImpl.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerImpl.java Fri Jan 23 14:20:40 2009
@@ -19,7 +19,9 @@
package org.apache.ode.bpel.elang.xpath20.compiler;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
@@ -30,6 +32,7 @@
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
+import net.sf.saxon.om.Name11Checker;
import net.sf.saxon.om.NamespaceConstant;
import net.sf.saxon.xpath.XPathEvaluator;
import net.sf.saxon.xpath.XPathFactoryImpl;
@@ -147,14 +150,22 @@
XPath xpe = xpf.newXPath();
xpe.setXPathFunctionResolver(funcResolver);
xpe.setXPathVariableResolver(varResolver);
- xpe.setNamespaceContext(source.getNamespaceContext());
+ xpe.setNamespaceContext(source.getNamespaceContext());
XPathExpression expr = xpe.compile(xpathStr);
// evaluate the expression so as to initialize the variables
try {
- expr.evaluate(node);
+ expr.evaluate(node);
} catch (XPathExpressionException xpee) {
// swallow errors caused by uninitialized variable
}
+ for (String varExpr : extractVariableExprs(xpathStr)) {
+ expr = xpe.compile(varExpr);
+ try {
+ expr.evaluate(node);
+ } catch (XPathExpressionException xpee) {
+ // swallow errors caused by uninitialized variable
+ }
+ }
} catch (XPathFactoryConfigurationException xpfce) {
__log.debug(xpfce);
__log.info("Couldn't validate properly expression " + xpathStr);
@@ -170,7 +181,54 @@
}
}
- public Map<String, String> getProperties() {
+ /**
+ * Returns the list of variable references in the given XPath expression
+ * that may not have been resolved properly, which is the case especially
+ * if the expression contains a function, which short circuited the evaluation.
+ *
+ * @param xpathStr
+ * @return list of variable expressions that may not have been resolved properly
+ */
+ private List<String> extractVariableExprs(String xpathStr) {
+ ArrayList<String> variableExprs = new ArrayList<String>();
+ if (xpathStr.indexOf("$") > 0 && // the xpath references a variable
+ xpathStr.indexOf("(") > 0) { // the xpath contains a function
+ // most likely, the variable reference has not been resolved, so make that happen
+ StringBuffer variableExpr = new StringBuffer();
+ boolean quoted = false, doubleQuoted = false, variable = false;
+ Name11Checker nameChecker = Name11Checker.getInstance();
+ for (int index = 0; index < xpathStr.length(); index++) {
+ char ch = xpathStr.charAt(index);
+ if (ch == '\''){
+ quoted = !quoted;
+ }
+ if (ch == '\"') {
+ doubleQuoted = !doubleQuoted;
+ }
+ if (quoted || doubleQuoted){
+ continue;
+ }
+ if (ch == '$') {
+ variable = true;
+ variableExpr.setLength(0);
+ variableExpr.append(ch);
+ } else {
+ if (variable) {
+ variableExpr.append(ch);
+ if (index == xpathStr.length() ||
+ !nameChecker.isQName(variableExpr.substring(1))) {
+ variable = false;
+ variableExpr.setLength(variableExpr.length() - 1);
+ variableExprs.add(variableExpr.toString());
+ }
+ }
+ }
+ }
+ }
+ return variableExprs;
+ }
+
+ public Map<String, String> getProperties() {
return _properties;
}
Modified: ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestAssignActivity2/TestAssign.bpel
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestAssignActivity2/TestAssign.bpel?rev=737207&r1=737206&r2=737207&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestAssignActivity2/TestAssign.bpel (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestAssignActivity2/TestAssign.bpel Fri Jan 23 14:20:40 2009
@@ -43,6 +43,7 @@
<variable name="myVar" messageType="test:TestAssignMessage"/>
<variable name="otherMsgVar" messageType="test:TestAssignMessage"/>
<variable name="strVar" type="xsd:string"/>
+ <variable name="txtVar" type="xsd:string"/>
<variable name="intVar" type="xsd:int"/>
</variables>
@@ -77,6 +78,22 @@
<to>$otherMsgVar.TestPart</to>
</copy>
</assign>
+
+ <assign name="assign2">
+ <copy>
+ <from><literal>1</literal></from>
+ <to variable="intVar"/>
+ </copy>
+ <copy>
+ <from>ode:process-property("dd:epr")/addr:EndpointReference/child::node()[position()=$intVar]</from>
+ <to variable="strVar"/>
+ </copy>
+ <copy>
+ <from>ode:process-property("dd:epr")/addr:EndpointReference/child::node()[$intVar]</from>
+ <to variable="strVar"/>
+ </copy>
+ </assign>
+
<reply name="end" partnerLink="TestAssignPartnerLink" portType="test:TestAssignPortType"
operation="testAssign" variable="otherMsgVar"/>
</sequence>