net.sf.saxon.pattern.SubstitutionGroupTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of saxon9 Show documentation
Show all versions of saxon9 Show documentation
Provides a basic XSLT 2.0 and XQuery 1.0 processor (W3C Recommendations,
January 2007). Command line interfaces and implementations of several
Java APIs (DOM, XPath, s9api) are also included.
The newest version!
package net.sf.saxon.pattern;
import net.sf.saxon.om.NamePool;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.sort.IntHashSet;
import net.sf.saxon.tinytree.TinyTree;
import net.sf.saxon.type.Type;
/**
* NodeTest is an interface that enables a test of whether a node has a particular
* name and type. A SubstitutionGroupTest matches element nodes whose name is one of
* a given set of names: it is used for KindTests of the form schema-element(N) where all
* elements in a substitution group are to be matched.
*
* @author Michael H. Kay
*/
public class SubstitutionGroupTest extends NodeTest {
private int head;
private IntHashSet group;
/**
* Constructor
* @param head The name of the head element of the substitution group
* @param group An IntSet containing Integer values representing the fingerprints
* of element names included in the substitution group
*/
public SubstitutionGroupTest(int head, IntHashSet group) {
this.group = group;
this.head = head;
}
/**
* Test whether this node test is satisfied by a given node
* @param nodeKind The type of node to be matched
* @param nameCode identifies the expanded name of the node to be matched
*/
public boolean matches(int nodeKind, int nameCode, int annotation) {
return nodeKind == Type.ELEMENT &&
group.contains(nameCode & NamePool.FP_MASK);
}
/**
* Test whether this node test is satisfied by a given node on a TinyTree. The node
* must be a document, element, text, comment, or processing instruction node.
* This method is provided
* so that when navigating a TinyTree a node can be rejected without
* actually instantiating a NodeInfo object.
*
* @param tree the TinyTree containing the node
* @param nodeNr the number of the node within the TinyTree
* @return true if the node matches the NodeTest, otherwise false
*/
public boolean matches(TinyTree tree, int nodeNr) {
return tree.getNodeKind(nodeNr) == Type.ELEMENT &&
group.contains(tree.getNameCode(nodeNr) & NamePool.FP_MASK);
}
/**
* Test whether this node test is satisfied by a given node. This alternative
* method is used in the case of nodes where calculating the fingerprint is expensive,
* for example DOM or JDOM nodes.
* @param node the node to be matched
*/
public boolean matches(NodeInfo node) {
return node.getNodeKind() == Type.ELEMENT &&
group.contains(node.getFingerprint());
}
/**
* Determine the default priority of this node test when used on its own as a Pattern
*/
public final double getDefaultPriority() {
return 0.0;
}
/**
* Determine the types of nodes to which this pattern applies. Used for optimisation.
* For patterns that match nodes of several types, return Type.NODE
* @return the type of node matched by this pattern. e.g. Type.ELEMENT or Type.TEXT
*/
public int getPrimitiveType() {
return Type.ELEMENT;
}
/**
* Get a mask indicating which kinds of nodes this NodeTest can match. This is a combination
* of bits: 1<
© 2015 - 2025 Weber Informatics LLC | Privacy Policy