private BinaryOperation exprFor (PathStep.Axis axis, CombinedNodeTest nodeTest) { NodeTest[] tests = nodeTest.getComponentNodeTests(); BinaryOperation.Operator op = operatorFor(nodeTest.getOperator()); return new BinaryOperation (exprFor(axis, tests[0]), op, exprFor(axis, tests[1])); }
/** * 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; } }
/** * Get the basic kind of object that this ItemType matches: for a NodeTest, this is the kind of node, * or Type.Node if it matches different kinds of nodes. * * @return the node kind matched by this node test */ public int getPrimitiveType() { int mask = getNodeKindMask(); if (mask == (1<<Type.ELEMENT)) { return Type.ELEMENT; } if (mask == (1<<Type.ATTRIBUTE)) { return Type.ATTRIBUTE; } if (mask == (1<<Type.DOCUMENT)) { return Type.DOCUMENT; } return Type.NODE; }
/** * 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); }
/** * Simplify type so that hierarchy comparison could be accurate. */ private ItemType simplify(ItemType it) { TypeHierarchy th = processor.getUnderlyingConfiguration().getTypeHierarchy(); if (it instanceof CombinedNodeTest) { CombinedNodeTest n = (CombinedNodeTest) it; __log.debug(n.getComponentNodeTests()); return simplify(n.getComponentNodeTests()[1]); } else if (it instanceof NodeTest) { NodeTest n = (NodeTest) it; __log.debug(n); SchemaType t = n.getContentType(); if (t.isSimpleType() || t.equals(AnyType.getInstance())) { AtomicType at = it.getAtomizedItemType(); while (!at.isBuiltInType()) at = at.getSuperType(th).getAtomizedItemType(); return at; } else if (t.isComplexType()) { return n; } else { return AnyItemType.getInstance(); } } else { if (it == null) return null; else return it.getAtomizedItemType(); } }
/** * Return a string representation of this ItemType suitable for use in stylesheet * export files. This differs from the result of toString() in that it will not contain * any references to anonymous types. Note that it may also use the Saxon extended syntax * for union types and tuple types. The default implementation returns the result of * calling {@code toString()}. * * @return the string representation as an instance of the XPath SequenceType construct */ @Override public String toExportString() { return makeString(true); }
/** * Get the basic kind of object that this ItemType matches: for a NodeTest, this is the kind of node, * or Type.Node if it matches different kinds of nodes. * * @return the node kind matched by this node test */ public int getPrimitiveType() { UType mask = getUType(); if (mask.equals(UType.ELEMENT)) { return Type.ELEMENT; } if (mask.equals(UType.ATTRIBUTE)) { return Type.ATTRIBUTE; } if (mask.equals(UType.DOCUMENT)) { return Type.DOCUMENT; } return Type.NODE; }
/** * 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); }
/** * Check that a SequenceType used in the definition of an imported variable or function * is available in the importing module * @param importedType the type that is to be checked * @param declaration the containing query or function definition * @throws net.sf.saxon.trans.XPathException if an error is fonnd. */ public void checkImportedType(SequenceType importedType, Declaration declaration) throws XPathException { ItemType type = importedType.getPrimaryType(); if (type instanceof AnyItemType) { return; } if (type.isAtomicType()) { int f = ((AtomicType)type).getFingerprint(); checkSchemaNamespaceImported(f, declaration); } else if (type instanceof ContentTypeTest) { SchemaType annotation = ((ContentTypeTest)type).getSchemaType(); int f = annotation.getFingerprint(); checkSchemaNamespaceImported(f, declaration); } else if (type instanceof CombinedNodeTest) { NodeTest[] tests = ((CombinedNodeTest)type).getComponentNodeTests(); for (int i=0; i<tests.length; i++) { SequenceType st = SequenceType.makeSequenceType(tests[i], StaticProperty.EXACTLY_ONE); checkImportedType(st, declaration); } } }
/** * Return a string representation of this ItemType suitable for use in stylesheet * export files. This differs from the result of toString() in that it will not contain * any references to anonymous types. Note that it may also use the Saxon extended syntax * for union types and tuple types. The default implementation returns the result of * calling {@code toString()}. * * @return the string representation as an instance of the XPath SequenceType construct */ @Override public String toExportString() { return makeString(true); }
/** * Get the basic kind of object that this ItemType matches: for a NodeTest, this is the kind of node, * or Type.Node if it matches different kinds of nodes. * * @return the node kind matched by this node test */ public int getPrimitiveType() { UType mask = getUType(); if (mask.equals(UType.ELEMENT)) { return Type.ELEMENT; } if (mask.equals(UType.ATTRIBUTE)) { return Type.ATTRIBUTE; } if (mask.equals(UType.DOCUMENT)) { return Type.DOCUMENT; } return Type.NODE; }
/** * 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; }
((CombinedNodeTest) pattern.getItemType()).getOperator() == Token.UNION) { CombinedNodeTest cnt = (CombinedNodeTest) pattern.getItemType(); NodeTest[] nt = cnt.getComponentNodeTests(); final NodeTestPattern nt0 = new NodeTestPattern(nt[0]); ExpressionTool.copyLocationInfo(pattern, nt0);
return nameTest; } else { CombinedNodeTest combo = new CombinedNodeTest(nameTest, Token.INTERSECT, contentTest); combo.setGlobalComponentTest(schemaDeclaration); return combo; if (primaryType == Type.ATTRIBUTE) { NodeTest nameTest = new NameTest(Type.ATTRIBUTE, nameCode, env.getNamePool()); result = new CombinedNodeTest(nameTest, Token.INTERSECT, typeTest); nextToken(); } else { result = new CombinedNodeTest(nameTest, Token.INTERSECT, typeTest); nextToken(); if (t.currentToken == Token.QMARK) {
/** * Check that a SequenceType used in the definition of an imported variable or function * is available in the importing module * @param importedType the type that is to be checked * @param declaration the containing query or function definition * @throws net.sf.saxon.trans.XPathException if an error is fonnd. */ public void checkImportedType(SequenceType importedType, Declaration declaration) throws XPathException { ItemType type = importedType.getPrimaryType(); if (type instanceof AnyItemType) { return; } if (type.isAtomicType()) { int f = ((AtomicType)type).getFingerprint(); checkSchemaNamespaceImported(f, declaration); } else if (type instanceof ContentTypeTest) { SchemaType annotation = ((ContentTypeTest)type).getSchemaType(); int f = annotation.getFingerprint(); checkSchemaNamespaceImported(f, declaration); } else if (type instanceof CombinedNodeTest) { NodeTest[] tests = ((CombinedNodeTest)type).getComponentNodeTests(); for (int i=0; i<tests.length; i++) { SequenceType st = SequenceType.makeSequenceType(tests[i], StaticProperty.EXACTLY_ONE); checkImportedType(st, declaration); } } }
public String toString() { return makeString(false); }
/** * Get the basic kind of object that this ItemType matches: for a NodeTest, this is the kind of node, * or Type.Node if it matches different kinds of nodes. * * @return the node kind matched by this node test */ public int getPrimitiveType() { int mask = getNodeKindMask(); if (mask == (1<<Type.ELEMENT)) { return Type.ELEMENT; } if (mask == (1<<Type.ATTRIBUTE)) { return Type.ATTRIBUTE; } if (mask == (1<<Type.DOCUMENT)) { return Type.DOCUMENT; } return Type.NODE; }
/** * 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; }
((CombinedNodeTest) pattern.getItemType()).getOperator() == Token.UNION) { CombinedNodeTest cnt = (CombinedNodeTest) pattern.getItemType(); NodeTest[] nt = cnt.getComponentNodeTests(); final NodeTestPattern nt0 = new NodeTestPattern(nt[0]); ExpressionTool.copyLocationInfo(pattern, nt0);
return nameTest; } else { CombinedNodeTest combo = new CombinedNodeTest(nameTest, Token.INTERSECT, contentTest); combo.setGlobalComponentTest(schemaDeclaration); return combo; if (primaryType == Type.ATTRIBUTE) { NodeTest nameTest = new NameTest(Type.ATTRIBUTE, nameCode, env.getNamePool()); result = new CombinedNodeTest(nameTest, Token.INTERSECT, typeTest); nextToken(); } else { result = new CombinedNodeTest(nameTest, Token.INTERSECT, typeTest); nextToken(); if (t.currentToken == Token.QMARK) {