You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by as...@apache.org on 2006/11/29 00:47:04 UTC

svn commit: r480289 [1/2] - in /incubator/ode/trunk: ./ axis2-war/ bpel-compiler/ bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/ bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/ bpel-compiler/src/main/java/org/apa...

Author: assaf
Date: Tue Nov 28 15:47:00 2006
New Revision: 480289

URL: http://svn.apache.org/viewvc?view=rev&rev=480289
Log:
Merged bpel-el-xpath20 module into bpel-compiler

Added:
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/Constants.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/WrappedResolverException.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/OdeXPathFunctionLibrary.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerBPEL20.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/OXPath20ExpressionBPEL20.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/
    incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/
    incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/
    incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java   (with props)
    incubator/ode/trunk/bpel-compiler/src/test/resources/variables.xml   (with props)
Removed:
    incubator/ode/trunk/bpel-el-xpath20/
Modified:
    incubator/ode/trunk/axis2-war/pom.xml
    incubator/ode/trunk/bpel-compiler/pom.xml
    incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
    incubator/ode/trunk/bpel-runtime/src/test/resources/atomic/same-transaction.bpel
    incubator/ode/trunk/distro-axis2/pom.xml
    incubator/ode/trunk/distro-axis2/src/main/assembly/assembly.xml
    incubator/ode/trunk/distro-jbi/pom.xml
    incubator/ode/trunk/distro-jbi/src/main/assembly/assembly.xml
    incubator/ode/trunk/pom.xml

Modified: incubator/ode/trunk/axis2-war/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2-war/pom.xml?view=diff&rev=480289&r1=480288&r2=480289
==============================================================================
--- incubator/ode/trunk/axis2-war/pom.xml (original)
+++ incubator/ode/trunk/axis2-war/pom.xml Tue Nov 28 15:47:00 2006
@@ -228,11 +228,6 @@
         </dependency>
         <dependency>
             <groupId>org.apache.ode</groupId>
-            <artifactId>ode-bpel-el-xpath20</artifactId>
-            <scope>runtime</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.ode</groupId>
             <artifactId>ode-bpel-obj</artifactId>
             <scope>runtime</scope>
         </dependency>

Modified: incubator/ode/trunk/bpel-compiler/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/pom.xml?view=diff&rev=480289&r1=480288&r2=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/pom.xml (original)
+++ incubator/ode/trunk/bpel-compiler/pom.xml Tue Nov 28 15:47:00 2006
@@ -46,13 +46,6 @@
             <artifactId>ode-bpel-schemas</artifactId>
         </dependency>
 
