ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From karth...@apache.org
Subject svn commit: r740569 - in /ode/trunk: bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/ runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/xquery10/runtime/ utils/src/main/java/org/apache/ode/utils/
Date Wed, 04 Feb 2009 01:32:40 GMT
Author: karthick
Date: Wed Feb  4 01:32:40 2009
New Revision: 740569

URL: http://svn.apache.org/viewvc?rev=740569&view=rev
Log:
Make sure that (a) variable nodes are bound properly and (b) xquery result node has a owner
document.

Modified:
    ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/HelloXQueryWorld.bpel
    ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/xquery10/runtime/XQuery10ExpressionRuntime.java
    ode/trunk/utils/src/main/java/org/apache/ode/utils/DOMUtils.java

Modified: ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/HelloXQueryWorld.bpel
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/HelloXQueryWorld.bpel?rev=740569&r1=740568&r2=740569&view=diff
==============================================================================
--- ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/HelloXQueryWorld.bpel
(original)
+++ ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXQueryExpression/HelloXQueryWorld.bpel
Wed Feb  4 01:32:40 2009
@@ -25,8 +25,8 @@
     xmlns:types="http://ode/bpel/types"
     xmlns:test="http://ode/bpel/unit-test.wsdl"
 	xmlns:ode="http://www.apache.org/ode/type/extension"
-    queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0"
-    expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0">
+    queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
+    expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">
 
     <import location="HelloXQueryWorld.wsdl"
         namespace="http://ode/bpel/unit-test.wsdl"
@@ -58,11 +58,11 @@
                 <to variable="otherVar"/>
             </copy>
             <copy>
-                <from><![CDATA[<test:content>Hello</test:content>]]></from>
+                <from expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0"><![CDATA[<test:content>Hello</test:content>]]></from>
                 <to variable="tempVar"/>
             </copy>
             <copy>
-                <from>
+                <from expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0">
 					typeswitch ($myVar.TestPart) 
 				      case $a as xs:string return "test"
 					  default return "default"
@@ -70,7 +70,7 @@
                 <to variable="otherVar"/>
             </copy>
             <copy>
