Author: karthick
Date: Fri Feb 6 00:55:15 2009
New Revision: 741359
URL: http://svn.apache.org/viewvc?rev=741359&view=rev
Log:
Handle all data types while (a) binding values to variables and (b) extracting
values from the result.
Modified:
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v2/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/xquery10/runtime/XQuery10ExpressionRuntime.java
Modified:
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v2/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
URL:
http://svn.apache.org/viewvc/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v2/xquery10/compiler/XQuery10ExpressionCompilerImpl.java?rev=741359&r1=741358&r2=741359&view=diff
==============================================================================
---
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v2/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
(original)
+++
ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/v2/xquery10/compiler/XQuery10ExpressionCompilerImpl.java
Fri Feb 6 00:55:15 2009
@@ -254,7 +254,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/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=741359&r1=741358&r2=741359&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
Fri Feb 6 00:55:15 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;
@@ -351,7 +353,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) {
@@ -373,7 +375,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);
+ }
}
}
}
@@ -506,21 +510,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;
}
@@ -553,11 +553,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;
}