/** * Ask whether a given Item is an instance of this UType * @param item the item to be tested * @return true if this UType matches the supplied item */ public boolean matches(Item item) { return subsumes(getUType(item)); }
/** * Ask whether a given Item is an instance of this UType * @param item the item to be tested * @return true if this UType matches the supplied item */ public boolean matches(Item item) { return subsumes(getUType(item)); }
/** * Determine whether two primitive atomic types are comparable under the rules for ValueComparisons * (that is, untyped atomic values treated as strings), using the "eq" operator * * @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} * @return true if the types are comparable, as defined by the rules of the "eq" operator; false if they * are not comparable, or if we don't yet know (because some subtypes of the static type are comparable * and others are not) */ public static boolean isGuaranteedComparable(UType t1, UType t2) { if (t1 == t2) { return true; // short cut } if (t1 == UType.UNTYPED_ATOMIC || t1 == UType.ANY_URI) { t1 = UType.STRING; } if (t2 == UType.UNTYPED_ATOMIC || t2 == UType.ANY_URI) { t2 = UType.STRING; } if (NUMERIC.subsumes(t1)) { t1 = NUMERIC; } if (NUMERIC.subsumes(t2)) { t2 = NUMERIC; } return t1.equals(t2); }
/** * Determine whether two primitive atomic types are comparable under the rules for ValueComparisons * (that is, untyped atomic values treated as strings), using the "eq" operator * * @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} * @return true if the types are comparable, as defined by the rules of the "eq" operator; false if they * are not comparable, or if we don't yet know (because some subtypes of the static type are comparable * and others are not) */ public static boolean isGuaranteedComparable(UType t1, UType t2) { if (t1 == t2) { return true; // short cut } if (t1 == UType.UNTYPED_ATOMIC || t1 == UType.ANY_URI) { t1 = UType.STRING; } if (t2 == UType.UNTYPED_ATOMIC || t2 == UType.ANY_URI) { t2 = UType.STRING; } if (NUMERIC.subsumes(t1)) { t1 = NUMERIC; } if (NUMERIC.subsumes(t2)) { t2 = NUMERIC; } return t1.equals(t2); }
/** * Get the nodes with a given key value * * @param soughtValue The required key value * @return a list of the selected nodes, always in document order with no duplicates, or null * to represent an empty list * @throws XPathException if a dynamic error is encountered */ public List<NodeInfo> get(AtomicValue soughtValue) throws XPathException { if (untypedKeys != null && !keyTypesConvertedFromUntyped.subsumes(soughtValue.getUType())) { reindexUntypedValues(soughtValue.getPrimitiveType()); } return index.get(getCollationKey(soughtValue, collation, implicitTimezone)); }
/** * Get the nodes with a given key value * * @param soughtValue The required key value * @return a list of the selected nodes, always in document order with no duplicates, or null * to represent an empty list * @throws XPathException if a dynamic error is encountered */ public List<NodeInfo> get(AtomicValue soughtValue) throws XPathException { if (untypedKeys != null && !keyTypesConvertedFromUntyped.subsumes(soughtValue.getUType())) { reindexUntypedValues(soughtValue.getPrimitiveType()); } return index.get(getCollationKey(soughtValue, collation, implicitTimezone)); }
/** * Obtain (that is, create or get) an itemType that matches all items whose primitive type is one * of the types present in this UType. * @return a corresponding ItemType */ public ItemType toItemType() { Set<PrimitiveUType> p = decompose(); if (p.isEmpty()) { return ErrorType.getInstance(); } else if (p.size() == 1) { return p.toArray(new PrimitiveUType[1])[0].toItemType(); } else if (ANY_NODE.subsumes(this)) { return AnyNodeTest.getInstance(); } else if (equals(NUMERIC)) { return NumericType.getInstance(); } else if (ANY_ATOMIC.subsumes(this)) { return BuiltInAtomicType.ANY_ATOMIC; } else { return AnyItemType.getInstance(); } }
/** * Obtain (that is, create or get) an itemType that matches all items whose primitive type is one * of the types present in this UType. * @return a corresponding ItemType */ public ItemType toItemType() { Set<PrimitiveUType> p = decompose(); if (p.isEmpty()) { return ErrorType.getInstance(); } else if (p.size() == 1) { return p.toArray(new PrimitiveUType[1])[0].toItemType(); } else if (ANY_NODE.subsumes(this)) { return AnyNodeTest.getInstance(); } else if (equals(NUMERIC)) { return NumericType.getInstance(); } else if (ANY_ATOMIC.subsumes(this)) { return BuiltInAtomicType.ANY_ATOMIC; } else { return AnyItemType.getInstance(); } }
/** * Re-index untyped atomic values after conversion to a specific type. This * happens when the "convertUntypedToOther" option is set (typically because this * index is used to support a general comparison), and the sought value is of a type * other that string or untyped atomic. We go through the index finding all untyped * atomic values, converting each one to the sought type, and adding it to the index under * this type. * @param type the type to which untyped atomic values should be converted * @throws XPathException if conversion of any untyped atomic value to the requested key type fails */ public void reindexUntypedValues(BuiltInAtomicType type) throws XPathException { UType uType = type.getUType(); if (UType.STRING_LIKE.subsumes(uType)) { return; } if (UType.NUMERIC.subsumes(uType)) { type = BuiltInAtomicType.DOUBLE; uType = UType.DOUBLE; } StringConverter converter = type.getStringConverter(rules); for (UntypedAtomicValue v : untypedKeys) { AtomicMatchKey uk = getCollationKey(v, collation, implicitTimezone); List<NodeInfo> nodes = index.get(uk); AtomicValue convertedValue = converter.convertString(v.getStringValueCS()).asAtomic(); AtomicMatchKey amk = getCollationKey(convertedValue, collation, implicitTimezone); for (NodeInfo node : nodes) { addEntry(amk, node, false); } } }
/** * Re-index untyped atomic values after conversion to a specific type. This * happens when the "convertUntypedToOther" option is set (typically because this * index is used to support a general comparison), and the sought value is of a type * other that string or untyped atomic. We go through the index finding all untyped * atomic values, converting each one to the sought type, and adding it to the index under * this type. * @param type the type to which untyped atomic values should be converted * @throws XPathException if conversion of any untyped atomic value to the requested key type fails */ public void reindexUntypedValues(BuiltInAtomicType type) throws XPathException { UType uType = type.getUType(); if (UType.STRING_LIKE.subsumes(uType)) { return; } if (UType.NUMERIC.subsumes(uType)) { type = BuiltInAtomicType.DOUBLE; uType = UType.DOUBLE; } StringConverter converter = type.getStringConverter(rules); for (UntypedAtomicValue v : untypedKeys) { AtomicMatchKey uk = getCollationKey(v, collation, implicitTimezone); List<NodeInfo> nodes = index.get(uk); AtomicValue convertedValue = converter.convertString(v.getStringValueCS()).asAtomic(); AtomicMatchKey amk = getCollationKey(convertedValue, collation, implicitTimezone); for (NodeInfo node : nodes) { addEntry(amk, node, false); } } }
private static AtomicMatchKey getCollationKey(AtomicValue value, StringCollator collation, int implicitTimezone) throws XPathException { if (UType.STRING_LIKE.subsumes(value.getUType())) { if (collation == null) { return new CodepointMatchKey(value.getStringValue()); } else { return collation.getCollationKey(value.getStringValue()); } } else { return value.getXPathComparable(false, collation, implicitTimezone); } }
private static AtomicMatchKey getCollationKey(AtomicValue value, StringCollator collation, int implicitTimezone) throws XPathException { if (UType.STRING_LIKE.subsumes(value.getUType())) { if (collation == null) { return new CodepointMatchKey(value.getStringValue()); } else { return collation.getCollationKey(value.getStringValue()); } } else { return value.getXPathComparable(false, collation, implicitTimezone); } }
/** * Evaluate as an Item. */ public Item evaluateItem(XPathContext context) throws XPathException { final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); Item item = getBaseExpression().evaluateItem(context); if (item == null) { return null; } if (requiredItemType.matches(item, th)) { return item; } else if (requiredItemType.getUType().subsumes(UType.STRING) && BuiltInAtomicType.ANY_URI.matches(item, th)) { return item; } else { String message = role.composeErrorMessage(requiredItemType, item, th); String errorCode = role.getErrorCode(); if ("XPDY0050".equals(errorCode)) { // error in "treat as" assertion dynamicError(message, errorCode, context); } else { typeError(message, errorCode, context); } return null; } }
/** * Evaluate as an Item. */ public Item evaluateItem(XPathContext context) throws XPathException { final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); Item item = getBaseExpression().evaluateItem(context); if (item == null) { return null; } if (requiredItemType.matches(item, th)) { return item; } else if (requiredItemType.getUType().subsumes(UType.STRING) && BuiltInAtomicType.ANY_URI.matches(item, th)) { return item; } else { String message = role.composeErrorMessage(requiredItemType, item, th); String errorCode = role.getErrorCode(); if ("XPDY0050".equals(errorCode)) { // error in "treat as" assertion dynamicError(message, errorCode, context); } else { typeError(message, errorCode, context); } return null; } }
private void testConformance(T item, Configuration config) throws XPathException { final TypeHierarchy th = config.getTypeHierarchy(); if (requiredItemType.matches(item, th)) { // OK, no action } else if (requiredItemType.getUType().subsumes(UType.STRING) && BuiltInAtomicType.ANY_URI.matches(item, th)) { // OK, no action } else { String message = role.composeErrorMessage(requiredItemType, item, th); String errorCode = role.getErrorCode(); if ("XPDY0050".equals(errorCode)) { // error in "treat as" assertion XPathException te = new XPathException(message, errorCode); te.setFailingExpression(failingExpression); te.setLocator(location); te.setIsTypeError(false); throw te; } else { XPathException te = new XPathException(message, errorCode); te.setFailingExpression(failingExpression); te.setLocator(location); te.setIsTypeError(true); throw te; } } }
private void testConformance(T item, Configuration config) throws XPathException { final TypeHierarchy th = config.getTypeHierarchy(); if (requiredItemType.matches(item, th)) { // OK, no action } else if (requiredItemType.getUType().subsumes(UType.STRING) && BuiltInAtomicType.ANY_URI.matches(item, th)) { // OK, no action } else { String message = role.composeErrorMessage(requiredItemType, item, th); String errorCode = role.getErrorCode(); if ("XPDY0050".equals(errorCode)) { // error in "treat as" assertion XPathException te = new XPathException(message, errorCode); te.setFailingExpression(failingExpression); te.setLocator(location); te.setIsTypeError(false); throw te; } else { XPathException te = new XPathException(message, errorCode); te.setFailingExpression(failingExpression); te.setLocator(location); te.setIsTypeError(true); throw te; } } }
public void addRule(Pattern pattern, Rule newRule) { UType uType = pattern.getUType(); if (uType.equals(UType.ELEMENT)) { int fp = pattern.getFingerprint(); addRuleToNamedOrUnnamedChain( newRule, fp, unnamedElementRuleChain, namedElementRuleChains); } else if (uType.equals(UType.ATTRIBUTE)) { int fp = pattern.getFingerprint(); addRuleToNamedOrUnnamedChain( newRule, fp, unnamedAttributeRuleChain, namedAttributeRuleChains); } else if (uType.equals(UType.DOCUMENT)) { addRuleToList(newRule, documentRuleChain); } else if (uType.equals(UType.TEXT)) { addRuleToList(newRule, textRuleChain); } else if (uType.equals(UType.COMMENT)) { addRuleToList(newRule, commentRuleChain); } else if (uType.equals(UType.PI)) { addRuleToList(newRule, processingInstructionRuleChain); } else if (uType.equals(UType.NAMESPACE)) { addRuleToList(newRule, namespaceRuleChain); } else if (UType.ANY_ATOMIC.subsumes(uType)) { addRuleToList(newRule, atomicValueRuleChain); } else if (UType.FUNCTION.subsumes(uType)) { addRuleToList(newRule, functionItemRuleChain); } else { addRuleToList(newRule, genericRuleChain); } }
public void addRule(Pattern pattern, Rule newRule) { UType uType = pattern.getUType(); if (uType.equals(UType.ELEMENT)) { int fp = pattern.getFingerprint(); addRuleToNamedOrUnnamedChain( newRule, fp, unnamedElementRuleChain, namedElementRuleChains); } else if (uType.equals(UType.ATTRIBUTE)) { int fp = pattern.getFingerprint(); addRuleToNamedOrUnnamedChain( newRule, fp, unnamedAttributeRuleChain, namedAttributeRuleChains); } else if (uType.equals(UType.DOCUMENT)) { addRuleToList(newRule, documentRuleChain); } else if (uType.equals(UType.TEXT)) { addRuleToList(newRule, textRuleChain); } else if (uType.equals(UType.COMMENT)) { addRuleToList(newRule, commentRuleChain); } else if (uType.equals(UType.PI)) { addRuleToList(newRule, processingInstructionRuleChain); } else if (uType.equals(UType.NAMESPACE)) { addRuleToList(newRule, namespaceRuleChain); } else if (UType.ANY_ATOMIC.subsumes(uType)) { addRuleToList(newRule, atomicValueRuleChain); } else if (UType.FUNCTION.subsumes(uType)) { addRuleToList(newRule, functionItemRuleChain); } else { addRuleToList(newRule, genericRuleChain); } }
b = Literal.makeEmptySequence(); boolean textonly = UType.TEXT.subsumes(b.getItemType().getUType());