You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ka...@apache.org on 2009/02/06 01:54:57 UTC

svn commit: r741358 - in /ode/branches/APACHE_ODE_1.X: bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/ bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/

Author: karthick
Date: Fri Feb  6 00:54:56 2009
New Revision: 741358

URL: http://svn.apache.org/viewvc?rev=741358&view=rev
Log:
Handle all data types while (a) binding values to variables and (b) extracting values from the result.

Modified:
    ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
    ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10ExpressionRuntime.java

Modified: ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java?rev=741358&r1=741357&r2=741358&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-compiler/src/main/java/org/apache/ode/bpel/elang/xquery10/compiler/XQuery10ExpressionCompilerImpl.java Fri Feb  6 00:54:56 2009
@@ -29,6 +29,7 @@
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerFactory;
+import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xquery.XQConnection;
 import javax.xml.xquery.XQConstants;
 import javax.xml.xquery.XQDataSource;
@@ -254,7 +255,12 @@
             		}
             	}
             }
-            exp.executeQuery();
+            // evaluate the expression so as to initialize the variables
+            try { 
+                exp.executeQuery();
+            } catch (XQException xpee) { 
+            	// swallow errors caused by uninitialized variables 
+            }
         } catch (XQException xqe) {
             __log.debug(xqe);
             __log.info("Couldn't validate properly expression " + xqueryStr);

Modified: ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10ExpressionRuntime.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10ExpressionRuntime.java?rev=741358&r1=741357&r2=741358&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10ExpressionRuntime.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xquery10/runtime/XQuery10ExpressionRuntime.java Fri Feb  6 00:54:56 2009
@@ -24,6 +24,7 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
@@ -38,6 +39,7 @@
 import javax.xml.xquery.XQPreparedExpression;
 import javax.xml.xquery.XQResultSequence;
 import javax.xml.xquery.XQSequence;
+import javax.xml.xquery.XQSequenceType;
 import javax.xml.xquery.XQStaticContext;
 
 import net.sf.saxon.Configuration;
@@ -359,7 +361,7 @@
                 Object value = variableResolver.resolveVariable(variable);
                 
                 // Figure out type of variable
-                XQItemType xqType = getItemType(xqconn, value);
+                XQSequenceType xqType = getItemType(xqconn, value);
                 
                 // Saxon doesn't like binding sequences to variables
                 if (value instanceof Node) {
@@ -381,7 +383,9 @@
                 	if (value instanceof XQSequence) {
                 		exp.bindSequence(variable, (XQSequence) value);
                 	} else {
-		                exp.bindObject(variable, value, xqType);
+                		if (xqType instanceof XQItemType) {
+			                exp.bindObject(variable, value, (XQItemType) xqType);
+                		}
                 	}
                 }
             }
@@ -501,6 +505,7 @@
             itemValue = item.getAtomicValue();
 
             break;
+            
         }
 
         return itemValue;
@@ -516,21 +521,17 @@
      *
      * @throws XQException XQException 
      */
-    private XQItemType getItemType(XQConnection xqconn, Object value) throws XQException {
-        XQItemType xqType = null;
+    private XQSequenceType getItemType(XQConnection xqconn, Object value) throws XQException {
+        XQSequenceType xqType = null;
         if (value instanceof Long) {
             xqType = xqconn.createAtomicType(XQItemType.XQBASETYPE_LONG);
         } else if (value instanceof String) {
             xqType = xqconn.createAtomicType(XQItemType.XQBASETYPE_STRING);
-        } else if (value instanceof NodeList) {
-            NodeList nodeList = (NodeList) value;
-
-            if (nodeList.getLength() == 1) {
-                xqType = xqconn.createNodeType();
-                value = nodeList.item(0);
-            } else {
-                value = null;
-            }
+        } else if (value instanceof Node) {
+        	xqType = xqconn.createNodeType();
+        } else if (value instanceof NodeList || value instanceof XQSequence) {
+            XQItemType xqItemType = xqconn.createNodeType();
+            xqType = xqconn.createSequenceType(xqItemType, XQSequenceType.OCC_ZERO_OR_MORE);
         }
         return xqType;
     }
@@ -563,11 +564,28 @@
             }
 
             resultValue = list;
-        } else {
-            resultValue = getItemValue(result.getItem());
-            if (resultValue instanceof Node) {
-            	resultValue = DOMUtils.cloneNode(document, (Node) resultValue); 
-            }
+        } else if (XPathConstants.NODE.equals(type)) {
+        	XQItem item = null;
+    		if (result.count() > 0) {
+    			result.first();
+    			if (result.isOnItem()) {
+    				item = result.getItem();
+    			}
+    		}
+    		if (item != null) {
+	            resultValue = getItemValue(item);
+	            if (resultValue instanceof Node) {
+	            	resultValue = DOMUtils.cloneNode(document, (Node) resultValue); 
+	            }
+    		}
+        } else if (XPathConstants.STRING.equals(type)) {
+        	resultValue = result.getSequenceAsString(new Properties());
+        } else if (XPathConstants.NUMBER.equals(type)) {
+        	resultValue = result.getSequenceAsString(new Properties());
+    		resultValue = Integer.parseInt((String) resultValue);
+        } else if (XPathConstants.BOOLEAN.equals(type)) {
+        	resultValue = result.getSequenceAsString(new Properties());
+    		resultValue = Boolean.parseBoolean((String) resultValue);
         }
     	return resultValue;
     }