Package net.sf.saxon.pattern
Class SelectorTest
java.lang.Object
net.sf.saxon.pattern.SelectorTest
- All Implemented Interfaces:
NamedXNodePredicate,NodePredicate,NodeTest,NodeVectorMatchMaker
public class SelectorTest
extends Object
implements NodeTest, NodeVectorMatchMaker, NamedXNodePredicate
A SelectorTest represents an axis step written as
./NNN or ./axis::NNN
where NNN is either an EQName or a wildcard (such as prefix:* or *:prefix).
The semantics depend on whether we are selecting JNodes or XNodes, which we don't know
in advance (except in the case where the axis is the attribute or namespace axis).
Once it is known whether the nodes to be matched will be JNodes or XNodes, this node test can be replaced by something more specific; but in many cases that isn't known till evaluation time.
The boolean flag asNCName is true if the test was written as a plain NCName. Where JNodes are being matched, this is interpreted as a string-valued key rather than as a QName.
The nodeKind represents the principal node kind for the axis, which is only relevant when selecting XNodes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasXNodeTest(Configuration config) Get an equivalent node test, knowing that it will only be used to match XNodesbooleanDetermines whether two NameTests are equalexplainMismatch(Item item, TypeHierarchy th) Get extra diagnostic information about why a supplied item does not conform to this item type, if available.export()final doubleDetermine the default priority of this node test when used on its own as a PatternGet an item type that all matching nodes must satisfygetMatcher(NodeVectorTree tree) Get a matching function that can be used to test whether numbered nodes in a TinyTree or DominoTree satisfy the node test.Get the name of the nodes matched by this nodetest, if it matches a specific name.intGet the kind of nodes that this node predicate matchesExtract a QNameTest (the strongest one possible) that must be satisfied by a node if it is to satisfy this NodeTestintGet a fingerprint that can be used to match required nodes.getUType()Get the correspondingUType.inthashCode()Returns a hash code value for the object.booleanAsk whether having the required fingerprint and node kind is a sufficient condition for a node to satisfy the predicate, or whether other conditions (such as type annotation or nillability) must also be satisfied.booleanDetermine whether the content type (if present) is nillablebooleanTest whether this node test is satisfied by a given node.Get a concise string representation of this node test for use in diagnosticstoString()
-
Constructor Details
-
SelectorTest
-
-
Method Details
-
getNodeKind
public int getNodeKind()Get the kind of nodes that this node predicate matches- Specified by:
getNodeKindin interfaceNamedXNodePredicate- Returns:
- the kind of nodes, for example
Type.ELEMENTorType.ATTRIBUTE
-
asXNodeTest
Get an equivalent node test, knowing that it will only be used to match XNodes- Specified by:
asXNodeTestin interfaceNodeTest- Returns:
- an equivalent node test for XNodes
-
getUType
Get the correspondingUType. A UType is a union of primitive item types. -
getMatcher
Get a matching function that can be used to test whether numbered nodes in a TinyTree or DominoTree satisfy the node test. (Calling this matcher must give the same result as callingmatchesNode(tree.getNode(nodeNr)), but it may well be faster).- Specified by:
getMatcherin interfaceNodeVectorMatchMaker- Parameters:
tree- the tree against which the returned function will operate- Returns:
- an IntPredicate; the matches() method of this predicate takes a node number as input, and returns true if and only if the node identified by this node number matches the node test.
-
getRequiredFingerprint
public int getRequiredFingerprint()Get a fingerprint that can be used to match required nodes.- Specified by:
getRequiredFingerprintin interfaceNamedXNodePredicate- Returns:
- if all nodes selected by the node test are of the required nodeKind, and have the same fingerprint, then return that fingerprint; otherwise return -1. Note that it is acceptable for the node test to impose further constraints, for example on the type annotation.
-
isFingerprintSufficient
public boolean isFingerprintSufficient()Ask whether having the required fingerprint and node kind is a sufficient condition for a node to satisfy the predicate, or whether other conditions (such as type annotation or nillability) must also be satisfied.- Specified by:
isFingerprintSufficientin interfaceNamedXNodePredicate- Returns:
- true if matching the fingerprint is a sufficient condition.
-
getItemType
Get an item type that all matching nodes must satisfy- Specified by:
getItemTypein interfaceNodeTest- Returns:
- an item type
-
test
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.- Specified by:
testin interfaceNodePredicate- Specified by:
testin interfaceNodeTest- Parameters:
gnode- the node to be matched- Returns:
- true if the node test is satisfied by the supplied node, false otherwise
-
getDefaultPriority
public final double getDefaultPriority()Determine the default priority of this node test when used on its own as a Pattern- Specified by:
getDefaultPriorityin interfaceNodeTest- Returns:
- the default priority for the pattern
-
getQNameTest
Extract a QNameTest (the strongest one possible) that must be satisfied by a node if it is to satisfy this NodeTest- Specified by:
getQNameTestin interfaceNodeTest- Returns:
- the strongest possible QNameTest
-
getMatchingNodeName
Get the name of the nodes matched by this nodetest, if it matches a specific name. Return null if the node test matches nodes of more than one name- Specified by:
getMatchingNodeNamein interfaceNamedXNodePredicate- Returns:
- the name that a node must have if it is to satisfy the predicate
-
toString
-
hashCode
public int hashCode()Returns a hash code value for the object. -
equals
Determines whether two NameTests are equal -
explainMismatch
Get extra diagnostic information about why a supplied item does not conform to this item type, if available. If extra information is returned, it should be in the form of a complete sentence, minus the closing full stop. No information should be returned for obvious cases.- Specified by:
explainMismatchin interfaceNodeTest- Parameters:
item- the item that doesn't match this typeth- the type hierarchy cache- Returns:
- optionally, a message explaining why the item does not match the type
-
toShortString
Description copied from interface:NodeTestGet a concise string representation of this node test for use in diagnostics- Specified by:
toShortStringin interfaceNodeTest- Returns:
- a suitably abbreviated respresention of the node test
-
isNillable
public boolean isNillable()Determine whether the content type (if present) is nillable- Specified by:
isNillablein interfaceNodeTest- Returns:
- true if the content test (when present) can match nodes that are nilled
-
export
-