/** * Determine the data type of the items returned by the expression * @param th the type hierarchy cache */ public ItemType getItemType(TypeHierarchy th) { ItemType operandType = operand.getItemType(th); int relationship = th.relationship(requiredItemType, operandType); switch (relationship) { case TypeHierarchy.OVERLAPS: if (requiredItemType instanceof NodeTest && operandType instanceof NodeTest) { return new CombinedNodeTest((NodeTest)requiredItemType, Token.INTERSECT, (NodeTest)operandType); } else { // we don't know how to intersect atomic types, it doesn't actually happen return requiredItemType; } case TypeHierarchy.SUBSUMES: case TypeHierarchy.SAME_TYPE: // shouldn't happen, but it doesn't matter return operandType; case TypeHierarchy.SUBSUMED_BY: default: return requiredItemType; } }
/** * Make a union node test for a set of supplied element fingerprints * * @param elements the set of integer element fingerprints to be tested for. Must not * be empty. * @param pool the name pool * @return a NodeTest that returns true if the node is an element whose name is one of the names * in this set */ private NodeTest makeUnionNodeTest(IntHashSet elements, NamePool pool) { NodeTest test = null; IntIterator iter = elements.iterator(); while (iter.hasNext()) { int fp = iter.next(); NodeTest nextTest = new NameTest(Type.ELEMENT, fp, pool); if (test == null) { test = nextTest; } else { test = new CombinedNodeTest(test, Token.UNION, nextTest); } } return test; }
/** * Make a union node test for a set of supplied element fingerprints * * @param elements the set of integer element fingerprints to be tested for. Must not * be empty. * @param pool the name pool * @return a NodeTest that returns true if the node is an element whose name is one of the names * in this set */ private NodeTest makeUnionNodeTest(IntHashSet elements, NamePool pool) { NodeTest test = null; IntIterator iter = elements.iterator(); while (iter.hasNext()) { int fp = iter.next(); NodeTest nextTest = new NameTest(Type.ELEMENT, fp, pool); if (test == null) { test = nextTest; } else { test = new CombinedNodeTest(test, Token.UNION, nextTest); } } return test; }
/** * Determine the data type of the items returned by the expression */ /*@NotNull*/ public ItemType getItemType() { ItemType operandType = getBaseExpression().getItemType(); TypeHierarchy th = getConfiguration().getTypeHierarchy(); int relationship = th.relationship(requiredItemType, operandType); switch (relationship) { case TypeHierarchy.OVERLAPS: if (requiredItemType instanceof NodeTest && operandType instanceof NodeTest) { return new CombinedNodeTest((NodeTest) requiredItemType, Token.INTERSECT, (NodeTest) operandType); } else { // we don't know how to intersect atomic types, it doesn't actually happen return requiredItemType; } case TypeHierarchy.SUBSUMES: case TypeHierarchy.SAME_TYPE: // shouldn't happen, but it doesn't matter return operandType; case TypeHierarchy.SUBSUMED_BY: default: return requiredItemType; } }
/** * Make a union node test for a set of supplied element fingerprints * @param elements the set of integer element fingerprints to be tested for * @param pool the name pool * @return a NodeTest that returns true if the node is an element whose name is one of the names * in this set */ private NodeTest makeUnionNodeTest(IntHashSet elements, NamePool pool) { NodeTest test = null; for (IntIterator iter = elements.iterator(); iter.hasNext();) { int fp = iter.next(); NodeTest nextTest = new NameTest(Type.ELEMENT, fp, pool); if (test == null) { test = nextTest; } else { test = new CombinedNodeTest(test, Token.UNION, nextTest); } } if (test == null) { return EmptySequenceTest.getInstance(); } else { return test; } }
/** * Make a union node test for a set of supplied element fingerprints * @param elements the set of integer element fingerprints to be tested for * @param pool the name pool * @return a NodeTest that returns true if the node is an element whose name is one of the names * in this set */ private NodeTest makeUnionNodeTest(IntHashSet elements, NamePool pool) { NodeTest test = null; for (IntIterator iter = elements.iterator(); iter.hasNext();) { int fp = iter.next(); NodeTest nextTest = new NameTest(Type.ELEMENT, fp, pool); if (test == null) { test = nextTest; } else { test = new CombinedNodeTest(test, Token.UNION, nextTest); } } if (test == null) { return EmptySequenceTest.getInstance(); } else { return test; } }
/** * Make a union node test for a set of supplied element fingerprints * @param elements the set of integer element fingerprints to be tested for * @param pool the name pool * @return a NodeTest that returns true if the node is an element whose name is one of the names * in this set */ private NodeTest makeUnionNodeTest(IntHashSet elements, NamePool pool) { NodeTest test = null; for (IntIterator iter = elements.iterator(); iter.hasNext();) { int fp = iter.next(); NodeTest nextTest = new NameTest(Type.ELEMENT, fp, pool); if (test == null) { test = nextTest; } else { test = new CombinedNodeTest(test, Token.UNION, nextTest); } } if (test == null) { return EmptySequenceTest.getInstance(); } else { return test; } }
/** * Determine the data type of the items returned by the expression */ /*@NotNull*/ public ItemType getItemType() { ItemType operandType = getBaseExpression().getItemType(); TypeHierarchy th = getConfiguration().getTypeHierarchy(); int relationship = th.relationship(requiredItemType, operandType); switch (relationship) { case TypeHierarchy.OVERLAPS: if (requiredItemType instanceof NodeTest && operandType instanceof NodeTest) { return new CombinedNodeTest((NodeTest) requiredItemType, Token.INTERSECT, (NodeTest) operandType); } else { // we don't know how to intersect atomic types, it doesn't actually happen return requiredItemType; } case TypeHierarchy.SUBSUMES: case TypeHierarchy.SAME_TYPE: // shouldn't happen, but it doesn't matter return operandType; case TypeHierarchy.SUBSUMED_BY: default: return requiredItemType; } }
if (++count == 1) { ItemType type = new CombinedNodeTest( new NameTest(Type.ELEMENT, nameCode, getNamePool()), Token.INTERSECT, ItemType type = new CombinedNodeTest( new NameTest(Type.ELEMENT, nameCode, getNamePool()), Token.INTERSECT,
if (++count == 1) { ItemType type = new CombinedNodeTest( new NameTest(Type.ELEMENT, nameCode, getNamePool()), Token.INTERSECT, ItemType type = new CombinedNodeTest( new NameTest(Type.ELEMENT, nameCode, getNamePool()), Token.INTERSECT,
/** * Parse a parenthesized item type (allowed in XQuery 3.0 and XPath 3.0 only) * * @return the item type * @throws XPathException in the event of a syntax error (or if 3.0 is not enabled) */ /*@NotNull*/ private ItemType parseParenthesizedItemType() throws XPathException { if (!allowXPath30Syntax) { grumble("Parenthesized item types require 3.0 to be enabled"); } nextToken(); ItemType primaryType = parseItemType(); while (primaryType instanceof NodeTest && language == EXTENDED_ITEM_TYPE && t.currentToken != Token.RPAR) { switch (t.currentToken) { case Token.UNION: case Token.EXCEPT: case Token.INTERSECT: int op = t.currentToken; nextToken(); primaryType = new CombinedNodeTest((NodeTest) primaryType, op, (NodeTest) parseItemType()); } } expect(Token.RPAR); nextToken(); return primaryType; }
/** * Parse a parenthesized item type (allowed in XQuery 3.0 and XPath 3.0 only) * * @return the item type * @throws XPathException in the event of a syntax error (or if 3.0 is not enabled) */ /*@NotNull*/ private ItemType parseParenthesizedItemType() throws XPathException { if (!allowXPath30Syntax) { grumble("Parenthesized item types require 3.0 to be enabled"); } nextToken(); ItemType primaryType = parseItemType(); while (primaryType instanceof NodeTest && language == EXTENDED_ITEM_TYPE && t.currentToken != Token.RPAR) { switch (t.currentToken) { case Token.UNION: case Token.EXCEPT: case Token.INTERSECT: int op = t.currentToken; nextToken(); primaryType = new CombinedNodeTest((NodeTest) primaryType, op, (NodeTest) parseItemType()); } } expect(Token.RPAR); nextToken(); return primaryType; }
if (++count == 1) { ItemType type = new CombinedNodeTest( new NameTest(Type.ELEMENT, nodeName, getNamePool()), Token.INTERSECT, ItemType type = new CombinedNodeTest( new NameTest(Type.ELEMENT, nodeName, getNamePool()), Token.INTERSECT,
if (++count == 1) { ItemType type = new CombinedNodeTest( new NameTest(Type.ELEMENT, nodeName, getNamePool()), Token.INTERSECT, ItemType type = new CombinedNodeTest( new NameTest(Type.ELEMENT, nodeName, getNamePool()), Token.INTERSECT,
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute * @param typeCode The type of the attribute * @param locationId the location of the node in the source, or of the instruction that created it * @param properties Bit significant value. The following bits are defined: * <dl> * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * </dl> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(NodeName nameCode, SimpleType typeCode, CharSequence value, Location locationId, int properties) throws XPathException { if (level == 0) { if (++count == 2) { checkAllowsMany(locationId); } ItemType type = new CombinedNodeTest( new NameTest(Type.ATTRIBUTE, nameCode, getNamePool()), Token.INTERSECT, new ContentTypeTest(Type.ATTRIBUTE, typeCode, getConfiguration(), false)); checkItemType(type, nodeSupplier(Type.ATTRIBUTE, nameCode, value), locationId); } nextReceiver.attribute(nameCode, typeCode, value, locationId, properties); }
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute, as held in the name pool * @param typeCode The type of the attribute, as held in the name pool * @param properties Bit significant value. The following bits are defined: * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) throws XPathException { if (level == 0) { if (++count == 2) { checkAllowsMany(locationId); } ItemType type = new CombinedNodeTest( new NameTest(Type.ATTRIBUTE, nameCode, getNamePool()), Token.INTERSECT, new ContentTypeTest(Type.ATTRIBUTE, getConfiguration().getSchemaType(typeCode), getConfiguration())); checkItemType(type, locationId); } nextReceiver.attribute(nameCode, typeCode, value, locationId, properties); }
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute * @param typeCode The type of the attribute * @param locationId the location of the node in the source, or of the instruction that created it * @param properties Bit significant value. The following bits are defined: * <dl> * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * </dl> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(NodeName nameCode, SimpleType typeCode, CharSequence value, Location locationId, int properties) throws XPathException { if (level == 0) { if (++count == 2) { checkAllowsMany(locationId); } ItemType type = new CombinedNodeTest( new NameTest(Type.ATTRIBUTE, nameCode, getNamePool()), Token.INTERSECT, new ContentTypeTest(Type.ATTRIBUTE, typeCode, getConfiguration(), false)); checkItemType(type, nodeSupplier(Type.ATTRIBUTE, nameCode, value), locationId); } nextReceiver.attribute(nameCode, typeCode, value, locationId, properties); }
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute, as held in the name pool * @param typeCode The type of the attribute, as held in the name pool * @param properties Bit significant value. The following bits are defined: * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) throws XPathException { if (level == 0) { if (++count == 2) { checkAllowsMany(locationId); } ItemType type = new CombinedNodeTest( new NameTest(Type.ATTRIBUTE, nameCode, getNamePool()), Token.INTERSECT, new ContentTypeTest(Type.ATTRIBUTE, getConfiguration().getSchemaType(typeCode), getConfiguration())); checkItemType(type, locationId); } nextReceiver.attribute(nameCode, typeCode, value, locationId, properties); }
/** * Make an ItemType representing an element declaration in the schema. This is the * equivalent of the XPath syntax <code>schema-element(element-name)</code> * * <p>It is undefined whether two calls supplying the same argument values will * return the same ItemType object.</p> * * @param name the element name * @return the ItemType * @throws SaxonApiException if the schema does not contain a global element declaration * for the given name */ public ItemType getSchemaElementTest(QName name) throws SaxonApiException { Configuration config = processor.getUnderlyingConfiguration(); int fingerprint = config.getNamePool().allocate("", name.getNamespaceURI(), name.getLocalName()); SchemaDeclaration decl = config.getElementDeclaration(fingerprint); if (decl == null) { throw new SaxonApiException("No global declaration found for element " + name.getClarkName()); } CombinedNodeTest combo = new CombinedNodeTest( new NameTest(Type.ELEMENT, fingerprint, config.getNamePool()), Token.INTERSECT, new ContentTypeTest(Type.ELEMENT, decl.getType(), config)); combo.setGlobalComponentTest(true); return new ItemType(combo, processor); }
/** * Get an ItemType representing an attribute declaration in the schema. This is the * equivalent of the XPath syntax <code>schema-attribute(attribute-name)</code> * * <p>It is undefined whether two calls supplying the same argument values will * return the same ItemType object.</p> * * @param name the attribute name * @return the ItemType * @throws SaxonApiException if the schema does not contain a global attribute declaration * for the given name */ public ItemType getSchemaAttributeTest(QName name) throws SaxonApiException { Configuration config = processor.getUnderlyingConfiguration(); int fingerprint = config.getNamePool().allocate("", name.getNamespaceURI(), name.getLocalName()); SchemaDeclaration decl = config.getAttributeDeclaration(fingerprint); if (decl == null) { throw new SaxonApiException("No global declaration found for attribute " + name.getClarkName()); } CombinedNodeTest combo = new CombinedNodeTest( new NameTest(Type.ATTRIBUTE, fingerprint, config.getNamePool()), Token.INTERSECT, new ContentTypeTest(Type.ATTRIBUTE, decl.getType(), config)); combo.setGlobalComponentTest(true); return new ItemType(combo, processor); }