-                <from><![CDATA[
+                <from  expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0"><![CDATA[
 					typeswitch ($myVar.TestPart) 
 				      case $a as text() return <test:content/>
 					  default return <test:content/>
@@ -80,7 +80,7 @@
             </copy>
 			<!-- this copy will fail since saxon is not schema-aware 
             <copy>
-                <from>
+                <from expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0">
 					typeswitch ($myVar.TestPart) 
 				      case $a as element(*, test:content) return "test"
 					  default return "default"
@@ -89,7 +89,7 @@
             </copy>
 			-->
             <copy>
-                <from>
+                <from  expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xquery1.0">
 					for $loopOnce in (1) 
 					return 
 						concat(bpws:getVariableProperty("myVar", "test:content"), "XQuery World")

Modified: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/xquery10/runtime/XQuery10ExpressionRuntime.java
URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/xquery10/runtime/XQuery10ExpressionRuntime.java?rev=740569&r1=740568&r2=740569&view=diff
==============================================================================
--- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/xquery10/runtime/XQuery10ExpressionRuntime.java
(original)
+++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/xquery10/runtime/XQuery10ExpressionRuntime.java
Wed Feb  4 01:32:40 2009
@@ -354,7 +354,10 @@
                 XQItemType xqType = getItemType(xqconn, value);
                 
                 // Saxon doesn't like binding sequences to variables
-                if (value instanceof NodeList) {
+                if (value instanceof Node) {
+                	// a node is a node-list, but the inverse isn't true.
+                	// so, if the value is truly a node, leave it alone.
+                } else if (value instanceof NodeList) {
                     // So extract the first item from the node list
                 	NodeList nodeList = (NodeList) value;
                 	ArrayList nodeArray = new ArrayList();
@@ -533,12 +536,16 @@
      * @throws XQException XQException 
      */
     private Object getResultValue(QName type, XQResultSequence result) throws XQException
{
+    	Document document = DOMUtils.newDocument();
     	Object resultValue = null;
         if (XPathConstants.NODESET.equals(type)) {
             List list = new ArrayList();
 
             while (result.next()) {
                 Object itemValue = getItemValue(result.getItem());
+                if (itemValue instanceof Node) {
+                	itemValue = DOMUtils.cloneNode(document, (Node) itemValue); 
+                }
 
                 if (itemValue != null) {
                     list.add(itemValue);
@@ -548,6 +555,9 @@
             resultValue = list;
         } else {
             resultValue = getItemValue(result.getItem());
+            if (resultValue instanceof Node) {
+            	resultValue = DOMUtils.cloneNode(document, (Node) resultValue); 
+            }
         }
     	return resultValue;
     }

Modified: ode/trunk/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
URL: http://svn.apache.org/viewvc/ode/trunk/utils/src/main/java/org/apache/ode/utils/DOMUtils.java?rev=740569&r1=740568&r2=740569&view=diff
==============================================================================
--- ode/trunk/utils/src/main/java/org/apache/ode/utils/DOMUtils.java (original)
+++ ode/trunk/utils/src/main/java/org/apache/ode/utils/DOMUtils.java Wed Feb  4 01:32:40 2009
@@ -56,12 +56,16 @@
 import org.apache.xml.serialize.OutputFormat;
 import org.apache.xml.serialize.XMLSerializer;
 import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
 import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
@@ -1061,4 +1065,65 @@
     	String prefix = qName.getPrefix(), localPart = qName.getLocalPart();
     	return (prefix == null || "".equals(prefix)) ? localPart : (prefix + ":" + localPart);
     }
+
+    public static Node cloneNode(Document document, Node node) {
+    	Node clone = null;
+    	String namespaceURI = node.getNamespaceURI();
+    	String localName = node.getLocalName();
+    	switch (node.getNodeType()) {
+    	case Node.ATTRIBUTE_NODE:
+    		if (namespaceURI == null) {
+    			clone = document.createAttribute(localName);
+    		} else {
+        		clone = document.createAttributeNS(namespaceURI, localName);
+    		}
+			break;
+    	case Node.CDATA_SECTION_NODE:
+    		clone = document.createCDATASection(((CDATASection) node).getData());
+			break;
+    	case Node.COMMENT_NODE:
+    		clone = document.createComment(((Comment) node).getData());
+			break;
+    	case Node.DOCUMENT_FRAGMENT_NODE:
+    		clone = document.createDocumentFragment();
+			break;
+    	case Node.DOCUMENT_NODE:
+    		clone = document;
+			break;
+    	case Node.ELEMENT_NODE:
+    		if (namespaceURI == null) {
+	    		clone = document.createElement(localName);
+    		} else {
+    			clone = document.createElementNS(namespaceURI, localName);
+    		}
+			break;
+    	case Node.ENTITY_NODE:
+    		// TODO
+			break;
+    	case Node.ENTITY_REFERENCE_NODE:
+    		clone = document.createEntityReference(localName);
+    		// TODO
+			break;
+    	case Node.NOTATION_NODE:
+    		// TODO
+			break;
+    	case Node.PROCESSING_INSTRUCTION_NODE:
+    		clone = document.createProcessingInstruction(((ProcessingInstruction) node).getData(),
localName);
+			break;
+    	case Node.TEXT_NODE:
+    		clone = document.createTextNode(((Text) node ).getData());
+			break;
+		default:
+			break;
+    	}
+
+    	NodeList children = node.getChildNodes();
+    	if (children != null) {
+	    	for (int i = 0; i < children.getLength(); i++) {
+	    		clone.appendChild(cloneNode(document, children.item(i)));
+	    	}
+    	}
+	    		
+    	return clone;
+    }
 }



Mime
View raw message