public boolean matchesItem(Item item) { for (ItemType itemType : getChildren()) if (itemType.matches(item)) return true; return false; }
private void checkItem(Item item, Location locationId) throws XPathException { TypeHierarchy th = getConfiguration().getTypeHierarchy(); if (!itemType.matches(item, th)) { throwTypeError(null, item, locationId); } }
private void checkItem(Item item, Location locationId) throws XPathException { TypeHierarchy th = getConfiguration().getTypeHierarchy(); if (!itemType.matches(item, th)) { throwTypeError(null, item, locationId); } }
while ((item = iter.next()) != null) { count++; if (!primaryType.matches(item, th)) { String s = "The " + RoleDiagnostic.ordinal(count) + " item is not an instance of the required type"; Optional<String> more = primaryType.explainMismatch(item, th);
while ((item = iter.next()) != null) { count++; if (!primaryType.matches(item, th)) { String s = "The " + RoleDiagnostic.ordinal(count) + " item is not an instance of the required type"; Optional<String> more = primaryType.explainMismatch(item, th);
private void checkContextItemType(Item contextItem) throws XPathException { if (contextItem != null) { ItemType type = env.getRequiredContextItemType(); TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!type.matches(contextItem, th)) { throw new XPathException("Supplied context item does not match required context item type " + type); } } }
private void checkContextItemType(Item contextItem) throws XPathException { if (contextItem != null) { ItemType type = env.getRequiredContextItemType(); TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!type.matches(contextItem, th)) { throw new XPathException("Supplied context item does not match required context item type " + type); } } }
/** * Determine whether this item type matches a given item. * * @param item the item to be tested against this item type * @return true if the item matches this item type, false if it does not match. * @throws net.sf.saxon.s9api.SaxonApiUncheckedException in the rare event that the item is a map or * array containing a lazily evaluated sequence, and evaluation of the sequence fails with a dynamic * error in the course of checking */ public boolean matches(XdmItem item) throws SaxonApiUncheckedException { try { TypeHierarchy th = processor.getUnderlyingConfiguration().getTypeHierarchy(); return underlyingType.matches((Item) item.getUnderlyingValue(), th); } catch (XPathException e) { throw new SaxonApiUncheckedException(e); } }
/** * Determine whether this item type matches a given item. * * @param item the item to be tested against this item type * @return true if the item matches this item type, false if it does not match. * @throws net.sf.saxon.s9api.SaxonApiUncheckedException in the rare event that the item is a map or * array containing a lazily evaluated sequence, and evaluation of the sequence fails with a dynamic * error in the course of checking */ public boolean matches(XdmItem item) throws SaxonApiUncheckedException { try { TypeHierarchy th = processor.getUnderlyingConfiguration().getTypeHierarchy(); return underlyingType.matches((Item) item.getUnderlyingValue(), th); } catch (XPathException e) { throw new SaxonApiUncheckedException(e); } }
/** * Determine whether a given value is a valid instance of this SequenceType * * @param value the value to be tested * @param th the type hierarchy cache * @return true if the value is a valid instance of this type * @throws XPathException if a dynamic error occurs while evaluating the Sequence (this * won't happen if the sequence is grounded) */ public boolean matches(Sequence<?> value, TypeHierarchy th) throws XPathException { int count = 0; SequenceIterator<?> iter = value.iterate(); Item item; while ((item = iter.next()) != null) { count++; if (!primaryType.matches(item, th)) { return false; } } return !(count == 0 && !Cardinality.allowsZero(cardinality) || count > 1 && !Cardinality.allowsMany(cardinality)); }
/** * Determine whether a given value is a valid instance of this SequenceType * * @param value the value to be tested * @param th the type hierarchy cache * @return true if the value is a valid instance of this type * @throws XPathException if a dynamic error occurs while evaluating the Sequence (this * won't happen if the sequence is grounded) */ public boolean matches(Sequence<?> value, TypeHierarchy th) throws XPathException { int count = 0; SequenceIterator<?> iter = value.iterate(); Item item; while ((item = iter.next()) != null) { count++; if (!primaryType.matches(item, th)) { return false; } } return !(count == 0 && !Cardinality.allowsZero(cardinality) || count > 1 && !Cardinality.allowsMany(cardinality)); }
/** * Here is the method that does the work * @param iter iterator over the operand sequence * @param context dynamic evaluation context * @return true if the operand is an instance of the required type * @throws XPathException if a failure occurs evaluating the operand */ private boolean isInstance(SequenceIterator iter, XPathContext context) throws XPathException { int count = 0; Item item; while ((item = iter.next()) != null) { count++; if (!targetType.matches(item, context.getConfiguration().getTypeHierarchy())) { iter.close(); return false; } if (count == 2 && !Cardinality.allowsMany(targetCardinality)) { iter.close(); return false; } } return !(count == 0 && ((targetCardinality & StaticProperty.ALLOWS_ZERO) == 0)); }
/** * Here is the method that does the work * @param iter iterator over the operand sequence * @param context dynamic evaluation context * @return true if the operand is an instance of the required type * @throws XPathException if a failure occurs evaluating the operand */ private boolean isInstance(SequenceIterator iter, XPathContext context) throws XPathException { int count = 0; Item item; while ((item = iter.next()) != null) { count++; if (!targetType.matches(item, context.getConfiguration().getTypeHierarchy())) { iter.close(); return false; } if (count == 2 && !Cardinality.allowsMany(targetCardinality)) { iter.close(); return false; } } return !(count == 0 && ((targetCardinality & StaticProperty.ALLOWS_ZERO) == 0)); }
/** * 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; } }
/** * Set the context item for evaluation of the XPath Expression * * @param item the context item * @throws XPathException if the node is in a document that was built under the wrong configuration */ public void setContextItem(Item<?> item) throws XPathException { if (item instanceof NodeInfo) { if (!((NodeInfo) item).getConfiguration().isCompatible(contextObject.getConfiguration())) { throw new XPathException( "Supplied node must be built using the same or a compatible Configuration", SaxonErrorCode.SXXP0004); } } TypeHierarchy th = contextObject.getConfiguration().getTypeHierarchy(); if (!contextItemType.matches(item, th)) { throw new XPathException("Supplied context item does not match required context item type " + contextItemType); } ManualIterator<Item<?>> iter = new ManualIterator<>(item); contextObject.setCurrentIterator(iter); }
/** * Set the context item for evaluation of the XPath Expression * * @param item the context item * @throws XPathException if the node is in a document that was built under the wrong configuration */ public void setContextItem(Item<?> item) throws XPathException { if (item instanceof NodeInfo) { if (!((NodeInfo) item).getConfiguration().isCompatible(contextObject.getConfiguration())) { throw new XPathException( "Supplied node must be built using the same or a compatible Configuration", SaxonErrorCode.SXXP0004); } } TypeHierarchy th = contextObject.getConfiguration().getTypeHierarchy(); if (!contextItemType.matches(item, th)) { throw new XPathException("Supplied context item does not match required context item type " + contextItemType); } ManualIterator<Item<?>> iter = new ManualIterator<>(item); contextObject.setCurrentIterator(iter); }
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; } } }
TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); if (requiredContextItemType != AnyItemType.getInstance() && !requiredContextItemType.matches(contextItem, th)) { RoleDiagnostic role = new RoleDiagnostic( RoleDiagnostic.MISC, "context item for the named template", 0);