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 2008/10/29 01:11:16 UTC
svn commit: r708740 [1/2] - in /ode/branches/APACHE_ODE_1.X: ./
bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/
bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/api/
bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compil...
Author: karthick
Date: Tue Oct 28 17:11:15 2008
New Revision: 708740
URL: http://svn.apache.org/viewvc?rev=708740&view=rev
Log:
This patch delivers the feature requested in https://issues.apache.org/jira/browse/ODE-369.
Added:
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10BpelFunctions.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20Draft.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/elang/xquery10/
ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/elang/xquery10/o/
ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/elang/xquery10/o/OXQuery10ExpressionBPEL20.java
ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/
ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/
ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10BpelFunctions.java
ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10ExpressionRuntime.java
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/HelloXQueryWorld.bpel
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/HelloXQueryWorld.wsdl
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/deploy.xml
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/test.properties
Modified:
ode/branches/APACHE_ODE_1.X/Rakefile
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20Draft.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/api/CompilerContext.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java
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-compiler/src/test/java/org/apache/ode/bpel/compiler/XPathTest.java
ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java
ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java
ode/branches/APACHE_ODE_1.X/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/java/org/apache/ode/test/DataHandling20Test.java
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestAssignActivity1/test.properties
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestAssignDate/NewDiagram-Pool.bpel
ode/branches/APACHE_ODE_1.X/bpel-test/src/test/resources/bpel/2.0/TestDuration/BugCastDayTimeDurationToDuration-Pool.bpel
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/Namespaces.java
Modified: ode/branches/APACHE_ODE_1.X/Rakefile
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/Rakefile?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/Rakefile (original)
+++ ode/branches/APACHE_ODE_1.X/Rakefile Tue Oct 28 17:11:15 2008
@@ -94,7 +94,7 @@
OPENJPA = ["org.apache.openjpa:openjpa:jar:1.1.0",
"net.sourceforge.serp:serp:jar:1.13.1"]
-SAXON = group("saxon", "saxon-xpath", "saxon-dom", :under=>"net.sf.saxon", :version=>"8.7")
+SAXON = group("saxon", "saxon-xpath", "saxon-dom", "saxon-xqj", :under=>"net.sf.saxon", :version=>"9.x")
SERVICEMIX = group("servicemix-core", "servicemix-shared", "servicemix-services",
:under=>"org.apache.servicemix", :version=>"3.1-incubating")
SPRING = group("spring-beans", "spring-context", "spring-core", "spring-jmx",
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler.java Tue Oct 28 17:11:15 2008
@@ -40,6 +40,8 @@
import javax.wsdl.WSDLException;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -117,6 +119,7 @@
import org.apache.ode.utils.xsd.XsdException;
import org.apache.ode.utils.xsd.SchemaModel;
import org.apache.xerces.xni.parser.XMLEntityResolver;
+import org.w3c.dom.Document;
import org.w3c.dom.Node;
/**
@@ -1646,6 +1649,16 @@
Collections.reverse(rval);
return rval;
}
+
+ public Map<URI, Source> getSchemaSources() {
+ Map<URI, Document> schemaBytes = _wsdlRegistry.getSchemaDocuments();
+ Map<URI, Source> schemaSources = new HashMap<URI, Source>();
+ for (URI uri : schemaBytes.keySet()) {
+ Document document = schemaBytes.get(uri);
+ schemaSources.put(uri, new DOMSource(document));
+ }
+ return schemaSources;
+ }
/**
* Compile external variable declaration.
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20.java Tue Oct 28 17:11:15 2008
@@ -48,6 +48,7 @@
public static final String OASIS_EXPLANG_XPATH_1_0 = "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0";
public static final String OASIS_EXPLANG_XPATH_2_0 = "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0";
+ public static final String OASIS_EXPLANG_XQUERY_1_0 = "urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0";
public BpelCompiler20() throws Exception {
super((WSDLFactory4BPEL) WSDLFactoryBPEL20.newInstance());
@@ -80,6 +81,12 @@
__log.error("Error loading XPath 2.0 Expression Language: it will not be available.");
}
+ try {
+ registerExpressionLanguage(OASIS_EXPLANG_XQUERY_1_0,
+ "org.apache.ode.bpel.elang.xquery10.compiler.XQuery10ExpressionCompilerBPEL20");
+ } catch (Exception e) {
+ __log.error("Error loading XQuery 1.0 Expression Language: it will not be available.");
+ }
}
protected String getBpwsNamespace() {
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20Draft.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20Draft.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20Draft.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelCompiler20Draft.java Tue Oct 28 17:11:15 2008
@@ -48,6 +48,7 @@
public static final String OASIS_EXPLANG_XPATH_1_0 = "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0";
public static final String OASIS_EXPLANG_XPATH_2_0 = "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0";
+ public static final String OASIS_EXPLANG_XQUERY_1_0 = "urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0";
public BpelCompiler20Draft() throws Exception {
super((WSDLFactory4BPEL) WSDLFactoryBPEL20Draft.newInstance());
@@ -76,6 +77,12 @@
"org.apache.ode.bpel.elang.xpath20.compiler.XPath20ExpressionCompilerBPEL20Draft");
} catch (Exception e) {
__log.error("Error loading XPath 2.0 Expression Language: it will not be available.");
+ }
+ try {
+ registerExpressionLanguage(OASIS_EXPLANG_XQUERY_1_0,
+ "org.apache.ode.bpel.elang.xquery10.compiler.XQuery10ExpressionCompilerBPEL20Draft");
+ } catch (Exception e) {
+ __log.error("Error loading XQuery 1.0 Expression Language: it will not be available.");
}
}
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/WSDLRegistry.java Tue Oct 28 17:11:15 2008
@@ -40,6 +40,8 @@
import javax.wsdl.*;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+
import java.io.StringReader;
import java.io.IOException;
import java.net.URI;
@@ -59,6 +61,7 @@
private final Map<URI, byte[]> _schemas = new HashMap<URI,byte[]>();
private final Map<URI, String> _internalSchemas = new HashMap<URI, String>();
+ private final Map<URI, Document> _documentSchemas = new HashMap<URI, Document>();
private SchemaModel _model;
@@ -208,8 +211,10 @@
try {
Document doc = DOMUtils.parse(new InputSource(new StringReader(schema)));
String schemaTargetNS = doc.getDocumentElement().getAttribute("targetNamespace");
- if (schemaTargetNS != null && schemaTargetNS.length() > 0)
+ if (schemaTargetNS != null && schemaTargetNS.length() > 0) {
_internalSchemas.put(new URI(schemaTargetNS), schema);
+ _documentSchemas.put(new URI(schemaTargetNS), doc);
+ }
} catch (Exception e) {
throw new RuntimeException("Couldn't parse schema in " + def.getTargetNamespace(), e);
}
@@ -291,4 +296,8 @@
return null;
}
+ Map<URI, Document> getSchemaDocuments() {
+ return _documentSchemas;
+ }
+
}
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/api/CompilerContext.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/api/CompilerContext.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/api/CompilerContext.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/api/CompilerContext.java Tue Oct 28 17:11:15 2008
@@ -18,10 +18,13 @@
*/
package org.apache.ode.bpel.compiler.api;
+import java.net.URI;
import java.util.List;
+import java.util.Map;
import javax.wsdl.Operation;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import org.apache.ode.bpel.compiler.bom.Activity;
import org.apache.ode.bpel.compiler.bom.Expression;
@@ -133,6 +136,7 @@
List<OActivity> getActivityStack();
OActivity getCurrent();
-
+
+ Map<URI, Source> getSchemaSources();
}
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.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/Constants.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/Constants.java Tue Oct 28 17:11:15 2008
@@ -34,7 +34,7 @@
* Extension function
* bpws:getVariableProperty('variableName','propertyName')
*/
- public static final String EXT_FUNCTION_GETVARIABLEPROPRTY = "getVariableProperty";
+ public static final String EXT_FUNCTION_GETVARIABLEPROPERTY = "getVariableProperty";
/**
* Extension function bpws:getLinkStatus('getLinkName')
@@ -65,6 +65,9 @@
public static final String NON_STDRD_FUNCTION_INSERT_AS_LAST_INTO = "insert-as-last-into";
public static final String NON_STDRD_FUNCTION_DELETE = "delete";
public static final String NON_STDRD_FUNCTION_RENAME = "rename";
+
+ public static final String XQUERY_FUNCTION_HANDLER_COMPILER = "org.apache.ode.bpel.elang.xquery10.compiler.XQuery10BpelFunctions";
+ public static final String XQUERY_FUNCTION_HANDLER_RUNTIME = "org.apache.ode.bpel.elang.xquery10.runtime.XQuery10BpelFunctions";
public static boolean isBpelNamespace(String uri){
return Namespaces.WS_BPEL_20_NS.equals(uri) || Namespaces.WSBPEL2_0_FINAL_EXEC.equals(uri)
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.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/JaxpFunctionResolver.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java Tue Oct 28 17:11:15 2008
@@ -65,7 +65,7 @@
throw new WrappedResolverException("Undeclared namespace for " + functionName);
} else if (functionName.getNamespaceURI().equals(_bpelNS)) {
String localName = functionName.getLocalPart();
- if (Constants.EXT_FUNCTION_GETVARIABLEPROPRTY.equals(localName)) {
+ if (Constants.EXT_FUNCTION_GETVARIABLEPROPERTY.equals(localName)) {
return new GetVariableProperty();
} else if (Constants.EXT_FUNCTION_DOXSLTRANSFORM.equals(localName)) {
return new DoXslTransform();
@@ -111,7 +111,7 @@
public Object evaluate(List params) throws XPathFunctionException {
if (params.size() != 2) {
throw new CompilationException(
- __msgs.errInvalidNumberOfArguments(Constants.EXT_FUNCTION_GETVARIABLEPROPRTY));
+ __msgs.errInvalidNumberOfArguments(Constants.EXT_FUNCTION_GETVARIABLEPROPERTY));
}
String varName = (String) params.get(0);
OScope.Variable v = _cctx.resolveVariable(varName);
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.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/SaxonContext.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java Tue Oct 28 17:11:15 2008
@@ -18,23 +18,13 @@
*/
package org.apache.ode.bpel.elang.xpath20.compiler;
-import net.sf.saxon.xpath.StandaloneContext;
-import net.sf.saxon.xpath.XPathFunctionLibrary;
-import net.sf.saxon.trans.Variable;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.trans.StaticError;
-import net.sf.saxon.om.QNameException;
-import net.sf.saxon.om.NameChecker;
+import java.util.List;
+
import net.sf.saxon.Configuration;
-import net.sf.saxon.functions.FunctionLibraryList;
import net.sf.saxon.functions.FunctionLibrary;
-import net.sf.saxon.expr.VariableReference;
-
-import javax.xml.namespace.QName;
-
-import org.apache.ode.utils.Namespaces;
-
-import java.util.List;
+import net.sf.saxon.functions.FunctionLibraryList;
+import net.sf.saxon.xpath.JAXPXPathStaticContext;
+import net.sf.saxon.xpath.XPathFunctionLibrary;
/**
* Hooks on Saxon StandaloneContext to be notified when the compilation
@@ -43,7 +33,7 @@
* at runtime.
* @author mriou <mriou at apache dot org>
*/
-public class SaxonContext extends StandaloneContext {
+public class SaxonContext extends JAXPXPathStaticContext {
private JaxpVariableResolver _varResolver;
private JaxpFunctionResolver _funcResolver;
@@ -66,46 +56,61 @@
oxpfl.setXPathFunctionResolver(_funcResolver);
((FunctionLibraryList)getFunctionLibrary()).addFunctionLibrary(oxpfl);
+
+ setXPathFunctionResolver(funcResolver);
+ setXPathVariableResolver(varResolver);
_varResolver = varResolver;
_funcResolver = funcResolver;
}
+
+ // The following methods don't apply to the JAXPXPathStaticContext interface.
- public Variable declareVariable(String qname, Object initialValue) throws XPathException {
- String prefix;
- String localName;
- final NameChecker checker = getConfiguration().getNameChecker();
- try {
- String[] parts = checker.getQNameParts(qname);
- prefix = parts[0];
- localName = parts[1];
- } catch (QNameException err) {
- throw new StaticError("Invalid QName for variable: " + qname);
- }
- String uri = "";
- if (!("".equals(prefix))) {
- uri = getURIForPrefix(prefix);
- }
-
- _varResolver.resolveVariable(new QName(uri, localName, prefix));
-
- return super.declareVariable(qname, initialValue);
- }
-
- public VariableReference bindVariable(int fingerprint) throws StaticError {
- String localName = getNamePool().getLocalName(fingerprint);
- String prefix = getNamePool().getPrefix(fingerprint);
- String ns = getNamePool().getURI(fingerprint);
- // The prefix is lost by compilation, hardcoding it from the ns.
- if (Namespaces.ODE_EXTENSION_NS.equals(ns)) prefix = "ode";
- if (prefix != null && prefix.length() > 0) prefix = prefix + ":";
- try {
- declareVariable(prefix + localName, null);
- } catch (XPathException e) {
- throw new StaticError(e);
- }
- return super.bindVariable(fingerprint);
- }
-
+// public Variable declareVariable(String qname, Object initialValue) throws XPathException {
+// String prefix;
+// String localName;
+// final NameChecker checker = getConfiguration().getNameChecker();
+// try {
+// String[] parts = checker.getQNameParts(qname);
+// prefix = parts[0];
+// localName = parts[1];
+// } catch (QNameException err) {
+// throw new StaticError("Invalid QName for variable: " + qname);
+// }
+// String uri = "";
+// if (!("".equals(prefix))) {
+// uri = getURIForPrefix(prefix);
+// }
+//
+// _varResolver.resolveVariable(new QName(uri, localName, prefix));
+//
+// return super.declareVariable(qname, initialValue);
+// }
+
+// public VariableReference bindVariable(int fingerprint) throws StaticError {
+// String localName = getNamePool().getLocalName(fingerprint);
+// String prefix = getNamePool().getPrefix(fingerprint);
+// String ns = getNamePool().getURI(fingerprint);
+// // The prefix is lost by compilation, hardcoding it from the ns.
+// if (Namespaces.ODE_EXTENSION_NS.equals(ns)) prefix = "ode";
+// if (prefix != null && prefix.length() > 0) prefix = prefix + ":";
+// try {
+// declareVariable(prefix + localName, null);
+// } catch (XPathException e) {
+// throw new StaticError(e);
+// }
+//// return super.bindVariable(fingerprint);
+// return null;
+// }
+
+// public VariableReference bindVariable(StructuredQName qName) {
+// // The prefix is lost by compilation, hardcoding it from the ns.
+// String prefix = qName.getPrefix();
+// String ns = qName.getNamespaceURI();
+// if (prefix == null && Namespaces.ODE_EXTENSION_NS.equals(ns)) {
+// qName = new StructuredQName("ode", ns, qName.getLocalName());
+// }
+// return super.bindVariable(qName);
+// }
}
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=708740&r1=708739&r2=708740&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 Tue Oct 28 17:11:15 2008
@@ -24,8 +24,13 @@
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import javax.xml.xpath.XPathFactoryConfigurationException;
+import net.sf.saxon.om.NamespaceConstant;
import net.sf.saxon.xpath.XPathEvaluator;
import net.sf.saxon.xpath.XPathFactoryImpl;
@@ -66,7 +71,7 @@
public XPath20ExpressionCompilerImpl(String bpelNS) {
_bpelNS = bpelNS;
_qnLinkStatus = new QName(_bpelNS, Constants.EXT_FUNCTION_GETLINKSTATUS);
- _qnVarProp = new QName(_bpelNS, Constants.EXT_FUNCTION_GETVARIABLEPROPRTY);
+ _qnVarProp = new QName(_bpelNS, Constants.EXT_FUNCTION_GETVARIABLEPROPERTY);
_qnVarData = new QName(_bpelNS, Constants.EXT_FUNCTION_GETVARIABLEDATA);
_qnXslTransform = new QName(_bpelNS, Constants.EXT_FUNCTION_DOXSLTRANSFORM);
@@ -130,20 +135,29 @@
}
out.xpath = xpathStr;
- try {
- __log.debug("Compiling expression " + xpathStr);
- XPathFactoryImpl xpf = new net.sf.saxon.xpath.XPathFactoryImpl();
+ try {
+ __log.debug("Compiling expression " + xpathStr);
+ System.setProperty(
+ "javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON,
+ "net.sf.saxon.xpath.XPathFactoryImpl");
+ XPathFactory xpf = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(
_compilerContext, out, source.getNamespaceContext(), _bpelNS);
- xpf.setXPathFunctionResolver(funcResolver);
JaxpVariableResolver varResolver = new JaxpVariableResolver(_compilerContext, out);
- xpf.setXPathVariableResolver(varResolver);
-
- XPathEvaluator xpe = (XPathEvaluator) xpf.newXPath();
- xpe.setStaticContext(new SaxonContext(xpf.getConfiguration(), varResolver, funcResolver));
+ XPath xpe = xpf.newXPath();
xpe.setXPathFunctionResolver(funcResolver);
+ xpe.setXPathVariableResolver(varResolver);
xpe.setNamespaceContext(source.getNamespaceContext());
- xpe.compile(xpathStr);
+ XPathExpression expr = xpe.compile(xpathStr);
+ // evaluate the expression so as to initialize the variables
+ 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);
} catch (XPathExpressionException e) {
__log.debug(e);
__log.info("Couldn't validate properly expression " + xpathStr);
Added: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10BpelFunctions.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10BpelFunctions.java?rev=708740&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10BpelFunctions.java (added)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10BpelFunctions.java Tue Oct 28 17:11:15 2008
@@ -0,0 +1,162 @@
+package org.apache.ode.bpel.elang.xquery10.compiler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+
+import net.sf.saxon.dom.NodeWrapper;
+import net.sf.saxon.expr.XPathContext;
+import net.sf.saxon.om.Item;
+
+import org.apache.ode.bpel.elang.xpath20.compiler.Constants;
+import org.apache.ode.bpel.elang.xpath20.compiler.JaxpFunctionResolver;
+import org.apache.ode.utils.Namespaces;
+import org.w3c.dom.Node;
+
+
+/**
+ * XQuery-Friendly definition of BPEL functions, which
+ * delegates calls to the JAXP-based function resolver
+ */
+public class XQuery10BpelFunctions {
+ public static final String USER_DATA_KEY_FUNCTION_RESOLVER = "function-resolver";
+ private static final QName WSBPEL_GET_VARIABLE_PROPERTY = new QName(Namespaces.WSBPEL2_0_FINAL_EXEC,
+ Constants.EXT_FUNCTION_GETVARIABLEPROPERTY);
+ private static final QName WSBPEL_GET_VARIABLE_DATA = new QName(Namespaces.WSBPEL2_0_FINAL_EXEC,
+ Constants.EXT_FUNCTION_GETVARIABLEDATA);
+ private static final QName WSBPEL_GET_LINK_STATUS = new QName(Namespaces.WSBPEL2_0_FINAL_EXEC,
+ Constants.EXT_FUNCTION_GETLINKSTATUS);
+ private static final QName WSBPEL_DO_XSL_TRANSFORM = new QName(Namespaces.WSBPEL2_0_FINAL_EXEC,
+ Constants.EXT_FUNCTION_DOXSLTRANSFORM);
+
+ /**
+ * WS-BPEL getVariableProperty function
+ *
+ * @param context context
+ * @param variableName variableName
+ * @param propertyName propertyName
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ public static Object getVariableProperty(XPathContext context,
+ String variableName, String propertyName) throws XPathFunctionException {
+ ArrayList<String> arguments = new ArrayList<String>();
+ arguments.add(variableName);
+ arguments.add(propertyName);
+
+ return evaluate(resolveFunction(context, WSBPEL_GET_VARIABLE_PROPERTY),
+ arguments);
+ }
+
+ /**
+ * WS-BPEL getVariableData function
+ *
+ * @param context context
+ * @param variableName variableName
+ * @param partName partName
+ * @param xpath xpath
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ public static Object getVariableData(XPathContext context,
+ String variableName, String partName, String xpath)
+ throws XPathFunctionException {
+ ArrayList<String> arguments = new ArrayList<String>();
+ arguments.add(variableName);
+ arguments.add(partName);
+ arguments.add(xpath);
+
+ return evaluate(resolveFunction(context, WSBPEL_GET_VARIABLE_DATA),
+ arguments);
+ }
+
+ /**
+ * WS-BPEL doXslTransform function
+ *
+ * @param context context
+ * @param xslUri xslUri
+ * @param sources sources
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ public static Object doXslTransform(XPathContext context, String xslUri,
+ Object sources) throws XPathFunctionException {
+ ArrayList<Object> arguments = new ArrayList<Object>();
+ arguments.add(xslUri);
+ arguments.add(sources);
+
+ return evaluate(resolveFunction(context, WSBPEL_DO_XSL_TRANSFORM),
+ arguments);
+ }
+
+ /**
+ * WS-BPEL getLinkStatus function
+ *
+ * @param context context
+ * @param linkName linkName
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ public static Object getLinkStatus(XPathContext context, String linkName)
+ throws XPathFunctionException {
+ ArrayList<String> arguments = new ArrayList<String>();
+ arguments.add(linkName);
+
+ return evaluate(resolveFunction(context, WSBPEL_GET_LINK_STATUS),
+ arguments);
+ }
+
+ /**
+ * Locates the JAXP equivalent function
+ *
+ * @param context context
+ * @param name name
+ *
+ * @return type
+ */
+ private static XPathFunction resolveFunction(XPathContext context,
+ QName name) {
+ JaxpFunctionResolver funcResolver = null;
+ Item item = context.getCurrentIterator().current();
+
+ if (item instanceof NodeWrapper) {
+ Node node = (Node) ((NodeWrapper) item).getUnderlyingNode();
+
+ if (node != null) {
+ funcResolver = (JaxpFunctionResolver) node.getUserData(USER_DATA_KEY_FUNCTION_RESOLVER);
+ }
+ }
+
+ return funcResolver.resolveFunction(name, 0);
+ }
+
+ /**
+ * Evaluates function against arguments passed by XQuery
+ *
+ * @param function function
+ * @param arguments arguments
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ private static Object evaluate(XPathFunction function, List arguments)
+ throws XPathFunctionException {
+ if (function == null) {
+ throw new XPathFunctionException("Unable to locate function in library");
+ }
+
+ return function.evaluate(arguments);
+ }
+}
Added: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20.java?rev=708740&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20.java (added)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20.java Tue Oct 28 17:11:15 2008
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.elang.xquery10.compiler;
+
+import org.apache.ode.utils.Namespaces;
+
+
+public class XQuery10ExpressionCompilerBPEL20 extends XQuery10ExpressionCompilerImpl {
+
+ public XQuery10ExpressionCompilerBPEL20() {
+ super(Namespaces.WSBPEL2_0_FINAL_EXEC);
+ }
+}
Added: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20Draft.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20Draft.java?rev=708740&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20Draft.java (added)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerBPEL20Draft.java Tue Oct 28 17:11:15 2008
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.bpel.elang.xquery10.compiler;
+
+import org.apache.ode.utils.Namespaces;
+
+public class XQuery10ExpressionCompilerBPEL20Draft extends XQuery10ExpressionCompilerImpl {
+
+ public XQuery10ExpressionCompilerBPEL20Draft() {
+ super(Namespaces.WS_BPEL_20_NS);
+ }
+
+}
Added: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java?rev=708740&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java (added)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java Tue Oct 28 17:11:15 2008
@@ -0,0 +1,397 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.bpel.elang.xquery10.compiler;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.xquery.XQConnection;
+import javax.xml.xquery.XQConstants;
+import javax.xml.xquery.XQDataSource;
+import javax.xml.xquery.XQException;
+import javax.xml.xquery.XQItemType;
+import javax.xml.xquery.XQPreparedExpression;
+import javax.xml.xquery.XQSequence;
+import javax.xml.xquery.XQStaticContext;
+
+import net.sf.saxon.Configuration;
+import net.sf.saxon.om.Validation;
+import net.sf.saxon.xqj.SaxonXQConnection;
+import net.sf.saxon.xqj.SaxonXQDataSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.bpel.compiler.api.ExpressionCompiler;
+import org.apache.ode.bpel.compiler.bom.Expression;
+import org.apache.ode.bpel.elang.xpath10.compiler.XPathMessages;
+import org.apache.ode.bpel.elang.xpath10.compiler.XslCompilationErrorListener;
+import org.apache.ode.bpel.elang.xpath20.compiler.Constants;
+import org.apache.ode.bpel.elang.xpath20.compiler.JaxpFunctionResolver;
+import org.apache.ode.bpel.elang.xpath20.compiler.JaxpVariableResolver;
+import org.apache.ode.bpel.elang.xpath20.compiler.WrappedResolverException;
+import org.apache.ode.bpel.elang.xquery10.o.OXQuery10ExpressionBPEL20;
+import org.apache.ode.bpel.o.OConstantVarType;
+import org.apache.ode.bpel.o.OElementVarType;
+import org.apache.ode.bpel.o.OExpression;
+import org.apache.ode.bpel.o.OLValueExpression;
+import org.apache.ode.bpel.o.OMessageVarType;
+import org.apache.ode.bpel.o.OScope;
+import org.apache.ode.bpel.o.OVarType;
+import org.apache.ode.bpel.o.OXsdTypeVarType;
+import org.apache.ode.bpel.o.OMessageVarType.Part;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.NSContext;
+import org.apache.ode.utils.Namespaces;
+import org.apache.ode.utils.msg.MessageBundle;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+import org.apache.xml.utils.XMLChar;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * XQuery compiler based on the SAXON implementation.
+ */
+public class XQuery10ExpressionCompilerImpl implements ExpressionCompiler {
+
+ protected static final Log __log = LogFactory.getLog(XQuery10ExpressionCompilerImpl.class);
+
+ protected String _bpelNS;
+ protected QName _qnLinkStatus;
+ protected QName _qnVarProp;
+ protected QName _qnVarData;
+ protected QName _qnXslTransform;
+
+ protected final XPathMessages __msgs = MessageBundle.getMessages(XPathMessages.class);
+ protected Map<String, String> _properties = new HashMap<String, String>();
+ protected CompilerContext _compilerContext;
+
+ public XQuery10ExpressionCompilerImpl(String bpelNS) {
+ _bpelNS = bpelNS;
+ _qnLinkStatus = new QName(_bpelNS, Constants.EXT_FUNCTION_GETLINKSTATUS);
+ _qnVarProp = new QName(_bpelNS, Constants.EXT_FUNCTION_GETVARIABLEPROPERTY);
+ _qnVarData = new QName(_bpelNS, Constants.EXT_FUNCTION_GETVARIABLEDATA);
+ _qnXslTransform = new QName(_bpelNS, Constants.EXT_FUNCTION_DOXSLTRANSFORM);
+
+ _properties.put("runtime-class", "org.apache.ode.bpel.elang.xquery10.runtime.XQuery10ExpressionRuntime");
+ TransformerFactory trsf = new net.sf.saxon.TransformerFactoryImpl();
+ XslTransformHandler.getInstance().setTransformerFactory(trsf);
+ }
+
+ public void setCompilerContext(CompilerContext compilerContext) {
+ _compilerContext = compilerContext;
+ XslCompilationErrorListener xe = new XslCompilationErrorListener(compilerContext);
+ XslTransformHandler.getInstance().setErrorListener(xe);
+ }
+
+ /**
+ * @see org.apache.ode.bpel.compiler.api.ExpressionCompiler#compileJoinCondition(java.lang.Object)
+ */
+ public OExpression compileJoinCondition(Object source) throws CompilationException {
+ return _compile((Expression) source, true);
+ }
+
+ /**
+ * @see org.apache.ode.bpel.compiler.api.ExpressionCompiler#compile(java.lang.Object)
+ */
+ public OExpression compile(Object source) throws CompilationException {
+ return _compile((Expression) source, false);
+ }
+
+ /**
+ * @see org.apache.ode.bpel.compiler.api.ExpressionCompiler#compileLValue(java.lang.Object)
+ */
+ public OLValueExpression compileLValue(Object source) throws CompilationException {
+ return (OLValueExpression) _compile((Expression) source, false);
+ }
+
+ /**
+ * @see org.apache.ode.bpel.compiler.api.ExpressionCompiler#compile(java.lang.Object)
+ */
+ private OExpression _compile(org.apache.ode.bpel.compiler.bom.Expression xquery, boolean isJoinCondition)
+ throws CompilationException {
+ OXQuery10ExpressionBPEL20 oexp = new OXQuery10ExpressionBPEL20(_compilerContext.getOProcess(), _qnVarData,
+ _qnVarProp, _qnLinkStatus, _qnXslTransform, isJoinCondition);
+ oexp.namespaceCtx = xquery.getNamespaceContext();
+ doJaxpCompile(oexp, xquery);
+ return oexp;
+ }
+
+ private void doJaxpCompile(OXQuery10ExpressionBPEL20 out, Expression source) throws CompilationException {
+ String xqueryStr;
+ Node node = source.getExpression();
+ if (node == null) {
+ throw new IllegalStateException("XQuery string and xpath node are both null");
+ }
+ if (node.getNodeType() != Node.TEXT_NODE &&
+ node.getNodeType() != Node.ELEMENT_NODE &&
+ node.getNodeType() != Node.CDATA_SECTION_NODE) {
+ throw new CompilationException(__msgs.errUnexpectedNodeTypeForXPath(DOMUtils.domToString(node)));
+ }
+ xqueryStr = DOMUtils.domToString(node);
+ xqueryStr = xqueryStr.trim();
+ if (xqueryStr.length() == 0) {
+ throw new CompilationException(__msgs.warnXPath20Syntax(DOMUtils.domToString(node), "empty string"));
+ }
+
+ try {
+ XQDataSource xqds = new SaxonXQDataSource();
+ XQConnection xqconn = xqds.getConnection();
+
+ __log.debug("Compiling expression " + xqueryStr);
+ Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
+ configuration.setAllNodesUntyped(true);
+ configuration.setHostLanguage(Configuration.XQUERY);
+
+ XQStaticContext staticContext = xqconn.getStaticContext();
+ JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(
+ _compilerContext, out, source.getNamespaceContext(), _bpelNS);
+ JaxpVariableResolver variableResolver = new JaxpVariableResolver(
+ _compilerContext, out);
+
+ XQueryDeclarations declarations = new XQueryDeclarations();
+ NSContext nsContext = source.getNamespaceContext();
+ Set<String> prefixes = nsContext.getPrefixes();
+ for (String prefix : prefixes) {
+ String uri = nsContext.getNamespaceURI(prefix);
+ staticContext.declareNamespace(prefix, uri);
+ if ("".equals(prefix)) {
+ declarations.declareDefaultElementNamespace(uri);
+ } else if ("bpws".equals(prefix)) {
+ declarations.declareNamespace("bpws", "java:" + Constants.XQUERY_FUNCTION_HANDLER_COMPILER);
+ } else {
+ declarations.declareNamespace(prefix, uri);
+ }
+ }
+ declarations.declareVariable(
+ getQName(nsContext, Namespaces.ODE_EXTENSION_NS, "pid"),
+ getQName(nsContext, Namespaces.XML_SCHEMA, "integer"));
+ Map<URI, Source> schemaDocuments = _compilerContext.getSchemaSources();
+ for (URI schemaUri : schemaDocuments.keySet()) {
+ Source schemaSource = schemaDocuments.get(schemaUri);
+ // Don't add schema sources, since our Saxon library is not schema-aware.
+ // configuration.addSchemaSource(schemaSource);
+ }
+ configuration.setSchemaValidationMode(Validation.SKIP);
+ List<OScope.Variable> variables = _compilerContext.getAccessibleVariables();
+ Map<QName, QName> variableTypes = new HashMap<QName, QName>();
+ for (String variableName : getVariableNames(xqueryStr)) {
+ OScope.Variable variable = getVariable(variables, variableName);
+ if (variable == null) {
+ continue;
+ }
+ OVarType type = variable.type;
+ QName nameQName = getNameQName(variableName);
+ QName typeQName = getTypeQName(variableName, type);
+ variableTypes.put(nameQName, typeQName);
+ String prefix = typeQName.getPrefix();
+ if (prefix == null || "".equals(prefix.trim())) {
+ prefix = getPrefixForUri(nsContext, typeQName.getNamespaceURI());
+ }
+ // don't declare typed variables, as our engine is not schema-aware
+ // declarations.declareVariable(variable.name, typeQName);
+ declarations.declareVariable(variableName);
+ }
+
+ // Add implicit declarations as prolog to the user-defined XQuery
+ out.xquery = declarations.toString() + xqueryStr;
+
+ // Check the XQuery for compilation errors
+ xqconn.setStaticContext(staticContext);
+ XQPreparedExpression exp = xqconn.prepareExpression(out.xquery);
+
+ // Pre-evaluate variables and functions by executing query
+ node.setUserData(XQuery10BpelFunctions.USER_DATA_KEY_FUNCTION_RESOLVER,
+ funcResolver, null);
+ exp.bindItem(XQConstants.CONTEXT_ITEM,
+ xqconn.createItemFromNode(node, xqconn.createNodeType()));
+ // Bind external variables to dummy runtime values
+ for (QName variable : exp.getAllUnboundExternalVariables()) {
+ QName typeQName = variableTypes.get(variable);
+ Object value = variableResolver.resolveVariable(variable);
+ if (typeQName != null) {
+ if (value.getClass().getName().startsWith("java.lang")) {
+ exp.bindAtomicValue(variable, value.toString(),
+ xqconn.createAtomicType(XQItemType.XQBASETYPE_ANYATOMICTYPE));
+ } else if (value instanceof Node) {
+ exp.bindNode(variable, (Node) value, xqconn.createNodeType());
+ } else if (value instanceof NodeList) {
+ NodeList nodeList = (NodeList) value;
+ ArrayList nodeArray = new ArrayList();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ nodeArray.add(nodeList.item(i));
+ }
+ XQSequence sequence = xqconn.createSequence(nodeArray.iterator());
+ exp.bindSequence(variable, sequence);
+ }
+ }
+ }
+ exp.executeQuery();
+ } catch (XQException xqe) {
+ __log.debug(xqe);
+ __log.info("Couldn't validate properly expression " + xqueryStr);
+ } catch (WrappedResolverException wre) {
+ if (wre._compilationMsg != null)
+ throw new CompilationException(wre._compilationMsg, wre);
+ if (wre.getCause() instanceof CompilationException)
+ throw (CompilationException) wre.getCause();
+ throw wre;
+ }
+ }
+
+ public Map<String, String> getProperties() {
+ return _properties;
+ }
+
+ private String getQName(NSContext nsContext, String uri, String localPart) {
+ String prefix = getPrefixForUri(nsContext, uri);
+ return (prefix == null ? localPart : (prefix + ":" + localPart));
+ }
+
+ private String getPrefixForUri(NSContext nsContext, String uri) {
+ Set<String> prefixes = nsContext.getPrefixes();
+ for (String prefix : prefixes) {
+ String anUri = (nsContext.getNamespaceURI(prefix));
+ if (anUri != null && anUri.equals(uri)) {
+ return prefix;
+ }
+ }
+ return null;
+ }
+
+ private List<String> getVariableNames(String xquery) {
+ List<String> variableNames = new ArrayList<String>();
+ for (int index = xquery.indexOf("$"); index != -1; index = xquery.indexOf("$")) {
+ StringBuffer variableName = new StringBuffer();
+ for (char ch = xquery.charAt(++index);
+ XMLChar.isNCName(ch);
+ ch = xquery.charAt(++index)) {
+ variableName.append(ch);
+ }
+ variableNames.add(variableName.toString());
+ xquery = xquery.substring(index);
+ }
+ return variableNames;
+ }
+
+ private OScope.Variable getVariable(List<OScope.Variable> variables, String variableName) {
+ String declaredVariable = getVariableDeclaredName(variableName);
+ for (OScope.Variable variable : variables) {
+ if (variable.name.equals(declaredVariable)) {
+ return variable;
+ }
+ }
+ return null;
+ }
+
+ private String getVariableDeclaredName(String variableReference) {
+ int dotIndex = variableReference.indexOf(".");
+ return dotIndex >= 0 ? variableReference.substring(0, dotIndex) : variableReference;
+ }
+
+ private String getVariablePartName(String variableReference) {
+ int dotIndex = variableReference.indexOf(".");
+ return dotIndex >= 0 ? variableReference.substring(dotIndex + 1) : "";
+ }
+
+ private QName getNameQName(String variableName) {
+ String prefix = null, localName = null;;
+ int colonIndex = variableName.indexOf(":");
+ if (colonIndex >= 0) {
+ prefix = variableName.substring(0, colonIndex);
+ localName = variableName.substring(colonIndex + 1);
+ } else {
+ prefix = "";
+ localName = variableName;
+ }
+ return new QName(prefix, localName);
+ }
+
+ private QName getTypeQName(String variableName, OVarType type) {
+ QName typeQName = null;
+ if (type instanceof OConstantVarType) {
+ typeQName = new QName(Namespaces.XML_SCHEMA, "string", "xs");
+ } else if (type instanceof OElementVarType) {
+ typeQName = ((OElementVarType) type).elementType;
+ } else if (type instanceof OMessageVarType) {
+ Part part = ((OMessageVarType) type).parts.get(getVariablePartName(variableName));
+ if (part != null) {
+ typeQName = getTypeQName(variableName, part.type);
+ }
+ } else if (type instanceof OXsdTypeVarType) {
+ typeQName = ((OXsdTypeVarType) type).xsdType;
+ }
+ return typeQName;
+ }
+
+ private class XQueryDeclarations {
+ StringBuffer declarations = new StringBuffer();
+
+ public XQueryDeclarations() {}
+
+ public void declareVariable(String name, QName type) {
+ declareVariable(name, type.getPrefix() + ":" + type.getLocalPart());
+ }
+
+ public void declareVariable(String name, String type) {
+ declarations.append("declare variable ")
+ .append("$")
+ .append(name)
+ .append(" as ")
+ .append(type)
+ .append(" external ")
+ .append(";\n");
+ }
+
+ public void declareVariable(String name) {
+ declarations.append("declare variable ")
+ .append("$")
+ .append(name)
+ .append(" external ")
+ .append(";\n");
+ }
+
+ public void declareNamespace(String prefix, String uri) {
+ declarations.append("declare namespace ")
+ .append(prefix)
+ .append("=")
+ .append("\"" + uri + "\"")
+ .append(";\n");
+ }
+
+ public void declareDefaultElementNamespace(String uri) {
+ declarations.append("declare default element namespace ")
+ .append("\"" + uri + "\"")
+ .append(";\n");
+ }
+
+ public String toString() {
+ return declarations.toString();
+ }
+ }
+}
Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler/XPathTest.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler/XPathTest.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler/XPathTest.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/test/java/org/apache/ode/bpel/compiler/XPathTest.java Tue Oct 28 17:11:15 2008
@@ -19,6 +19,7 @@
package org.apache.ode.bpel.compiler;
import java.io.IOException;
+import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -26,6 +27,7 @@
import javax.wsdl.Operation;
import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
import junit.framework.TestCase;
@@ -271,4 +273,8 @@
public Part resolveHeaderPart(Variable variable, String partname) throws CompilationException {
return null;
}
+
+ public Map<URI, Source> getSchemaSources() {
+ return null;
+ }
}
Added: ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/elang/xquery10/o/OXQuery10ExpressionBPEL20.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/elang/xquery10/o/OXQuery10ExpressionBPEL20.java?rev=708740&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/elang/xquery10/o/OXQuery10ExpressionBPEL20.java (added)
+++ ode/branches/APACHE_ODE_1.X/bpel-obj/src/main/java/org/apache/ode/bpel/elang/xquery10/o/OXQuery10ExpressionBPEL20.java Tue Oct 28 17:11:15 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.bpel.elang.xquery10.o;
+
+import javax.xml.namespace.QName;
+
+import net.sf.saxon.expr.Expression;
+import net.sf.saxon.query.XQueryExpression;
+
+import org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20;
+import org.apache.ode.bpel.o.OProcess;
+
+/**
+ * A representation of an XQuery expression
+ */
+public class OXQuery10ExpressionBPEL20 extends OXPath20ExpressionBPEL20 {
+
+ private static final long serialVersionUID = -1L;
+
+ public String xquery;
+
+ public OXQuery10ExpressionBPEL20(OProcess owner, QName qname_getVariableData,
+ QName qname_getVariableProperty, QName qname_getLinkStatus,
+ QName qname_doXslTransform, boolean isJoinExpression) {
+ super(owner, qname_getVariableData, qname_getVariableProperty, qname_getLinkStatus,
+ qname_doXslTransform, isJoinExpression);
+ }
+}
Modified: ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java Tue Oct 28 17:11:15 2008
@@ -38,6 +38,7 @@
import javax.xml.xpath.XPathFunctionResolver;
import net.sf.saxon.dom.NodeWrapper;
+import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.IntegerValue;
import net.sf.saxon.value.QNameValue;
@@ -89,7 +90,7 @@
String localName = functionName.getLocalPart();
if (Constants.EXT_FUNCTION_GETVARIABLEDATA.equals(localName)) {
return new GetVariableData();
- } else if (Constants.EXT_FUNCTION_GETVARIABLEPROPRTY.equals(localName)) {
+ } else if (Constants.EXT_FUNCTION_GETVARIABLEPROPERTY.equals(localName)) {
return new GetVariableProperty();
} else if (Constants.EXT_FUNCTION_GETLINKSTATUS.equals(localName)) {
return new GetLinkStatus();
@@ -496,11 +497,16 @@
}
} else {
try {
- List elmts = (List) args.get(1);
- Element elt = (Element) elmts.get(0);
+ Element elt = null;
+ if (args.get(1) instanceof List) {
+ List elmts = (List) args.get(1);
+ elt = (Element) elmts.get(0);
+ } else if (args.get(1) instanceof Element) {
+ elt = (Element) args.get(1);
+ }
pairs = Helper.extractNameValueMap(elt);
} catch (ClassCastException e) {
- throw new XPathFunctionException(new FaultException(faultQName, "Expected an element similar too: <foo><name1>value1</name1>name2>value2</name2>...</foo>"));
+ throw new XPathFunctionException(new FaultException(faultQName, "Expected an element similar too: <foo><name1>value1</name1><name2>value2</name2>...</foo>"));
}
}
@@ -990,6 +996,11 @@
} else {
localName = qName;
}
+ } else if (args.get(1) instanceof QName) {
+ QName qName = (QName) args.get(1);
+ namespaceUri = qName.getNamespaceURI();
+ localName = qName.getLocalPart();
+ prefix = qName.getPrefix();
} else {
throw new XPathFunctionException("Unexpected argument type: "+args.get(1).getClass());
}
@@ -1141,10 +1152,13 @@
try {
return Integer.parseInt(extractString(arg));
} catch (ClassCastException cce) {
- if (arg instanceof IntegerValue) {
- return (int) ((IntegerValue) arg).longValue();
- }
- throw new IllegalArgumentException("Parameter MUST point to an integer, single element or text node.", cce);
+ try {
+ return (int) ((IntegerValue) arg).longValue();
+ } catch (XPathException xpe) {
+ throw new IllegalArgumentException("Parameter MUST point to an integer, single element or text node.", xpe);
+ } catch (ClassCastException ccce) {
+ throw new IllegalArgumentException("Parameter MUST point to an integer, single element or text node.", ccce);
+ }
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException("Parameter MUST point to an integer, single element or text node.", nfe);
}
Modified: ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java Tue Oct 28 17:11:15 2008
@@ -19,7 +19,20 @@
package org.apache.ode.bpel.elang.xpath20.runtime;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathVariableResolver;
+
+import net.sf.saxon.Configuration;
+import net.sf.saxon.dom.DocumentWrapper;
+import net.sf.saxon.dom.NodeWrapper;
+import net.sf.saxon.om.NodeInfo;
+import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.value.DateTimeValue;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.common.FaultException;
@@ -32,13 +45,10 @@
import org.apache.ode.bpel.o.OXsdTypeVarType;
import org.apache.ode.utils.Namespaces;
import org.apache.ode.utils.xsd.XSTypes;
+import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import javax.xml.namespace.QName;
-import javax.xml.xpath.XPathVariableResolver;
-import java.util.Calendar;
-
/**
* @author mriou <mriou at apache dot org>
*/
@@ -48,10 +58,12 @@
private EvaluationContext _ectx;
private OXPath10ExpressionBPEL20 _oxpath;
+ private Configuration _config;
- public JaxpVariableResolver(EvaluationContext ectx, OXPath10ExpressionBPEL20 oxpath) {
+ public JaxpVariableResolver(EvaluationContext ectx, OXPath10ExpressionBPEL20 oxpath, Configuration config) {
_ectx = ectx;
_oxpath = oxpath;
+ _config = config;
}
public Object resolveVariable(QName variableName) {
@@ -92,7 +104,7 @@
OMessageVarType.Part part = partName == null ? null : ((OMessageVarType)variable.type).parts.get(partName);
try{
- Node variableNode = _ectx.readVariable(variable, part);
+ final Node variableNode = _ectx.readVariable(variable, part);
if (variableNode == null)
throw new FaultException(variable.getOwner().constants.qnSelectionFailure,
"Unknown variable " + variableName.getLocalPart());
@@ -103,10 +115,8 @@
return getSimpleContent(variableNode,((OXsdTypeVarType)part.type).xsdType);
}
- // Saxon expects a node list, this nodelist should contain exactly one item, the attribute
- // value
- return new SingletonNodeList(variableNode);
-
+ // Saxon used to expect a node list, but now a regular node will suffice.
+ return variableNode;
}catch(FaultException e){
throw new WrappedResolverException(e);
}
@@ -114,43 +124,33 @@
}
private Object getSimpleContent(Node simpleNode, QName type) {
+ Document doc = (simpleNode instanceof Document) ? ((Document) simpleNode) : simpleNode
+ .getOwnerDocument();
String text = simpleNode.getTextContent();
try {
Object jobj = XSTypes.toJavaObject(type,text);
// Saxon wants its own dateTime type and doesn't like Calendar or Date
- if (jobj instanceof Calendar) return new DateTimeValue((Calendar) jobj, true);
- else return jobj;
+ if (jobj instanceof Calendar) {
+ return new DateTimeValue((Calendar) jobj, true);
+ } else {
+ // return the value wrapped in a text node
+ return doc.createTextNode(jobj.toString());
+ }
} catch (Exception e) { }
- // Elegant way failed, trying brute force
- try {
- return Integer.valueOf(text);
- } catch (NumberFormatException e) { }
- try {
- return Double.valueOf(text);
- } catch (NumberFormatException e) { }
+ // Elegant way failed, trying brute force
+ // Actually, we don't want to return simple types, so no more brute force
+ // try {
+ // return Integer.valueOf(text);
+ //} catch (NumberFormatException e) { }
+ //try {
+ // return Double.valueOf(text);
+ //} catch (NumberFormatException e) { }
+
// Remember: always a node set
if (simpleNode.getParentNode() != null)
return simpleNode.getParentNode().getChildNodes();
- else return text;
- }
-
-
- private static class SingletonNodeList implements NodeList {
- private Node _node;
-
- SingletonNodeList(Node node) {
- _node = node;
+ else {
+ return doc.createTextNode(text);
}
-
- public Node item(int index) {
- if (index != 0)
- throw new IndexOutOfBoundsException(""+index);
- return _node;
- }
-
- public int getLength() {
- return 1;
- }
-
}
}
Modified: ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java?rev=708740&r1=708739&r2=708740&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java Tue Oct 28 17:11:15 2008
@@ -18,13 +18,20 @@
*/
package org.apache.ode.bpel.elang.xpath20.runtime;
+import net.sf.saxon.dom.DocumentWrapper;
+import net.sf.saxon.om.NamespaceConstant;
+import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.trans.DynamicError;
import net.sf.saxon.value.DurationValue;
import net.sf.saxon.xpath.XPathEvaluator;
+import net.sf.saxon.xpath.XPathFactoryImpl;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.common.FaultException;
import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.elang.xpath20.runtime.JaxpFunctionResolver;
+import org.apache.ode.bpel.elang.xpath20.runtime.JaxpVariableResolver;
import org.apache.ode.bpel.elang.xpath20.compiler.WrappedResolverException;
import org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20;
import org.apache.ode.bpel.explang.ConfigurationException;
@@ -32,6 +39,7 @@
import org.apache.ode.bpel.explang.EvaluationException;
import org.apache.ode.bpel.explang.ExpressionLanguageRuntime;
import org.apache.ode.bpel.o.OExpression;
+import org.apache.ode.bpel.o.OScope;
import org.apache.ode.utils.DOMUtils;
import org.apache.ode.utils.ISO8601DateParser;
import org.apache.ode.utils.xsd.Duration;
@@ -40,9 +48,13 @@
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
import java.util.*;
/**
@@ -89,9 +101,15 @@
/**
* @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluate(org.apache.ode.bpel.o.OExpression, org.apache.ode.bpel.explang.EvaluationContext)
*/
- public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+ @SuppressWarnings("unchecked")
+ public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
List result;
- Object someRes = evaluate(cexp, ctx, XPathConstants.NODESET);
+ Object someRes = null;
+ try {
+ someRes = evaluate(cexp, ctx, XPathConstants.NODESET);
+ } catch (Exception e) {
+ someRes = evaluate(cexp, ctx, XPathConstants.STRING);
+ }
if (someRes instanceof List) {
result = (List) someRes;
__log.debug("Returned list of size " + result.size());
@@ -100,20 +118,21 @@
Object simpleType = result.get(0);
// Dates get a separate treatment as we don't want to call toString on them
String textVal;
- if (simpleType instanceof Date)
+ if (simpleType instanceof Date) {
textVal = ISO8601DateParser.format((Date) simpleType);
- else if (simpleType instanceof DurationValue)
+ } else if (simpleType instanceof DurationValue) {
textVal = ((DurationValue)simpleType).getStringValue();
- else
+ } else {
textVal = simpleType.toString();
+ }
// Wrapping in a document
- Document d = DOMUtils.newDocument();
+ Document document = DOMUtils.newDocument();
// Giving our node a parent just in case it's an LValue expression
- Element wrapper = d.createElement("wrapper");
- Text text = d.createTextNode(textVal);
+ Element wrapper = document.createElement("wrapper");
+ Text text = document.createTextNode(textVal);
wrapper.appendChild(text);
- d.appendChild(wrapper);
+ document.appendChild(wrapper);
result = Collections.singletonList(text);
}
} else if (someRes instanceof NodeList) {
@@ -122,9 +141,19 @@
result = new ArrayList(retVal.getLength());
for(int m = 0; m < retVal.getLength(); ++m) {
Node val = retVal.item(m);
- if (val.getNodeType() == Node.DOCUMENT_NODE) val = ((Document)val).getDocumentElement();
+ if (val.getNodeType() == Node.DOCUMENT_NODE) {
+ val = ((Document)val).getDocumentElement();
+ }
result.add(val);
}
+ } else if (someRes instanceof String) {
+ // Wrapping in a document
+ Document document = DOMUtils.newDocument();
+ Element wrapper = document.createElement("wrapper");
+ Text text = document.createTextNode((String) someRes);
+ wrapper.appendChild(text);
+ document.appendChild(wrapper);
+ result = Collections.singletonList(text);
} else {
result = null;
}
@@ -142,7 +171,7 @@
}
public Calendar evaluateAsDate(OExpression cexp, EvaluationContext context) throws FaultException, EvaluationException {
- List literal = DOMUtils.toList(evaluate(cexp, context, XPathConstants.NODESET));
+ List literal = DOMUtils.toList(evaluate(cexp, context));
if (literal.size() == 0)
throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "No results for expression: " + cexp);
if (literal.size() > 1)
@@ -155,7 +184,9 @@
cal.setTime((Date) date);
return cal;
}
- if (date instanceof Element) date = ((Element)date).getTextContent();
+ if (date instanceof Element) date = ((Element) date).getTextContent();
+
+ if (date instanceof Text) date = ((Text) date).getTextContent();
try {
return ISO8601DateParser.parseCal(date.toString());
@@ -179,17 +210,30 @@
private Object evaluate(OExpression cexp, EvaluationContext ctx, QName type) throws FaultException, EvaluationException {
try {
- net.sf.saxon.xpath.XPathFactoryImpl xpf = new net.sf.saxon.xpath.XPathFactoryImpl();
-
OXPath20ExpressionBPEL20 oxpath20 = ((OXPath20ExpressionBPEL20) cexp);
- xpf.setXPathFunctionResolver(new JaxpFunctionResolver(ctx, oxpath20));
- xpf.setXPathVariableResolver(new JaxpVariableResolver(ctx, oxpath20));
- XPathEvaluator xpe = (XPathEvaluator) xpf.newXPath();
+ System.setProperty("javax.xml.xpath.XPathFactory:"+NamespaceConstant.OBJECT_MODEL_SAXON,
+ "net.sf.saxon.xpath.XPathFactoryImpl");
+ System.setProperty("javax.xml.xpath.XPathFactory:"+XPathConstants.DOM_OBJECT_MODEL,
+ "net.sf.saxon.xpath.XPathFactoryImpl");
+ System.setProperty("javax.xml.xpath.XPathFactory:"+NamespaceConstant.OBJECT_MODEL_JDOM,
+ "net.sf.saxon.xpath.XPathFactoryImpl");
+ System.setProperty("javax.xml.xpath.XPathFactory:"+NamespaceConstant.OBJECT_MODEL_XOM,
+ "net.sf.saxon.xpath.XPathFactoryImpl");
+ System.setProperty("javax.xml.xpath.XPathFactory:"+NamespaceConstant.OBJECT_MODEL_DOM4J,
+ "net.sf.saxon.xpath.XPathFactoryImpl");
+
+ XPathFactory xpf = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
+ JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(
+ ctx, oxpath20);
+ JaxpVariableResolver varResolver = new JaxpVariableResolver(ctx, oxpath20, ((XPathFactoryImpl) xpf).getConfiguration());
+ xpf.setXPathFunctionResolver(funcResolver);
+ xpf.setXPathVariableResolver(varResolver);
+ XPath xpe = xpf.newXPath();
xpe.setNamespaceContext(oxpath20.namespaceCtx);
- // Just checking that the expression is valid
XPathExpression expr = xpe.compile(((OXPath10Expression)cexp).xpath);
+ Node contextNode = ctx.getRootNode() == null ? DOMUtils.newDocument() : ctx.getRootNode();
- Object evalResult = expr.evaluate(ctx.getRootNode() == null ? DOMUtils.newDocument() : ctx.getRootNode(), type);
+ Object evalResult = expr.evaluate(contextNode, type);
if (evalResult != null && __log.isDebugEnabled()) {
__log.debug("Expression " + cexp.toString() + " generated result " + evalResult
+ " - type=" + evalResult.getClass().getName());
@@ -217,5 +261,4 @@
}
}
-
}
Added: ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10BpelFunctions.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10BpelFunctions.java?rev=708740&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10BpelFunctions.java (added)
+++ ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10BpelFunctions.java Tue Oct 28 17:11:15 2008
@@ -0,0 +1,163 @@
+package org.apache.ode.bpel.elang.xquery10.runtime;
+
+import net.sf.saxon.dom.NodeWrapper;
+import net.sf.saxon.expr.XPathContext;
+import net.sf.saxon.om.Item;
+
+import org.apache.ode.bpel.elang.xpath20.compiler.Constants;
+import org.apache.ode.bpel.elang.xpath20.runtime.JaxpFunctionResolver;
+import org.apache.ode.utils.Namespaces;
+
+import org.w3c.dom.Node;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+
+
+/**
+ * XQuery-Friendly definition of BPEL functions, which
+ * delegates calls to the JAXP-based function resolver
+ */
+public class XQuery10BpelFunctions {
+ public static final String USER_DATA_KEY_FUNCTION_RESOLVER = "function-resolver";
+ private static final QName WSBPEL_GET_VARIABLE_PROPERTY = new QName(Namespaces.WSBPEL2_0_FINAL_EXEC,
+ Constants.EXT_FUNCTION_GETVARIABLEPROPERTY);
+ private static final QName WSBPEL_GET_VARIABLE_DATA = new QName(Namespaces.WSBPEL2_0_FINAL_EXEC,
+ Constants.EXT_FUNCTION_GETVARIABLEDATA);
+ private static final QName WSBPEL_GET_LINK_STATUS = new QName(Namespaces.WSBPEL2_0_FINAL_EXEC,
+ Constants.EXT_FUNCTION_GETLINKSTATUS);
+ private static final QName WSBPEL_DO_XSL_TRANSFORM = new QName(Namespaces.WSBPEL2_0_FINAL_EXEC,
+ Constants.EXT_FUNCTION_DOXSLTRANSFORM);
+
+ /**
+ * WS-BPEL getVariableProperty function
+ *
+ * @param context context
+ * @param variableName variableName
+ * @param propertyName propertyName
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ public static Object getVariableProperty(XPathContext context,
+ String variableName, String propertyName) throws XPathFunctionException {
+ ArrayList<String> arguments = new ArrayList<String>();
+ arguments.add(variableName);
+ arguments.add(propertyName);
+
+ return evaluate(resolveFunction(context, WSBPEL_GET_VARIABLE_PROPERTY),
+ arguments);
+ }
+
+ /**
+ * WS-BPEL getVariableData function
+ *
+ * @param context context
+ * @param variableName variableName
+ * @param partName partName
+ * @param xpath xpath
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ public static Object getVariableData(XPathContext context,
+ String variableName, String partName, String xpath)
+ throws XPathFunctionException {
+ ArrayList<String> arguments = new ArrayList<String>();
+ arguments.add(variableName);
+ arguments.add(partName);
+ arguments.add(xpath);
+
+ return evaluate(resolveFunction(context, WSBPEL_GET_VARIABLE_DATA),
+ arguments);
+ }
+
+ /**
+ * WS-BPEL doXslTransform function
+ *
+ * @param context context
+ * @param xslUri xslUri
+ * @param sources sources
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ public static Object doXslTransform(XPathContext context, String xslUri,
+ Object sources) throws XPathFunctionException {
+ ArrayList<Object> arguments = new ArrayList<Object>();
+ arguments.add(xslUri);
+ arguments.add(sources);
+
+ return evaluate(resolveFunction(context, WSBPEL_DO_XSL_TRANSFORM),
+ arguments);
+ }
+
+ /**
+ * WS-BPEL getLinkStatus function
+ *
+ * @param context context
+ * @param linkName linkName
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ public static Object getLinkStatus(XPathContext context, String linkName)
+ throws XPathFunctionException {
+ ArrayList<String> arguments = new ArrayList<String>();
+ arguments.add(linkName);
+
+ return evaluate(resolveFunction(context, WSBPEL_GET_LINK_STATUS),
+ arguments);
+ }
+
+ /**
+ * Locates the equivalent JAXP function
+ *
+ * @param context context
+ * @param name name
+ *
+ * @return type
+ */
+ private static XPathFunction resolveFunction(XPathContext context,
+ QName name) {
+ JaxpFunctionResolver funcResolver = null;
+ Item item = context.getCurrentIterator().current();
+
+ if (item instanceof NodeWrapper) {
+ Node node = (Node) ((NodeWrapper) item).getUnderlyingNode();
+
+ if (node != null) {
+ funcResolver = (JaxpFunctionResolver) node.getUserData(USER_DATA_KEY_FUNCTION_RESOLVER);
+ }
+ }
+
+ return funcResolver.resolveFunction(name, 0);
+ }
+
+ /**
+ * Evaluates function against arguments passed by XQuery
+ *
+ * @param function function
+ * @param arguments arguments
+ *
+ * @return type
+ *
+ * @throws XPathFunctionException XPathFunctionException
+ */
+ private static Object evaluate(XPathFunction function, List arguments)
+ throws XPathFunctionException {
+ if (function == null) {
+ throw new XPathFunctionException("Unable to locate function in library");
+ }
+
+ return function.evaluate(arguments);
+ }
+}