/** * End of event stream */ public void close() throws XPathException { if (count == 0 && !Cardinality.allowsZero(cardinality)) { XPathException err = new XPathException("An empty sequence is not allowed as the " + role.getMessage()); String errorCode = role.getErrorCode(); err.setErrorCode(errorCode); if (!"XPDY0050".equals(errorCode)) { err.setIsTypeError(true); } throw err; } // don't pass on the close event }
/** * End of event stream */ public void close() throws XPathException { if (count == 0 && !Cardinality.allowsZero(cardinality)) { XPathException err = new XPathException("An empty sequence is not allowed as the " + role.getMessage()); String errorCode = role.getErrorCode(); err.setErrorCode(errorCode); if (!"XPDY0050".equals(errorCode)) { err.setIsTypeError(true); } throw err; } // don't pass on the close event }
/** * Evaluate as an Item. */ public Item evaluateItem(XPathContext context) throws XPathException { SequenceIterator iter = operand.iterate(context); Item item = null; while (true) { Item nextItem = iter.next(); if (nextItem == null) break; if (requiredCardinality == StaticProperty.EMPTY) { typeError("An empty sequence is required as the " + role.getMessage(), role.getErrorCode(), context); return null; } if (item != null) { typeError("A sequence of more than one item is not allowed as the " + role.getMessage() + depictSequenceStart(iter.getAnother(), 2), role.getErrorCode(), context); return null; } item = nextItem; } if (item == null && !Cardinality.allowsZero(requiredCardinality)) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), context); return null; } return item; }
/** * Evaluate as an Item. */ public Item evaluateItem(XPathContext context) throws XPathException { SequenceIterator iter = operand.iterate(context); Item item = null; while (true) { Item nextItem = iter.next(); if (nextItem == null) break; if (requiredCardinality == StaticProperty.EMPTY) { typeError("An empty sequence is required as the " + role.getMessage(), role.getErrorCode(), context); return null; } if (item != null) { typeError("A sequence of more than one item is not allowed as the " + role.getMessage() + depictSequenceStart(iter.getAnother(), 2), role.getErrorCode(), context); return null; } item = nextItem; } if (item == null && !Cardinality.allowsZero(requiredCardinality)) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), context); return null; } return item; }
/** * Evaluate as an Item. */ public Item evaluateItem(XPathContext context) throws XPathException { SequenceIterator iter = operand.iterate(context); Item item = null; while (true) { Item nextItem = iter.next(); if (nextItem == null) break; if (requiredCardinality == StaticProperty.EMPTY) { typeError("An empty sequence is required as the " + role.getMessage(), role.getErrorCode(), context); return null; } if (item != null) { typeError("A sequence of more than one item is not allowed as the " + role.getMessage() + depictSequenceStart(iter.getAnother(), 2), role.getErrorCode(), context); return null; } item = nextItem; } if (item == null && !Cardinality.allowsZero(requiredCardinality)) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), context); return null; } return item; }
/** * Iterate over the sequence of values */ public SequenceIterator iterate(XPathContext context) throws XPathException { SequenceIterator base = operand.iterate(context); // If the base iterator knows how many items there are, then check it now rather than wasting time if ((base.getProperties() & SequenceIterator.LAST_POSITION_FINDER) != 0) { int count = ((LastPositionFinder)base).getLastPosition(); if (count == 0 && !Cardinality.allowsZero(requiredCardinality)) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), context); } else if (count == 1 && requiredCardinality == StaticProperty.EMPTY) { typeError("The only value allowed for the " + role.getMessage() + " is an empty sequence", role.getErrorCode(), context); } else if (count > 1 && !Cardinality.allowsMany(requiredCardinality)) { typeError("A sequence of more than one item is not allowed as the " + role.getMessage() + depictSequenceStart(base.getAnother(), 2), role.getErrorCode(), context); } return base; } // Otherwise return an iterator that does the checking on the fly return new CardinalityCheckingIterator(base, requiredCardinality, role, this); }
/** * Iterate over the sequence of values */ public SequenceIterator iterate(XPathContext context) throws XPathException { SequenceIterator base = operand.iterate(context); // If the base iterator knows how many items there are, then check it now rather than wasting time if ((base.getProperties() & SequenceIterator.LAST_POSITION_FINDER) != 0) { int count = ((LastPositionFinder)base).getLastPosition(); if (count == 0 && !Cardinality.allowsZero(requiredCardinality)) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), context); } else if (count == 1 && requiredCardinality == StaticProperty.EMPTY) { typeError("The only value allowed for the " + role.getMessage() + " is an empty sequence", role.getErrorCode(), context); } else if (count > 1 && !Cardinality.allowsMany(requiredCardinality)) { typeError("A sequence of more than one item is not allowed as the " + role.getMessage() + depictSequenceStart(base.getAnother(), 2), role.getErrorCode(), context); } return base; } // Otherwise return an iterator that does the checking on the fly return new CardinalityCheckingIterator(base, requiredCardinality, role); }
if (!Cardinality.allowsZero(requiredCardinality)) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode()); role.getMessage() + " is an empty sequence", role.getErrorCode()); typeError( "A sequence of more than one item is not allowed as the " + role.getMessage() + CardinalityChecker.depictSequenceStart(base.getAnother(), 2), role.getErrorCode());
if (!Cardinality.allowsZero(requiredCardinality)) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode()); role.getMessage() + " is an empty sequence", role.getErrorCode()); typeError( "A sequence of more than one item is not allowed as the " + role.getMessage() + CardinalityChecker.depictSequenceStart(base.getAnother(), 2), role.getErrorCode());
/** * Iterate over the sequence of values */ public SequenceIterator iterate(XPathContext context) throws XPathException { SequenceIterator base = operand.iterate(context); // If the base iterator knows how many items there are, then check it now rather than wasting time if ((base.getProperties() & SequenceIterator.LAST_POSITION_FINDER) != 0) { int count = ((LastPositionFinder)base).getLastPosition(); if (count == 0 && !Cardinality.allowsZero(requiredCardinality)) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), context); } else if (count == 1 && requiredCardinality == StaticProperty.EMPTY) { typeError("The only value allowed for the " + role.getMessage() + " is an empty sequence", role.getErrorCode(), context); } else if (count > 1 && !Cardinality.allowsMany(requiredCardinality)) { typeError("A sequence of more than one item is not allowed as the " + role.getMessage() + depictSequenceStart(base.getAnother(), 2), role.getErrorCode(), context); } return base; } // Otherwise return an iterator that does the checking on the fly return new CardinalityCheckingIterator(base, requiredCardinality, role); }
private void checkAllowsMany(long locationId) throws XPathException { if (!Cardinality.allowsMany(cardinality)) { XPathException err = new XPathException("A sequence of more than one item is not allowed as the " + role.getMessage()); String errorCode = role.getErrorCode(); err.setErrorCode(errorCode); if (!"XPDY0050".equals(errorCode)) { err.setIsTypeError(true); } err.setLocator(ExpressionLocation.getSourceLocator(locationId, getPipelineConfiguration().getLocationProvider())); throw err; } }
private void checkAllowsMany(long locationId) throws XPathException { if (!Cardinality.allowsMany(cardinality)) { XPathException err = new XPathException("A sequence of more than one item is not allowed as the " + role.getMessage()); String errorCode = role.getErrorCode(); err.setErrorCode(errorCode); if (!"XPDY0050".equals(errorCode)) { err.setIsTypeError(true); } err.setLocator(ExpressionLocation.getSourceLocator(locationId, getPipelineConfiguration().getLocationProvider())); throw err; } }
private void checkItemType(ItemType type, long locationId) throws XPathException { if (!getConfiguration().getTypeHierarchy().isSubType(type, itemType)) { String message = role.composeErrorMessage(itemType, type, getNamePool()); String errorCode = role.getErrorCode(); XPathException err = new XPathException(message); err.setErrorCode(errorCode); if (!"XPDY0050".equals(errorCode)) { err.setIsTypeError(true); } err.setLocator(ExpressionLocation.getSourceLocator(locationId, getPipelineConfiguration().getLocationProvider())); throw err; } }
private void checkItemType(ItemType type, long locationId) throws XPathException { if (!getConfiguration().getTypeHierarchy().isSubType(type, itemType)) { String message = role.composeErrorMessage(itemType, type, getNamePool()); String errorCode = role.getErrorCode(); XPathException err = new XPathException(message); err.setErrorCode(errorCode); if (!"XPDY0050".equals(errorCode)) { err.setIsTypeError(true); } err.setLocator(ExpressionLocation.getSourceLocator(locationId, getPipelineConfiguration().getLocationProvider())); throw err; } }
private void testConformance(Item item, XPathContext context) throws XPathException { if (!requiredItemType.matchesItem(item, true, (context == null ? null : context.getConfiguration()))) { String message; if (context == null) { // no name pool available message = "Supplied value of type " + Type.displayTypeName(item) + " does not match the required type of " + role.getMessage(); } else { final NamePool pool = context.getNamePool(); final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); message = role.composeErrorMessage(requiredItemType, Value.asValue(item).getItemType(th), pool); } String errorCode = role.getErrorCode(); if ("XPDY0050".equals(errorCode)) { // error in "treat as" assertion dynamicError(message, errorCode, context); } else { typeError(message, errorCode, context); } } }
private void testConformance(Item item, XPathContext context) throws XPathException { if (!requiredItemType.matchesItem(item, true, (context == null ? null : context.getConfiguration()))) { String message; if (context == null) { // no name pool available message = "Supplied value of type " + Type.displayTypeName(item) + " does not match the required type of " + role.getMessage(); } else { final NamePool pool = context.getNamePool(); final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); message = role.composeErrorMessage(requiredItemType, Value.asValue(item).getItemType(th), pool); } String errorCode = role.getErrorCode(); if ("XPDY0050".equals(errorCode)) { // error in "treat as" assertion dynamicError(message, errorCode, context); } else { typeError(message, errorCode, context); } } }
private void testConformance(Item item, XPathContext context) throws XPathException { if (!requiredItemType.matchesItem(item, true, (context == null ? null : context.getConfiguration()))) { String message; if (context == null) { // no name pool available message = "Supplied value of type " + Type.displayTypeName(item) + " does not match the required type of " + role.getMessage(); } else { final NamePool pool = context.getNamePool(); final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); message = role.composeErrorMessage(requiredItemType, Value.asValue(item).getItemType(th), pool); } String errorCode = role.getErrorCode(); if ("XPDY0050".equals(errorCode)) { // error in "treat as" assertion dynamicError(message, errorCode, context); } else { typeError(message, errorCode, context); } } }
/** * Type-check the expression */ public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { operand = visitor.typeCheck(operand, contextItemType); visitor.resetStaticProperties(); if (Literal.isEmptySequence(operand)) { if (!allowEmpty) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), null); } return operand; } final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (operand.getItemType(th).isAtomicType()) { return operand; } return this; }
/** * Type-check the expression */ public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { operand = visitor.typeCheck(operand, contextItemType); visitor.resetStaticProperties(); if (Literal.isEmptySequence(operand)) { if (!allowEmpty) { typeError("An empty sequence is not allowed as the " + role.getMessage(), role.getErrorCode(), null); } return operand; } final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (operand.getItemType(th).isAtomicType()) { return operand; } return this; }
"Conditional expession: If " + cond + " satisfied, an empty sequence will be returned, " + "but this is not allowed as the " + role.getMessage()); err.setErrorCode(role.getErrorCode()); err.setIsTypeError(true); throw err;