/** * Determine the data type of the items returned by the expression, if possible * @return a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, * or Type.ITEM (meaning not known in advance) * @param th the type hierarchy cache */ public ItemType getItemType(TypeHierarchy th) { if (requiredType.equals(BuiltInAtomicType.DOUBLE)) { return BuiltInAtomicType.DOUBLE; } else { return BuiltInAtomicType.FLOAT; } }
/** * Determine the data type of the items returned by the expression, if possible * @return a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, * or Type.ITEM (meaning not known in advance) * @param th the type hierarchy cache */ public ItemType getItemType(TypeHierarchy th) { if (requiredType.equals(BuiltInAtomicType.DOUBLE)) { return BuiltInAtomicType.DOUBLE; } else { return BuiltInAtomicType.FLOAT; } }
/** * Determine whether two primitive atomic types are comparable under the rules for GeneralComparisons * (that is, untyped atomic values treated as comparable to anything) * * @param t1 the first type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param t2 the second type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param ordered true if testing for an ordering comparison (lt, gt, le, ge). False * if testing for an equality comparison (eq, ne) * @return true if the types are comparable, as defined by the rules of the "=" operator */ public static boolean isGenerallyComparable(/*@NotNull*/ BuiltInAtomicType t1, /*@NotNull*/ BuiltInAtomicType t2, boolean ordered) { return t1.equals(BuiltInAtomicType.ANY_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_ATOMIC) || t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t2.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || isGuaranteedComparable(t1, t2, ordered); }
/** * Determine whether two primitive atomic types are comparable under the rules for GeneralComparisons * (that is, untyped atomic values treated as comparable to anything) * * @param t1 the first type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param t2 the second type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param ordered true if testing for an ordering comparison (lt, gt, le, ge). False * if testing for an equality comparison (eq, ne) * @return true if the types are comparable, as defined by the rules of the "=" operator */ public static boolean isGenerallyComparable(/*@NotNull*/ BuiltInAtomicType t1, /*@NotNull*/ BuiltInAtomicType t2, boolean ordered) { return t1.equals(BuiltInAtomicType.ANY_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_ATOMIC) || t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t2.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || isGuaranteedComparable(t1, t2, ordered); }
/** * Determine whether two primitive atomic types are guaranteed comparable under the rules for GeneralComparisons * (that is, untyped atomic values treated as comparable to anything). This method returns false if a run-time * check is necessary. * * @param t1 the first type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param t2 the second type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param ordered true if testing for an ordering comparison (lt, gt, le, ge). False * if testing for an equality comparison (eq, ne) * @return true if the types are comparable, as defined by the rules of the "=" operator */ public static boolean isGuaranteedGenerallyComparable(/*@NotNull*/ BuiltInAtomicType t1, /*@NotNull*/ BuiltInAtomicType t2, boolean ordered) { return !(t1.equals(BuiltInAtomicType.ANY_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_ATOMIC)) && isGenerallyComparable(t1, t2, ordered); }
/** * Determine whether two primitive atomic types are guaranteed comparable under the rules for GeneralComparisons * (that is, untyped atomic values treated as comparable to anything). This method returns false if a run-time * check is necessary. * * @param t1 the first type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param t2 the second type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param ordered true if testing for an ordering comparison (lt, gt, le, ge). False * if testing for an equality comparison (eq, ne) * @return true if the types are comparable, as defined by the rules of the "=" operator */ public static boolean isGuaranteedGenerallyComparable(/*@NotNull*/ BuiltInAtomicType t1, /*@NotNull*/ BuiltInAtomicType t2, boolean ordered) { return !(t1.equals(BuiltInAtomicType.ANY_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_ATOMIC)) && isGenerallyComparable(t1, t2, ordered); }
return true; // short cut if (t1.equals(BuiltInAtomicType.ANY_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_ATOMIC)) { return true; // meaning we don't actually know at this stage return t2.isPrimitiveNumeric(); if (t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t1.equals(BuiltInAtomicType.ANY_URI)) { t1 = BuiltInAtomicType.STRING; if (t2.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_URI)) { t2 = BuiltInAtomicType.STRING; if (t1.equals(BuiltInAtomicType.DAY_TIME_DURATION)) { t1 = BuiltInAtomicType.DURATION; if (t2.equals(BuiltInAtomicType.DAY_TIME_DURATION)) { t2 = BuiltInAtomicType.DURATION; if (t1.equals(BuiltInAtomicType.YEAR_MONTH_DURATION)) { t1 = BuiltInAtomicType.DURATION; if (t2.equals(BuiltInAtomicType.YEAR_MONTH_DURATION)) { t2 = BuiltInAtomicType.DURATION;
return t2.isPrimitiveNumeric(); if (t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t1.equals(BuiltInAtomicType.ANY_URI)) { t1 = BuiltInAtomicType.STRING; if (t2.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_URI)) { t2 = BuiltInAtomicType.STRING; if (t1.equals(BuiltInAtomicType.DAY_TIME_DURATION)) { t1 = BuiltInAtomicType.DURATION; if (t2.equals(BuiltInAtomicType.DAY_TIME_DURATION)) { t2 = BuiltInAtomicType.DURATION; if (t1.equals(BuiltInAtomicType.YEAR_MONTH_DURATION)) { t1 = BuiltInAtomicType.DURATION; if (t2.equals(BuiltInAtomicType.YEAR_MONTH_DURATION)) { t2 = BuiltInAtomicType.DURATION;
private static Object getCollationKey(AtomicValue value, BuiltInAtomicType itemType, StringCollator collation, XPathContext context) throws XPathException { Object val; if (itemType.equals(BuiltInAtomicType.STRING) || itemType.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || itemType.equals(BuiltInAtomicType.ANY_URI)) { if (collation==null) { val = value.getStringValue(); } else { val = collation.getCollationKey(value.getStringValue()); } } else { val = value.getXPathComparable(false, collation, context); } return val; }
private static Object getCollationKey(AtomicValue value, BuiltInAtomicType itemType, StringCollator collation, XPathContext context) throws XPathException { Object val; if (itemType.equals(BuiltInAtomicType.STRING) || itemType.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || itemType.equals(BuiltInAtomicType.ANY_URI)) { if (collation==null) { val = value.getStringValue(); } else { val = collation.getCollationKey(value.getStringValue()); } } else { val = value.getXPathComparable(false, collation, context); } return val; }
private static Object getCollationKey(AtomicValue value, BuiltInAtomicType itemType, StringCollator collation, XPathContext context) throws XPathException { Object val; if (itemType.equals(BuiltInAtomicType.STRING) || itemType.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || itemType.equals(BuiltInAtomicType.ANY_URI)) { if (collation==null) { val = value.getStringValue(); } else { val = collation.getCollationKey(value.getStringValue()); } } else { val = value.getXPathComparable(false, collation, context); } return val; }
/** * Get the schema type information for this node. Returns null for an untyped node. */ /*@Nullable*/ public TypeInfo getSchemaTypeInfo() { SchemaType type = node.getSchemaType(); if (type == null || BuiltInAtomicType.UNTYPED_ATOMIC.equals(type)) { return null; } return new TypeInfoImpl(node.getConfiguration(), type); }
/** * Get the schema type information for this node. Returns null for an untyped node. */ /*@Nullable*/ public TypeInfo getSchemaTypeInfo() { SchemaType type = node.getSchemaType(); if (type == null || BuiltInAtomicType.UNTYPED_ATOMIC.equals(type)) { return null; } return new TypeInfoImpl(node.getConfiguration(), type); }
if (t0.equals(BuiltInAtomicType.STRING) || t1.equals(BuiltInAtomicType.STRING) || (t0.equals(BuiltInAtomicType.UNTYPED_ATOMIC) && t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC))) { StringValue s0 = (StringValue)a0.convert(BuiltInAtomicType.STRING, true, context).asAtomic(); StringValue s1 = (StringValue)a1.convert(BuiltInAtomicType.STRING, true, context).asAtomic(); if (t0.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { a0 = a0.convert(t1, true, context).asAtomic(); if (t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { a1 = a1.convert(t0, true, context).asAtomic();
/** * Get the schema type information for this node. * * @return the type information. Returns null for an untyped node. */ /*@Nullable*/ public TypeInfo getSchemaTypeInfo() { SchemaType type = node.getSchemaType(); if (type == null || Untyped.getInstance().equals(type) || BuiltInAtomicType.UNTYPED_ATOMIC.equals(type)) { return null; } return new TypeInfoImpl(node.getConfiguration(), type); }
/** * Get the schema type information for this node. * * @return the type information. Returns null for an untyped node. */ /*@Nullable*/ public TypeInfo getSchemaTypeInfo() { SchemaType type = node.getSchemaType(); if (type == null || Untyped.getInstance().equals(type) || BuiltInAtomicType.UNTYPED_ATOMIC.equals(type)) { return null; } return new TypeInfoImpl(node.getConfiguration(), type); }
if (t0.equals(BuiltInAtomicType.STRING) || t1.equals(BuiltInAtomicType.STRING) || (t0.equals(BuiltInAtomicType.UNTYPED_ATOMIC) && t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC))) { StringValue s0 = StringValue.makeStringValue(a0.getStringValueCS()); StringValue s1 = StringValue.makeStringValue(a1.getStringValueCS()); if (t0.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { a0 = t1.getStringConverter(rules).convert((StringValue)a0).asAtomic(); if (t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { a1 = t0.getStringConverter(rules).convert((StringValue)a1).asAtomic();
/** * Perform the promotion * @param value the numeric or untyped atomic value to be promoted * @param context the XPath dynamic evaluation context * @return the value that results from the promotion */ private AtomicValue promote(AtomicValue value, XPathContext context) throws XPathException { if (!(value instanceof NumericValue || value instanceof UntypedAtomicValue)) { final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); XPathException err = new XPathException( "Cannot promote non-numeric value to " + getItemType(th).toString(), "XPTY0004", context); err.setLocator(this); throw err; } if (requiredType.equals(BuiltInAtomicType.FLOAT) && value instanceof DoubleValue) { XPathException err = new XPathException( "Cannot promote from xs:double to xs:float", "XPTY0004", context); err.setLocator(this); throw err; } return value.convert(requiredType, true, context).asAtomic(); }