Class NodeSetPattern
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.PseudoExpression
-
- net.sf.saxon.pattern.Pattern
-
- net.sf.saxon.pattern.NodeSetPattern
-
- All Implemented Interfaces:
ExportAgent
,Locatable
,IdentityComparable
,Traceable
public class NodeSetPattern extends Pattern
A NodeSetPattern is a pattern based on an expression that is evaluated to return a set of nodes; a node matches the pattern if it is a member of this node-set.In XSLT 2.0 there are two forms of NodeSetPattern allowed, represented by calls on the id() and key() functions. In XSLT 3.0, additional forms are allowed, for example a variable reference, and a call to the doc() function. This class provides the general capability to use any expression at the head of a pattern. This is used also to support streaming, where streaming XPath expressions are mapped to patterns.
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD
-
-
Constructor Summary
Constructors Constructor Description NodeSetPattern(Expression exp)
Create a node-set pattern.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
allocateSlots(SlotManager slotManager, int nextFree)
Allocate slots to any variables used within the patternint
computeHashCode()
Hashcode supporting equals()Pattern
copy(RebindingMap rebindings)
Copy a pattern.boolean
equals(java.lang.Object other)
Determine whether this pattern is the same as another patternvoid
export(ExpressionPresenter presenter)
Diagnostic print of expression structure.int
getDependencies()
Get the dependencies of the pattern.ItemType
getItemType()
Get a NodeTest that all the nodes matching this pattern must satisfyExpression
getSelectionExpression()
Get the underlying expressionUType
getUType()
Get a UType indicating which kinds of items this Pattern can match.boolean
isMotionless()
Test whether a pattern is motionless, that is, whether it can be evaluated against a node without repositioning the input stream.boolean
matches(Item item, XPathContext context)
Determine whether this Pattern matches the given Nodejava.lang.Iterable<Operand>
operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.Pattern
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Perform optimisation of an expression and its subexpressions.SequenceIterator
selectNodes(TreeInfo doc, XPathContext context)
Select nodes in a document using this PatternFinder.void
setItemType(ItemType type)
Set the item type, that is, the type of nodes/items which the pattern will matchPattern
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Type-check the pattern.-
Methods inherited from class net.sf.saxon.pattern.Pattern
bindCurrent, convertToTypedPattern, effectiveBooleanValue, getDefaultPriority, getFingerprint, getHostLanguage, getOriginalText, handleDynamicError, isLiftable, isRecoverable, make, matchesBeneathAnchor, matchesCurrentGroup, patternContainsVariable, reconstruct, replaceCurrent, setOriginalText, setPriority, setRecoverable, simplify, toPattern, toShortString, toString
-
Methods inherited from class net.sf.saxon.expr.PseudoExpression
computeCardinality, evaluateAsString, evaluateItem, getImplementationMethod, iterate, process
-
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeSpecialProperties, computeStaticProperties, dynamicError, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getCost, getEvaluationMethod, getExpressionName, getExtraProperty, getIntegerBounds, getInterpretedExpression, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, suppressValidation, typeCheckChildren, typeError, unordered, verifyParentPointers
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Constructor Detail
-
NodeSetPattern
public NodeSetPattern(Expression exp)
Create a node-set pattern.- Parameters:
exp
- an expression that can be evaluated to return a node-set; a node matches the pattern if it is present in this node-set. The expression must not depend on the focus, though it can depend on other aspects of the dynamic context such as local or global variables.
-
-
Method Detail
-
operands
public java.lang.Iterable<Operand> operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression. Default implementation works off the results of iterateSubExpressions()If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.
- Overrides:
operands
in classExpression
- Returns:
- an iterator containing the sub-expressions of this expression
-
getSelectionExpression
public Expression getSelectionExpression()
Get the underlying expression- Returns:
- the expression that returns all the selected nodes
-
typeCheck
public Pattern typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
Type-check the pattern. Default implementation does nothing. This is only needed for patterns that contain variable references or function calls.- Overrides:
typeCheck
in classPattern
- Parameters:
visitor
- the expression visitorcontextItemType
- the type of the context item at the point where the pattern is defined. Set to null if it is known that the context item is undefined.- Returns:
- the optimised Pattern
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
optimize
public Pattern optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Description copied from class:Pattern
Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.
- Overrides:
optimize
in classPattern
- Parameters:
visitor
- an expression visitorcontextInfo
- the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set toType.ITEM_TYPE
- Returns:
- the original expression, rewritten if appropriate to optimize execution
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
setItemType
public void setItemType(ItemType type)
Set the item type, that is, the type of nodes/items which the pattern will match- Parameters:
type
- the item type that the pattern will match
-
getDependencies
public int getDependencies()
Get the dependencies of the pattern. The only possible dependency for a pattern is on local variables. This is analyzed in those patterns where local variables may appear.- Overrides:
getDependencies
in classPattern
- Returns:
- the dependencies, as a bit-significant mask
-
isMotionless
public boolean isMotionless()
Test whether a pattern is motionless, that is, whether it can be evaluated against a node without repositioning the input stream. This is a necessary condition for patterns used as the match pattern of a streamed template rule.- Overrides:
isMotionless
in classPattern
- Returns:
- true if the pattern is motionless, that is, if it can be evaluated against a streamed node without changing the position in the streamed input file
-
allocateSlots
public int allocateSlots(SlotManager slotManager, int nextFree)
Allocate slots to any variables used within the pattern- Overrides:
allocateSlots
in classPattern
- Parameters:
slotManager
- the slot manager representing the stack frame for local variablesnextFree
- the next slot that is free to be allocated @return the next slot that is free to be allocated- Returns:
- the next slot that is free to be allocated
-
selectNodes
public SequenceIterator selectNodes(TreeInfo doc, XPathContext context) throws XPathException
Select nodes in a document using this PatternFinder.- Overrides:
selectNodes
in classPattern
- Parameters:
doc
- the document node at the root of a treecontext
- the dynamic evaluation context- Returns:
- an iterator over the selected nodes in the document.
- Throws:
XPathException
-
matches
public boolean matches(Item item, XPathContext context) throws XPathException
Determine whether this Pattern matches the given Node- Specified by:
matches
in classPattern
- Parameters:
item
- The NodeInfo representing the Element or other node to be tested against the Patterncontext
- The dynamic context.- Returns:
- true if the node matches the Pattern, false otherwise
- Throws:
XPathException
- if an error occurs while matching the pattern (the caller will usually treat this the same as a false result)
-
getUType
public UType getUType()
Get a UType indicating which kinds of items this Pattern can match.
-
getItemType
public ItemType getItemType()
Get a NodeTest that all the nodes matching this pattern must satisfy- Specified by:
getItemType
in classPattern
- Returns:
- an ItemType, as specific as possible, which all the matching items satisfy
-
equals
public boolean equals(java.lang.Object other)
Determine whether this pattern is the same as another pattern- Overrides:
equals
in classExpression
- Parameters:
other
- the other object- Returns:
- true if the other operand is an expression and if it can be determined that the two expressions are equivalent, in the sense that they will always return the same result.
-
computeHashCode
public int computeHashCode()
Hashcode supporting equals()- Overrides:
computeHashCode
in classExpression
- Returns:
- a computed hash code
-
copy
public Pattern copy(RebindingMap rebindings)
Copy a pattern. This makes a deep copy.
-
export
public void export(ExpressionPresenter presenter) throws XPathException
Description copied from class:Expression
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
export
in interfaceExportAgent
- Specified by:
export
in classPattern
- Parameters:
presenter
- the expression presenter used to display the structure- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
-