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/1e141c2d Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/1e141c2d Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/1e141c2d Branch: refs/heads/ode-1.3.x Commit: 1e141c2de692df9675a5ec26d9614ee47dcce0eb Parents: 7988af2 Author: Tammo van Lessen <[email protected]> Authored: Mon Feb 2 19:54:36 2015 +0100 Committer: Tammo van Lessen <[email protected]> Committed: Wed Feb 11 13:42:42 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/1e141c2d/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 ecf34a4..96ede14 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;
