Package net.sf.saxon.pattern
Class AnchorPattern
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.PseudoExpression
-
- net.sf.saxon.pattern.Pattern
-
- net.sf.saxon.pattern.AnchorPattern
-
- All Implemented Interfaces:
ExportAgent
,Locatable
,IdentityComparable
,Traceable
- Direct Known Subclasses:
CurrentGroupPattern
public class AnchorPattern extends Pattern
This is a special pattern that matches the "anchor node". It is used for the selectors that arise when evaluating XPath expressions in streaming mode; the anchor node is the context node for the streamed XPath evaluation. Given a streamed evaluation of an expression such as ./BOOKS/BOOK/PRICE, the way we evaluate this is to turn it into a pattern, which is then tested against all descendant nodes. Conceptually the pattern is $A/BOOKS/BOOK/PRICE, where $A is referred to as the anchor node. When we evaluate the pattern against (say) a PRICE element, the match will only succeed if the name of the element is "PRICE" and its ancestors are, in order, a BOOK element, a BOOKS element, and the anchor node $A.
-
-
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 Modifier Constructor Description protected
AnchorPattern()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Pattern
copy(RebindingMap rebindings)
Copy an AnchorPattern.void
export(ExpressionPresenter presenter)
Diagnostic print of expression structure.static AnchorPattern
getInstance()
ItemType
getItemType()
Get a NodeTest that all the nodes matching this pattern must satisfyUType
getUType()
Get a UType indicating which kinds of items this Pattern can match.boolean
matches(Item item, XPathContext context)
Determine whether this Pattern matches the given Node.boolean
matchesBeneathAnchor(NodeInfo node, NodeInfo anchor, XPathContext context)
Determine whether this pattern matches a given Node within the subtree rooted at a given anchor node.java.lang.String
reconstruct()
Reconstruct a string representation of the pattern from its compiled form, in cases where the original text is not availablePattern
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Type-check the pattern.-
Methods inherited from class net.sf.saxon.pattern.Pattern
allocateSlots, bindCurrent, convertToTypedPattern, effectiveBooleanValue, getDefaultPriority, getDependencies, getElaborator, getFingerprint, getHostLanguage, getOriginalText, handleDynamicError, isLiftable, isMotionless, isRecoverable, make, matchesCurrentGroup, matchesItem, optimize, patternContainsVariable, replaceCurrent, selectNodes, 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, computeHashCode, computeSpecialProperties, computeStaticProperties, dispatchTailCall, dynamicError, equals, explain, getCardinality, getConfiguration, getCost, getEvaluationMethod, getExpressionName, getExtraProperty, getIntegerBounds, 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, makeElaborator, markTailFunctionCalls, operandList, operands, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, typeCheckChildren, typeError, unordered, verifyParentPointers, withLocation
-
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
-
-
-
-
Method Detail
-
getInstance
public static AnchorPattern getInstance()
-
getUType
public UType getUType()
Get a UType indicating which kinds of items this Pattern can match.
-
typeCheck
public Pattern typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
Type-check the pattern.- 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)
-
matchesBeneathAnchor
public boolean matchesBeneathAnchor(NodeInfo node, NodeInfo anchor, XPathContext context) throws XPathException
Determine whether this pattern matches a given Node within the subtree rooted at a given anchor node. This method is used when the pattern is used for streaming.- Overrides:
matchesBeneathAnchor
in classPattern
- Parameters:
node
- The NodeInfo representing the Element or other node to be tested against the Patternanchor
- The anchor node, which must match any AnchorPattern subpatterncontext
- The dynamic context. Only relevant if the pattern uses variables, or contains calls on functions such as document() or key().- 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)
-
matches
public boolean matches(Item item, XPathContext context) throws XPathException
Determine whether this Pattern matches the given Node. This is the main external interface for matching patterns: it sets current() to the node being tested- Specified by:
matches
in classPattern
- Parameters:
item
- The NodeInfo representing the Element or other node to be tested against the Patterncontext
- The dynamic context. Only relevant if the pattern uses variables, or contains calls on functions such as document() or key().- Returns:
- true if the node matches the Pattern, false otherwise
- Throws:
XPathException
- if an error occurs while matching the pattern
-
getItemType
public ItemType getItemType()
Get a NodeTest that all the nodes matching this pattern must satisfy- Specified by:
getItemType
in classPattern
- Returns:
- a NodeTest, as specific as possible, which all the matching nodes satisfy
-
reconstruct
public java.lang.String reconstruct()
Description copied from class:Pattern
Reconstruct a string representation of the pattern from its compiled form, in cases where the original text is not available- Overrides:
reconstruct
in classPattern
-
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.
-
copy
public Pattern copy(RebindingMap rebindings)
Copy an AnchorPattern. Since there is only one, return the same.
-
-