-<!--
-        <dependency>
-            <groupId>org.apache.ode</groupId>
-            <artifactId>ode-bpel-el-xpath20</artifactId>
-            <scope>test</scope>
-        </dependency>
--->
         <dependency>
             <groupId>org.apache.ode</groupId>
             <artifactId>ode-bpel-obj</artifactId>

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/Constants.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/Constants.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/Constants.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/Constants.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,54 @@
+/*
+ * 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.xpath20;
+
+/**
+ * XPath-4-BPEL related constants.
+ */
+public class Constants {
+  /**
+   * Extension function bpws:getVariableData('variableName', 'partName'?,
+   * 'locationPath'?)
+   */
+  public static final String EXT_FUNCTION_GETVARIABLEDATA = "getVariableData";
+
+  /**
+   * Extension function
+   * bpws:getVariableProperty('variableName','propertyName')
+   */
+  public static final String EXT_FUNCTION_GETVARIABLEPROPRTY = "getVariableProperty";
+
+  /**
+   * Extension function bpws:getLinkStatus('getLinkName')
+   */
+  public static final String EXT_FUNCTION_GETLINKSTATUS = "getLinkStatus";
+
+  /**
+   * Extension function bpws:getLinkStatus('getLinkName')
+   */
+  public static final String EXT_FUNCTION_DOXSLTRANSFORM = "doXslTransform";
+
+  public static final String BPEL20_NS = "http://schemas.xmlsoap.org/ws/2004/03/business-process/";
+  public static final String BPEL11_NS = "http://schemas.xmlsoap.org/ws/2003/03/business-process/";
+
+  public static boolean isBpelNamespace(String uri){
+    return BPEL20_NS.equals(uri) || BPEL11_NS.equals(uri);
+  }
+
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/Constants.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/Constants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/WrappedResolverException.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/WrappedResolverException.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/WrappedResolverException.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/WrappedResolverException.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,47 @@
+/*
+ * 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.xpath20;
+
+import org.apache.ode.bpel.compiler.api.CompilationMessage;
+
+/**
+ * @author mriou <mriou at apache dot org>
+ */
+public class WrappedResolverException extends RuntimeException {
+    private static final long serialVersionUID = -2677245631724501573L;
+    
+    public CompilationMessage _compilationMsg;
+
+    public WrappedResolverException(String message) {
+        super(message);
+    }
+
+    public WrappedResolverException(CompilationMessage message) {
+        _compilationMsg = message;
+    }
+
+    public WrappedResolverException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public WrappedResolverException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/WrappedResolverException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/WrappedResolverException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/WrappedResolverException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,130 @@
+/*
+ * 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.xpath20.compiler;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+import javax.xml.xpath.XPathFunctionResolver;
+
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.bpel.elang.xpath10.compiler.XPathMessages;
+import org.apache.ode.bpel.elang.xpath10.compiler.XslCompileUriResolver;
+import org.apache.ode.bpel.elang.xpath20.Constants;
+import org.apache.ode.bpel.elang.xpath20.WrappedResolverException;
+import org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20;
+import org.apache.ode.bpel.o.OProcess;
+import org.apache.ode.bpel.o.OScope;
+import org.apache.ode.bpel.o.OXslSheet;
+import org.apache.ode.utils.NSContext;
+import org.apache.ode.utils.msg.MessageBundle;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+
+/**
+ * @author mriou <mriou at apache dot org>
+ */
+public class JaxpFunctionResolver implements XPathFunctionResolver {
+
+    private static final XPathMessages __msgs = MessageBundle.getMessages(XPathMessages.class);
+
+    private CompilerContext _cctx;
+    private OXPath20ExpressionBPEL20 _out;
+    private NSContext _nsContext;
+    private String _bpelNS;
+
+    public JaxpFunctionResolver(CompilerContext cctx, OXPath20ExpressionBPEL20 out,
+                                NSContext nsContext, String bpelNS) {
+        _cctx = cctx;
+        _bpelNS = bpelNS;
+        _nsContext = nsContext;
+        _bpelNS = bpelNS;
+        _out = out;
+    }
+
+    public XPathFunction resolveFunction(QName functionName, int arity) {
+        if (functionName.getNamespaceURI() == null) {
+            throw new WrappedResolverException("Undeclared namespace for " + functionName);
+        } else if (functionName.getNamespaceURI().equals(_bpelNS)) {
+            String localName = functionName.getLocalPart();
+            if (Constants.EXT_FUNCTION_GETVARIABLEPROPRTY.equals(localName)) {
+                return new GetVariableProperty();
+            } else if (Constants.EXT_FUNCTION_DOXSLTRANSFORM.equals(localName)) {
+                return new DoXslTransform();
+            } else {
+                throw new WrappedResolverException(__msgs.errUnknownBpelFunction(localName));
+            }
+        }
+
+        return null;
+    }
+
+
+    public class GetVariableProperty implements XPathFunction {
+        public Object evaluate(List params) throws XPathFunctionException {
+            if (params.size() != 2) {
+                throw new CompilationException(
+                        __msgs.errInvalidNumberOfArguments(Constants.EXT_FUNCTION_GETVARIABLEPROPRTY));
+            }
+            String varName = (String) params.get(0);
+            OScope.Variable v = _cctx.resolveVariable(varName);
+            _out.vars.put(varName, v);
+
+            String propName = (String) params.get(1);
+            QName qname = _nsContext.derefQName(propName);
+
+            if (qname == null)
+                throw new CompilationException(
+                        __msgs.errInvalidQName(propName));
+
+            OProcess.OProperty property = _cctx.resolveProperty(qname);
+            // Make sure we can...
+            _cctx.resolvePropertyAlias(v, qname);
+
+            _out.properties.put(propName, property);
+            _out.vars.put(varName, v);
+            return "";
+        }
+    }
+
+    public class DoXslTransform implements XPathFunction {
+        public Object evaluate(List params) throws XPathFunctionException {
+            if (params.size() < 2 || params.size() % 2 != 0) {
+                throw new CompilationException(
+                        __msgs.errInvalidNumberOfArguments(Constants.EXT_FUNCTION_DOXSLTRANSFORM));
+            }
+
+            String xslUri = (String) params.get(0);
+            OXslSheet xslSheet = _cctx.compileXslt(xslUri);
+            try {
+                XslTransformHandler.getInstance().parseXSLSheet(xslSheet.uri, xslSheet.sheetBody,
+                        new XslCompileUriResolver(_cctx, _out));
+            } catch (Exception e) {
+                throw new CompilationException(__msgs.errXslCompilation(xslUri, e.toString()));
+            }
+
+            _out.xslSheets.put(xslSheet.uri, xslSheet);
+            return "";
+        }
+    }
+
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpFunctionResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,121 @@
+/*
+ * 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.xpath20.compiler;
+
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10ExpressionBPEL20;
+import org.apache.ode.bpel.elang.xpath20.WrappedResolverException;
+import org.apache.ode.bpel.o.OElementVarType;
+import org.apache.ode.bpel.o.OLink;
+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.utils.Namespaces;
+import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Document;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathVariableResolver;
+
+/**
+ * This is a mock implementation of the XPathVariableResolver for compilation. It
+ * always returns an empty string which allows execution of XPath expressions even
+ * if we don't have any values yet. This way we can easily rule out invalid variables
+ * and isolate properly BPEL variables.
+ * @author mriou <mriou at apache dot org>
+ */
+public class JaxpVariableResolver implements XPathVariableResolver {
+
+    private CompilerContext _cctx;
+    private OXPath10ExpressionBPEL20 _oxpath;
+
+    public JaxpVariableResolver(CompilerContext cctx, OXPath10ExpressionBPEL20 oxpath) {
+        _cctx = cctx;
+        _oxpath = oxpath;
+    }
+
+    public Object resolveVariable(QName variableName) {
+        // Custom variables
+        if ("ode".equals(variableName.getPrefix())
+                || Namespaces.ODE_EXTENSION_NS.equals(variableName.getNamespaceURI())) {
+            if ("pid".equals(variableName.getLocalPart())) return "";
+        }
+
+        try {
+            String name = variableName.getLocalPart();
+            if(_oxpath.isJoinExpression) {
+                // these resolve to links
+                OLink olink = _cctx.resolveLink(name);
+                _oxpath.links.put(name, olink);
+                return Boolean.TRUE;
+            } else {
+                int dot = name.indexOf('.');
+                if (dot != -1)
+                    name = name.substring(0,dot);
+                OScope.Variable var = _cctx.resolveVariable(name);
+                _oxpath.vars.put(name, var);
+                return extractValue(var.type);
+            }
+        } catch (CompilationException e) {
+            throw new WrappedResolverException(e);
+        }
+    }
+
+    private Object extractValue(OVarType varType) {
+        if (varType instanceof OXsdTypeVarType) {
+            return generateFromType(((OXsdTypeVarType)varType).xsdType);
+        } else if (varType instanceof OElementVarType) {
+            return generateFromType(((OElementVarType)varType).elementType);
+        } else if (varType instanceof OMessageVarType) {
+            // MR That's an ugly hack but otherwise, xpath compilation doesn't work
+            return extractValue( ((OMessageVarType.Part) ((OMessageVarType)varType).parts.values().iterator().next()).type);
+        }
+        return "";
+    }
+
+    private Object generateFromType(QName typeName) {
+        if (typeName.getNamespaceURI().equals(Namespaces.XML_SCHEMA)) {
+            if (typeName.getLocalPart().equals("int") ||
+                    typeName.getLocalPart().equals("integer") ||
+                    typeName.getLocalPart().equals("short") ||
+                    typeName.getLocalPart().equals("long") ||
+                    typeName.getLocalPart().equals("byte") ||
+                    typeName.getLocalPart().equals("float") ||
+                    typeName.getLocalPart().equals("double") ||
+                    typeName.getLocalPart().equals("nonPositiveInteger") ||
+                    typeName.getLocalPart().equals("nonNegativeInteger") ||
+                    typeName.getLocalPart().equals("negativeInteger") ||
+                    typeName.getLocalPart().equals("unsignedLong") ||
+                    typeName.getLocalPart().equals("unsignedInt") ||
+                    typeName.getLocalPart().equals("unsignedShort") ||
+                    typeName.getLocalPart().equals("unsignedByte"))
+                return 0;
+            if (typeName.getLocalPart().equals("boolean"))
+                return Boolean.TRUE;
+            if (typeName.getLocalPart().equals("string"))
+                return "";
+        }
+        Document doc = DOMUtils.newDocument();
+        doc.appendChild(doc.createElement("empty"));
+        return doc.getDocumentElement();
+    }
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/JaxpVariableResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/OdeXPathFunctionLibrary.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/OdeXPathFunctionLibrary.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/OdeXPathFunctionLibrary.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/OdeXPathFunctionLibrary.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,54 @@
+package org.apache.ode.bpel.elang.xpath20.compiler;
+
+import net.sf.saxon.expr.Expression;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.trans.StaticError;
+import net.sf.saxon.xpath.XPathFunctionCall;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+import java.util.ArrayList;
+
+/**
+ * Overloading the XPathFunctionLibrary to force it to initialize our functions giving
+ * the provided parameters. Otherwise the Saxon implemetation just never gives you
+ * any parameter before runtime.
+ * @author mriou <mriou at apache dot org>
+ */
+public class OdeXPathFunctionLibrary extends net.sf.saxon.xpath.XPathFunctionLibrary {
+    private static final long serialVersionUID = -8885396864277163797L;
+    
+    private JaxpFunctionResolver _funcResolver;
+
+    public OdeXPathFunctionLibrary(JaxpFunctionResolver funcResolver) {
+        _funcResolver = funcResolver;
+    }
+
+    public Expression bind(int nameCode, String uri, String local, Expression[] staticArgs) throws XPathException {
+        QName name = new QName(uri, local);
+        XPathFunction function = _funcResolver.resolveFunction(name, staticArgs.length);
+        if (function == null) {
+            return null;
+        }
+
+        // Converting the expression array to the simple string
+        ArrayList args = new ArrayList(staticArgs.length);
+        for (Expression expression : staticArgs) {
+            String exprStr = expression.toString();
+            if (exprStr.startsWith("\"")) exprStr = exprStr.substring(1);
+            if (exprStr.endsWith("\"")) exprStr = exprStr.substring(0, exprStr.length() - 1);
+            args.add(exprStr);
+        }
+
+        try {
+            function.evaluate(args);
+        } catch (XPathFunctionException e) {
+            throw new StaticError(e);
+        }
+        XPathFunctionCall fc = new XPathFunctionCall(function);
+        fc.setArguments(staticArgs);
+        return fc;
+    }
+
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/OdeXPathFunctionLibrary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/OdeXPathFunctionLibrary.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/OdeXPathFunctionLibrary.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,93 @@
+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 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;
+
+/**
+ * Hooks on Saxon StandaloneContext to be notified when the compilation
+ * finds some variables and functions. This allows us to prepare the
+ * OXpathExpression with variable references and all the things needed
+ * at runtime.
+ * @author mriou <mriou at apache dot org>
+ */
+public class SaxonContext extends StandaloneContext {
+
+    private JaxpVariableResolver _varResolver;
+    private JaxpFunctionResolver _funcResolver;
+
+    public SaxonContext(Configuration config, JaxpVariableResolver varResolver,
+                        JaxpFunctionResolver funcResolver) {
+        super(config);
+
+        // We need to remove the default XPathFunctionLibrary to replace it
+        // with our own
+        List libList = ((FunctionLibraryList)getFunctionLibrary()).libraryList;
+        XPathFunctionLibrary xpathLib = null;
+        for (Object lib : libList) {
+            FunctionLibrary flib = (FunctionLibrary) lib;
+            if (flib instanceof XPathFunctionLibrary) xpathLib = (XPathFunctionLibrary) flib;
+        }
+        if (xpathLib != null) libList.remove(xpathLib);
+        OdeXPathFunctionLibrary oxpfl = new OdeXPathFunctionLibrary(funcResolver);
+        oxpfl.setXPathFunctionResolver(funcResolver);
+
+        oxpfl.setXPathFunctionResolver(_funcResolver);
+        ((FunctionLibraryList)getFunctionLibrary()).addFunctionLibrary(oxpfl);
+
+        _varResolver = varResolver;
+        _funcResolver = funcResolver;
+    }
+
+    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);
+    }
+
+
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/SaxonContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerBPEL20.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerBPEL20.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerBPEL20.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerBPEL20.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,178 @@
+/*
+ * 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.xpath20.compiler;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.xpath.XPathExpressionException;
+
+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.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.Constants;
+import org.apache.ode.bpel.elang.xpath20.WrappedResolverException;
+import org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20;
+import org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime;
+import org.apache.ode.bpel.o.OExpression;
+import org.apache.ode.bpel.o.OLValueExpression;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.msg.MessageBundle;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+import org.w3c.dom.Node;
+
+
+/**
+ * XPath compiler based on the SAXON implementation.
+ * 
+ * @author mriou <mriou at apache dot org>
+ */
+public class XPath20ExpressionCompilerBPEL20 implements ExpressionCompiler {
+
+    private static final Log __log = LogFactory.getLog(XPath20ExpressionCompilerBPEL20.class);
+
+    private static final QName _qnLinkStatus = new QName(Constants.BPEL20_NS, Constants.EXT_FUNCTION_GETLINKSTATUS);
+
+    private static final QName _qnVarProp = new QName(Constants.BPEL20_NS, Constants.EXT_FUNCTION_GETVARIABLEPROPRTY);
+
+    private static final QName _qnVarData = new QName(Constants.BPEL20_NS, Constants.EXT_FUNCTION_GETVARIABLEDATA);
+
+    private static final QName _qnXslTransform = new QName(Constants.BPEL20_NS, Constants.EXT_FUNCTION_DOXSLTRANSFORM);
+
+    private static final XPathMessages __msgs = MessageBundle.getMessages(XPathMessages.class);
+
+    private CompilerContext _compilerContext;
+
+    private Map<String, String> _properties = new HashMap<String, String>();
+
+    public XPath20ExpressionCompilerBPEL20() {
+        super();
+        _properties.put("runtime-class", XPath20ExpressionRuntime.class.getName());
+        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.capi.ExpressionCompiler#compile(java.lang.Object)
+     */
+    private OExpression _compile(org.apache.ode.bpel.compiler.bom.Expression xpath, boolean isJoinCondition)
+            throws CompilationException {
+        OXPath20ExpressionBPEL20 oexp = new OXPath20ExpressionBPEL20(_compilerContext.getOProcess(), _qnVarData,
+                _qnVarProp, _qnLinkStatus, _qnXslTransform, isJoinCondition);
+        oexp.namespaceCtx = xpath.getNamespaceContext();
+        doJaxpCompile(oexp, xpath);
+        return oexp;
+    }
+
+    private void doJaxpCompile(OXPath20ExpressionBPEL20 out, Expression source) throws CompilationException {
+        String xpathStr;
+        Node node = source.getExpression();
+        if (node == null) {
+            throw new IllegalStateException("XPath string and xpath node are both null");
+        }
+        if (node.getNodeType() != Node.TEXT_NODE) {
+            throw new CompilationException(__msgs.errUnexpectedNodeTypeForXPath(DOMUtils.domToString(node)));
+        }
+        xpathStr = node.getNodeValue();
+        xpathStr = xpathStr.trim();
+
+        out.xpath = xpathStr;
+        try {
+            __log.debug("Compiling expression " + xpathStr);
+            XPathFactoryImpl xpf = new net.sf.saxon.xpath.XPathFactoryImpl();
+            JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(
+                    _compilerContext, out, source.getNamespaceContext(), Constants.BPEL20_NS);
+            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));
+            xpe.setXPathFunctionResolver(funcResolver);
+            xpe.setNamespaceContext(source.getNamespaceContext());
+            xpe.compile(xpathStr);
+
+            // Here we're "faking" an evaluation to parse properly variables and
+            // functions and
+            // detect all possible mistakes. To do so we're using specific
+            // resolvers that always
+            // return guessed appropriate values from variable types.
+//            expr.evaluate(DOMUtils.newDocument());
+
+            // Fishing for predicates
+            // TODO Clean that up
+//            if (xpathStr.indexOf("[$") > 0) {
+//                String rightStr = xpathStr.substring(xpathStr.indexOf("[$") + 2, xpathStr.length());
+//                String varStr = rightStr.substring(0, rightStr.indexOf("]"));
+//                varResolver.resolveVariable(new QName(null, varStr));
+//            }
+        } catch (XPathExpressionException e) {
+            __log.debug(e);
+            __log.info("Couldn't validate properly expression " + xpathStr);
+        } 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;
+    }
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerBPEL20.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerBPEL20.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/compiler/XPath20ExpressionCompilerBPEL20.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/OXPath20ExpressionBPEL20.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/OXPath20ExpressionBPEL20.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/OXPath20ExpressionBPEL20.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/OXPath20ExpressionBPEL20.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,51 @@
+/*
+ * 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.xpath20.o;
+
+import net.sf.saxon.expr.Expression;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10ExpressionBPEL20;
+import org.apache.ode.bpel.o.OProcess;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author mriou <mriou at apache dot org>
+ */
+public class OXPath20ExpressionBPEL20 extends OXPath10ExpressionBPEL20 {
+
+    private static final long serialVersionUID = -1L;
+
+    private Expression _compiledExpr;
+
+    public OXPath20ExpressionBPEL20(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);
+    }
+
+    public Expression getCompiledExpr() {
+        return _compiledExpr;
+    }
+
+    public void setCompiledExpr(Expression compiledExpr) {
+        _compiledExpr = compiledExpr;
+    }
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/OXPath20ExpressionBPEL20.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/OXPath20ExpressionBPEL20.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/o/OXPath20ExpressionBPEL20.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,284 @@
+/*
+ * 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.xpath20.runtime;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+import javax.xml.xpath.XPathFunctionResolver;
+
+import net.sf.saxon.dom.NodeWrapper;
+
+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.xpath10.o.OXPath10ExpressionBPEL20;
+import org.apache.ode.bpel.elang.xpath20.Constants;
+import org.apache.ode.bpel.elang.xpath20.WrappedResolverException;
+import org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20;
+import org.apache.ode.bpel.explang.EvaluationContext;
+import org.apache.ode.bpel.o.OLink;
+import org.apache.ode.bpel.o.OProcess;
+import org.apache.ode.bpel.o.OScope;
+import org.apache.ode.bpel.o.OXslSheet;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * @author mriou <mriou at apache dot org>
+ */
+public class JaxpFunctionResolver implements XPathFunctionResolver {
+
+    private static final Log __log = LogFactory.getLog(JaxpFunctionResolver.class);
+
+    private EvaluationContext _ectx;
+    private OXPath20ExpressionBPEL20 _oxpath;
+    private String _bpelNS;
+
+    public JaxpFunctionResolver(EvaluationContext ectx, OXPath20ExpressionBPEL20 oxpath, String bpelNS) {
+        _ectx = ectx;
+        _oxpath = oxpath;
+        _bpelNS = bpelNS;
+    }
+
+    public XPathFunction resolveFunction(QName functionName, int arity) {
+        __log.debug("Resolving function " + functionName);
+        if (functionName.getNamespaceURI() == null) {
+            throw new WrappedResolverException("Undeclared namespace for " + functionName);
+        } else if (functionName.getNamespaceURI().equals(_bpelNS)) {
+            String localName = functionName.getLocalPart();
+            if (Constants.EXT_FUNCTION_GETVARIABLEDATA.equals(localName)) {
+                return new GetVariableData();
+            } else if (Constants.EXT_FUNCTION_GETVARIABLEPROPRTY.equals(localName)) {
+                return new GetVariableProperty();
+            } else if (Constants.EXT_FUNCTION_GETLINKSTATUS.equals(localName)) {
+                return new GetLinkStatus();
+            } else if (Constants.EXT_FUNCTION_DOXSLTRANSFORM.equals(localName)) {
+                return new DoXslTransform();
+            } else {
+                throw new WrappedResolverException("Unknown BPEL function: " + functionName);
+            }
+        }
+
+        return null;
+    }
+
+    public class GetLinkStatus implements XPathFunction {
+        public Object evaluate(List args) throws XPathFunctionException {
+            assert args.size() == 1;
+
+            OLink olink = _oxpath.links.get(args.get(0));
+            try {
+                return _ectx.isLinkActive(olink) ? Boolean.TRUE : Boolean.FALSE;
+            } catch (FaultException e) {
+                throw new XPathFunctionException(e);
+            }
+        }
+    }
+
+    public class GetVariableData implements XPathFunction {
+        public Object evaluate(List args) throws XPathFunctionException {
+            if (__log.isDebugEnabled()) {
+                __log.debug("call(context=" + _ectx + " args=" + args + ")");
+            }
+
+            String varname  = (String) args.get(0);
+            String partname = args.size() > 1 ? (String) args.get(1) : null;
+            String xpathStr = args.size() > 2 ? (String)args.get(2) : null;
+
+            OXPath10Expression.OSigGetVariableData sig = _oxpath.resolveGetVariableDataSig(varname,partname,xpathStr);
+            if (sig == null) {
+                String msg = "InternalError: Attempt to use an unknown getVariableData signature: " + args;
+                if (__log.isFatalEnabled())
+                    __log.fatal(msg);
+                throw new XPathFunctionException(msg);
+            }
+
+            try {
+                Node ret = _ectx.readVariable(sig.variable, sig.part);
+                if (sig.location != null)
+                    ret = _ectx.evaluateQuery(ret, sig.location);
+
+                if (__log.isDebugEnabled()) {
+                    __log.debug("bpws:getVariableData(" + args +  ")' = " + ret);
+                }
+
+                return ret;
+            } catch (FaultException e) {
+                __log.error("bpws:getVariableData(" + args + ") threw FaultException");
+
+                throw new XPathFunctionException(e);
+            }
+        }
+    }
+
+    public class GetVariableProperty implements XPathFunction {
+        public Object evaluate(List args) throws XPathFunctionException {
+            if (args.size() != 2) {
+                throw new XPathFunctionException("missing required arguments");
+            }
+
+            OScope.Variable var = _oxpath.vars.get(args.get(0));
+            OProcess.OProperty property = _oxpath.properties.get(args.get(1));
+
+            if (__log.isDebugEnabled()) {
+                __log.debug("function call:'bpws:getVariableProperty(" + var + ","
+                        + property + ")'");
+            }
+
+            try {
+                return _ectx.readMessageProperty(var, property);
+            } catch (FaultException e) {
+                throw new XPathFunctionException(e);
+            }
+        }
+    }
+
+    public class DoXslTransform implements XPathFunction {
+        public Object evaluate(List args) throws XPathFunctionException {
+            assert args.size() >= 2;
+            assert args.size() % 2 == 0;
+            if (__log.isDebugEnabled()) {
+                __log.debug("call(context=" + _ectx + " args=" + args + ")");
+            }
+            if(!(_oxpath instanceof OXPath10ExpressionBPEL20)) {
+                throw new IllegalStateException("XPath function bpws:doXslTransform not supported in " +
+                        "BPEL 1.1!");
+            }
+
+            Element varElmt;
+            try {
+                if (args.get(1) instanceof List) {
+                    List elmts = (List)args.get(1);
+                    if (elmts.size() != 1) throw new XPathFunctionException(
+                            new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,
+                                    "Second parameter of the bpws:doXslTransform function MUST point to a single " +
+                                            "element node."));
+                    varElmt = (Element) elmts.get(0);
+                } else {
+                    if (args.get(1) instanceof NodeWrapper)
+                        varElmt = (Element) ((NodeWrapper)args.get(1)).getUnderlyingNode();
+                    else varElmt = (Element) args.get(1);
+                }
+            } catch (ClassCastException e) {
+                throw new XPathFunctionException(
+                        new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,
+                                "Second parameter of the bpws:doXslTransform function MUST point to a single " +
+                                        "element node."));
+            }
+
+            URI xslUri;
+            try {
+                xslUri = new URI((String) args.get(0));
+            } catch (URISyntaxException use) {
+                // Shouldn't happen, checked at compilation time
+                throw new XPathFunctionException("First parameter of the bpws:doXslTransform isn't a valid URI!");
+            }
+            OXslSheet xslSheet = _oxpath.xslSheets.get(xslUri);
+            // Shouldn't happen, checked at compilation time
+            if (xslSheet == null) throw new XPathFunctionException("Couldn't find the XSL sheet " + args.get(0)
+                    + ", process compilation or deployment was probably incomplete!");
+
+            if (!(varElmt instanceof Element)) {
+                throw new XPathFunctionException(
+                        new FaultException(_oxpath.getOwner().constants.qnXsltInvalidSource,
+                                "Second parameter of the bpws:doXslTransform function MUST point to a single " +
+                                        "element node."));
+            }
+
+            HashMap<QName, Object> parametersMap = null;
+            if (args.size() > 2) {
+                parametersMap = new HashMap<QName, Object>();
+                for (int idx = 2; idx < args.size(); idx+=2) {
+                    QName keyQName = _oxpath.namespaceCtx.derefQName((String) args.get(idx));
+                    Object paramElmt;
+                    if (args.get(idx + 1) instanceof NodeWrapper) {
+                        Element tmpElmt = (Element) ((NodeWrapper)args.get(idx + 1)).getUnderlyingNode();
+                        Document paramDoc = DOMUtils.newDocument();
+                        paramDoc.appendChild(paramDoc.importNode(tmpElmt, true));
+                        paramElmt = paramDoc;
+                        if (__log.isDebugEnabled())
+                            __log.debug("Passing parameter " + keyQName + " " + DOMUtils.domToString(paramDoc));
+                    } else paramElmt = args.get(idx + 1);
+
+                    parametersMap.put(keyQName, paramElmt);
+                }
+            }
+
+            if (__log.isDebugEnabled())
+                __log.debug("Executing XSL sheet " + args.get(0) + " on element " + DOMUtils.domToString(varElmt));
+
+            Document varDoc = DOMUtils.newDocument();
+            varDoc.appendChild(varDoc.importNode(varElmt, true));
+
+            DOMSource source = new DOMSource(varDoc);
+            // Using a StreamResult as a DOMResult doesn't behaves properly when the result
+            // of the transformation is just a string.
+            StringWriter writerResult = new StringWriter();
+            StreamResult result = new StreamResult(writerResult);
+            XslRuntimeUriResolver resolver = new XslRuntimeUriResolver(_oxpath);
+            XslTransformHandler.getInstance().cacheXSLSheet(xslUri, xslSheet.sheetBody, resolver);
+            try {
+                XslTransformHandler.getInstance().transform(xslUri, source, result, parametersMap, resolver);
+            } catch (Exception e) {
+                throw new XPathFunctionException(
+                        new FaultException(_oxpath.getOwner().constants.qnSubLanguageExecutionFault,
+                                e.toString()));
+            }
+            writerResult.flush();
+
+            String output = writerResult.toString();
+            if (__log.isDebugEnabled())
+                __log.debug("Returned by XSL Sheet: " + output);
+            // I'm not really proud of that but hey, it does the job and I don't think there's
+            // any other easy way.
+            if (output.startsWith("<?xml")) {
+                try {
+                    return DOMUtils.stringToDOM(output).getChildNodes();
+                } catch (SAXException e) {
+                    throw new XPathFunctionException("Parsing the result of the XSL sheet " + args.get(0) +
+                            " didn't produce a parsable XML result: " + output);
+                } catch (IOException e) {
+                    throw new XPathFunctionException(e);
+                } catch (Exception e) {
+                    throw new XPathFunctionException("Parsing the result of the XSL sheet " + args.get(0) +
+                            " didn't produce a parsable XML result: " + output);
+                }
+            } else {
+                return output;
+            }
+        }
+    }
+
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,149 @@
+/*
+ * 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.xpath20.runtime;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathVariableResolver;
+
+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.OXPath10ExpressionBPEL20;
+import org.apache.ode.bpel.elang.xpath20.WrappedResolverException;
+import org.apache.ode.bpel.explang.EvaluationContext;
+import org.apache.ode.bpel.o.OLink;
+import org.apache.ode.bpel.o.OMessageVarType;
+import org.apache.ode.bpel.o.OScope;
+import org.apache.ode.bpel.o.OXsdTypeVarType;
+import org.apache.ode.utils.Namespaces;
+import org.apache.ode.utils.xsd.XSTypes;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author mriou <mriou at apache dot org>
+ */
+public class JaxpVariableResolver implements XPathVariableResolver {
+
+    private static final Log __log = LogFactory.getLog(JaxpVariableResolver.class);
+
+    private EvaluationContext _ectx;
+    private OXPath10ExpressionBPEL20 _oxpath;
+
+    public JaxpVariableResolver(EvaluationContext ectx, OXPath10ExpressionBPEL20 oxpath) {
+        _ectx = ectx;
+        _oxpath = oxpath;
+    }
+
+    public Object resolveVariable(QName variableName) {
+        __log.debug("Resolving variable " + variableName);
+
+        if(!(_oxpath instanceof OXPath10ExpressionBPEL20)){
+            throw new IllegalStateException("XPath variables not supported for bpel 1.1");
+        }
+
+        // Custom variables
+        if (variableName.getNamespaceURI().equals(Namespaces.ODE_EXTENSION_NS)) {
+            if ("pid".equals(variableName.getLocalPart())) {
+                return _ectx.getProcessId();
+            }
+        }
+
+        OXPath10ExpressionBPEL20 expr = _oxpath;
+        if(expr.isJoinExpression){
+            OLink olink = _oxpath.links.get(variableName.getLocalPart());
+
+            try {
+                return _ectx.isLinkActive(olink) ? Boolean.TRUE : Boolean.FALSE;
+            } catch (FaultException e) {
+                throw new WrappedResolverException(e);
+            }
+        }else{
+            String varName;
+            String partName;
+            int dotloc = variableName.getLocalPart().indexOf('.');
+            if (dotloc == -1) {
+                varName = variableName.getLocalPart();
+                partName = null;
+            } else {
+                varName = variableName.getLocalPart().substring(0, dotloc);
+                partName = variableName.getLocalPart().substring(dotloc + 1);
+            }
+            OScope.Variable variable = _oxpath.vars.get(varName);
+            OMessageVarType.Part part = partName == null ? null : ((OMessageVarType)variable.type).parts.get(partName);
+
+            try{
+                Node variableNode = _ectx.readVariable(variable, part);
+                if (variableNode == null)
+                    throw new FaultException(variable.getOwner().constants.qnSelectionFailure, "Unknown variable " + variableName.getLocalPart());
+                if (variable.type instanceof OXsdTypeVarType && ((OXsdTypeVarType)variable.type).simple) 
+                	return getSimpleContent(variableNode,((OXsdTypeVarType)variable.type).xsdType);
+                if (part != null && part.type instanceof OXsdTypeVarType && ((OXsdTypeVarType)part.type).simple)
+                	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);
+                
+            }catch(FaultException e){
+                throw new WrappedResolverException(e);
+            }
+        }
+    }
+    
+    private Object getSimpleContent(Node simpleNode, QName type) {
+        String text = simpleNode.getTextContent();
+        try {
+    		return XSTypes.toJavaObject(type,text);
+    	} 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) { }
+        // 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;
+        }
+        
+        public Node item(int index) {
+            if (index != 0)
+                throw new IndexOutOfBoundsException(""+index);
+            return _node;
+        }
+
+        public int getLength() {
+            return 1;
+        }
+        
+    }
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpVariableResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,200 @@
+/*
+ * 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.xpath20.runtime;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+
+import net.sf.saxon.xpath.XPathEvaluator;
+import net.sf.saxon.trans.DynamicError;
+
+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.Constants;
+import org.apache.ode.bpel.elang.xpath20.WrappedResolverException;
+import org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20;
+import org.apache.ode.bpel.explang.ConfigurationException;
+import org.apache.ode.bpel.explang.EvaluationContext;
+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.utils.DOMUtils;
+import org.apache.ode.utils.xsd.Duration;
+import org.apache.ode.utils.xsd.XMLCalendar;
+import org.apache.ode.utils.xsl.XslTransformHandler;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * XPath 2.0 Expression Language run-time subsytem.
+ * Saxon implementation.
+ */
+public class XPath20ExpressionRuntime implements ExpressionLanguageRuntime {
+
+    static final short NODE_TYPE = 1;
+    static final short NODESET_TYPE = 2;
+    static final short STRING_TYPE = 3;
+    static final short BOOLEAN_TYPE = 4;
+    static final short NUMBER_TYPE = 5;
+
+    /** Class-level logger. */
+    private static final Log __log = LogFactory.getLog(XPath20ExpressionRuntime.class);
+
+    public XPath20ExpressionRuntime(){
+    }
+
+    public void initialize(Map properties) throws ConfigurationException {
+        TransformerFactory trsf = new net.sf.saxon.TransformerFactoryImpl();
+        XslTransformHandler.getInstance().setTransformerFactory(trsf);
+    }
+
+    /**
+     * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluateAsString(org.apache.ode.bpel.o.OExpression, org.apache.ode.bpel.explang.EvaluationContext)
+     */
+    public String evaluateAsString(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+        return (String)evaluate(cexp, ctx, XPathConstants.STRING);
+    }
+
+    /**
+     * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluateAsBoolean(org.apache.ode.bpel.o.OExpression, org.apache.ode.bpel.explang.EvaluationContext)
+     */
+    public boolean evaluateAsBoolean(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+        return (Boolean) evaluate(cexp, ctx, XPathConstants.BOOLEAN);
+    }
+
+    public Number evaluateAsNumber(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+        return (Number) evaluate(cexp, ctx, XPathConstants.NUMBER);
+    }
+
+    /**
+     * @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 {
+        List result;
+        Object someRes = evaluate(cexp, ctx, XPathConstants.NODESET);
+        if (someRes instanceof List) {
+            result = (List) someRes;
+            if ((result.size() == 1) && !(result.get(0) instanceof Node)) {
+              Document d = DOMUtils.newDocument();
+              // Giving our node a parent just in case it's an LValue expression
+              Element wrapper = d.createElement("wrapper");
+              Text text = d.createTextNode(result.get(0).toString());
+              wrapper.appendChild(text);
+              d.appendChild(wrapper);
+              result = Collections.singletonList(text);
+            }
+        } else if (someRes instanceof NodeList) {
+            NodeList retVal = (NodeList) someRes;
+            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();
+                result.add(val);
+            }
+        } else {
+            result = null;
+        }
+
+        return result;
+    }
+
+    public Node evaluateNode(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException {
+        List retVal = evaluate(cexp, ctx);
+        if (retVal.size() == 0)
+            throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "No results for expression: " + cexp);
+        if (retVal.size() > 1)
+            throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "Multiple results for expression: " + cexp);
+        return (Node) retVal.get(0);
+    }
+
+    public Calendar evaluateAsDate(OExpression cexp, EvaluationContext context) throws FaultException, EvaluationException {
+
+        String literal = evaluateAsString(cexp, context);
+
+        try {
+            return new XMLCalendar(literal);
+        } catch (Exception ex) {
+            __log.error("Date conversion error." ,ex);
+            throw new EvaluationException("Date conversion errror.", ex);
+        }
+    }
+
+    public Duration evaluateAsDuration(OExpression cexp, EvaluationContext context) throws FaultException, EvaluationException {
+        String literal = this.evaluateAsString(cexp, context);
+        try {
+            return new Duration(literal);
+        } catch (Exception ex) {
+            __log.error("Date conversion error.", ex);
+            throw new EvaluationException("Duration conversion error." ,ex);
+        }
+    }
+
+    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, Constants.BPEL20_NS));
+            xpf.setXPathVariableResolver(new JaxpVariableResolver(ctx, oxpath20));
+            XPathEvaluator xpe = (XPathEvaluator) xpf.newXPath();
+            xpe.setNamespaceContext(oxpath20.namespaceCtx);
+            // Just checking that the expression is valid
+            XPathExpression expr = xpe.compile(((OXPath10Expression)cexp).xpath);
+
+            Object evalResult = expr.evaluate(ctx.getRootNode() == null ? DOMUtils.newDocument() : ctx.getRootNode(), type);
+            if (evalResult != null && __log.isDebugEnabled())
+                __log.debug("Expression " + cexp.toString() + " generated result " + evalResult
+                        + " - type=" + evalResult.getClass().getName());
+            return evalResult;
+        } catch (XPathExpressionException e) {
+            // Extracting the real cause from all this wrapping isn't a simple task
+            Throwable cause = e.getCause() != null ? e.getCause() : e;
+            if (cause instanceof DynamicError) {
+                Throwable th = ((DynamicError)cause).getException();
+                if (th != null) {
+                    cause = th;
+                    if (cause.getCause() != null) cause = cause.getCause();
+                }
+            }
+            throw new EvaluationException("Error while executing an XPath expression: " + cause.toString(), cause);
+        } catch (WrappedResolverException wre) {
+            wre.printStackTrace();
+            throw (FaultException)wre.getCause();
+        } catch (Throwable t) {
+            t.printStackTrace();
+            throw new EvaluationException("Error while executing an XPath expression: ", t);
+        }
+
+    }
+
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntime.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,50 @@
+/*
+ * 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.xpath20.runtime;
+
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.o.OXslSheet;
+
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamSource;
+import java.net.URI;
+import java.io.StringReader;
+
+/**
+ * Used to give the Xsl processor a way to access included XSL sheets
+ * by using the maps of sheets pre-processed at compilation time and
+ * stored in the OXPath10Expression.
+ */
+public class XslRuntimeUriResolver implements URIResolver {
+
+  private OXPath10Expression _expr;
+
+  public XslRuntimeUriResolver(OXPath10Expression expr) {
+    _expr = expr;
+  }
+
+  public Source resolve(String href, String base) throws TransformerException {
+    URI uri = URI.create(href);
+    OXslSheet sheet = _expr.xslSheets.get(uri);
+    return new StreamSource(new StringReader(sheet.sheetBody));
+  }
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java?view=auto&rev=480289
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java Tue Nov 28 15:47:00 2006
@@ -0,0 +1,185 @@
+package org.apache.ode.bpel.elang.xpath20.runtime;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Operation;
+import javax.xml.namespace.QName;
+
+import org.apache.ode.bpel.compiler.api.CompilationException;
+import org.apache.ode.bpel.compiler.api.CompilerContext;
+import org.apache.ode.bpel.compiler.bom.Activity;
+import org.apache.ode.bpel.compiler.bom.BpelObject;
+import org.apache.ode.bpel.compiler.bom.Expression;
+import org.apache.ode.bpel.compiler.bom.ScopeLikeActivity;
+import org.apache.ode.bpel.o.OActivity;
+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.OLink;
+import org.apache.ode.bpel.o.OMessageVarType;
+import org.apache.ode.bpel.o.OPartnerLink;
+import org.apache.ode.bpel.o.OProcess;
+import org.apache.ode.bpel.o.OScope;
+import org.apache.ode.bpel.o.OXsdTypeVarType;
+import org.apache.ode.bpel.o.OXslSheet;
+import org.apache.ode.bpel.o.OMessageVarType.Part;
+import org.apache.ode.bpel.o.OProcess.OProperty;
+import org.apache.ode.bpel.o.OProcess.OPropertyAlias;
+import org.apache.ode.bpel.o.OScope.CorrelationSet;
+import org.apache.ode.bpel.o.OScope.Variable;
+import org.apache.ode.utils.NSContext;
+
+public class MockCompilerContext implements CompilerContext {
+    private OProcess _oprocess = new OProcess("20");
+    private Map<String , Variable> _vars =new  HashMap<String, Variable>();
+    
+    public OExpression constantExpr(boolean value) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    public OExpression compileJoinCondition(Expression expr) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OExpression compileExpr(Expression expr) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OLValueExpression compileLValueExpr(Expression expr) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OXslSheet compileXslt(String docStrUri) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OXsdTypeVarType resolveXsdType(QName typeName) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OProperty resolveProperty(QName name) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Variable resolveVariable(String name) throws CompilationException {
+        return _vars.get(name);
+    }
+
+    public List<Variable> getAccessibleVariables() {
+        return new ArrayList<Variable>(_vars.values());
+    }
+
+    public Variable resolveMessageVariable(String inputVar) throws CompilationException {
+        return _vars.get(inputVar);
+    }
+
+    public Variable resolveMessageVariable(String inputVar, QName messageType) throws CompilationException {
+        return _vars.get(inputVar);
+    }
+
+    public Part resolvePart(Variable variable, String partname) throws CompilationException {
+        return ((OMessageVarType)variable.type).parts.get(partname);
+    }
+
+    public OActivity compile(Activity child) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OActivity compileSLC(Activity source) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OPartnerLink resolvePartnerLink(String name) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Operation resolvePartnerRoleOperation(OPartnerLink partnerLink, String operationName) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Operation resolveMyRoleOperation(OPartnerLink partnerLink, String operationName) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OPropertyAlias resolvePropertyAlias(Variable variable, QName property) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void recoveredFromError(Object where, CompilationException bce) throws CompilationException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public OLink resolveLink(String linkName) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OScope resolveCompensatableScope(String scopeToCompensate) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public OProcess getOProcess() throws CompilationException {
+        return _oprocess;
+    }
+
+    public CorrelationSet resolveCorrelationSet(String csetName) throws CompilationException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getSourceLocation() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void compile(OActivity context, BpelObject activity, Runnable run) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public boolean isPartnerLinkAssigned(String plink) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public List<OActivity> getActivityStack() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void registerElementVar(String name, QName type) {
+        OElementVarType varType = new OElementVarType(getOProcess(),type);
+        OScope.Variable var = new OScope.Variable(getOProcess(),varType);
+        var.name = name;
+        _vars.put(name, var);
+    }
+    public OExpression compileExpr(String locationstr, NSContext nsContext) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    public OActivity getCurrent() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    public OScope compileSLC(ScopeLikeActivity child, Variable[] variables) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Propchange: incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/ode/trunk/bpel-compiler/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/MockCompilerContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain