ODE-1027: Properly cast numbers in XPath 1.0 expressions.

Project: http://git-wip-us.apache.org/repos/asf/ode/repo
Commit: http://git-wip-us.apache.org/repos/asf/ode/commit/28dcae93
Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/28dcae93
Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/28dcae93

Branch: refs/heads/master
Commit: 28dcae93d007ede3b93b7e9df53584d021452e45
Parents: f17a322
Author: Tammo van Lessen <[email protected]>
Authored: Mon Feb 2 19:54:36 2015 +0100
Committer: Tammo van Lessen <[email protected]>
Committed: Mon Feb 2 19:54:36 2015 +0100

----------------------------------------------------------------------
 .../elang/xpath10/runtime/JaxenContexts.java    | 35 +++++++++++++++++---
 1 file changed, 31 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ode/blob/28dcae93/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
----------------------------------------------------------------------
diff --git 
a/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
 
b/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
index 90643e4..7cc32c8 100644
--- 
a/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
+++ 
b/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
@@ -69,6 +69,18 @@ class JaxenContexts implements FunctionContext, 
VariableContext {
     private static final FunctionContext __defaultXPathFunctions = 
XPathFunctionContext.getInstance();
     
     private static final QName BOOLEAN = new 
QName("http://www.w3.org/2001/XMLSchema";, "boolean");
+    private static final QName BYTE = new 
QName("http://www.w3.org/2001/XMLSchema";, "byte");
+    private static final QName INT = new 
QName("http://www.w3.org/2001/XMLSchema";, "int");
+    private static final QName INTEGER = new 
QName("http://www.w3.org/2001/XMLSchema";, "integer");
+    private static final QName LONG = new 
QName("http://www.w3.org/2001/XMLSchema";, "long");
+    private static final QName SHORT = new 
QName("http://www.w3.org/2001/XMLSchema";, "short");
+    private static final QName UNSIGNED_INT = new 
QName("http://www.w3.org/2001/XMLSchema";, "unsignedInt");
+    private static final QName UNSIGNED_SHORT = new 
QName("http://www.w3.org/2001/XMLSchema";, "unsignedShort");
+    private static final QName UNSIGNED_BYTE = new 
QName("http://www.w3.org/2001/XMLSchema";, "unsignedByte");
+    private static final QName DECIMAL = new 
QName("http://www.w3.org/2001/XMLSchema";, "decimal");
+    private static final QName FLOAT = new 
QName("http://www.w3.org/2001/XMLSchema";, "float");
+    private static final QName DOUBLE = new 
QName("http://www.w3.org/2001/XMLSchema";, "double");
+
 
     private OXPath10Expression _oxpath;
     private EvaluationContext _xpathEvalCtx;
@@ -189,10 +201,25 @@ class JaxenContexts implements FunctionContext, 
VariableContext {
                 if (_xpathEvalCtx.narrowTypes() && type instanceof 
OXsdTypeVarType && ((OXsdTypeVarType)type).simple) {
                        String value = variableNode.getTextContent();
                        OXsdTypeVarType theType = (OXsdTypeVarType)type;
-                       
-                       if (BOOLEAN.equals(theType.xsdType)) {
-                               return new Boolean(value) ;
-                       }
+
+                    // cast booleans to boolean
+                    if (BOOLEAN.equals(theType.xsdType)) {
+                        return new Boolean(value) ;
+                    }
+
+                    // and numbers to numbers (XPath only understands Double, 
so Double it shall be.
+                    if (INT.equals(theType.xsdType) || 
UNSIGNED_SHORT.equals(theType.xsdType) ||
+                            INTEGER.equals(theType.xsdType) ||
+                            LONG.equals(theType.xsdType) || 
UNSIGNED_INT.equals(theType.xsdType) ||
+                            SHORT.equals(theType.xsdType) || 
UNSIGNED_BYTE.equals(theType.xsdType) ||
+                            BYTE.equals(theType.xsdType) ||
+                            DECIMAL.equals(theType.xsdType) ||
+                            FLOAT.equals(theType.xsdType) ||
+                            DOUBLE.equals(theType.xsdType)
+                            ) {
+                        return new Double(value);
+                    }
+
                     return value;
                 } else {
                     return variableNode;

Reply via email to