Package net.sf.saxon.pattern
Class PatternThatSetsCurrent
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.PseudoExpression
-
- net.sf.saxon.pattern.Pattern
-
- net.sf.saxon.pattern.PatternThatSetsCurrent
-
- All Implemented Interfaces:
ExportAgent
,Locatable
,IdentityComparable
,Traceable
public class PatternThatSetsCurrent extends Pattern
This class represents a pattern that sets the value of current() to the node being matched, and then wraps another pattern that uses the value of current()
-
-
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 PatternThatSetsCurrent(Pattern wrappedPattern)
PatternThatSetsCurrent(Pattern wrappedPattern, LocalVariableBinding binding)
-
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 patternPattern
convertToTypedPattern(java.lang.String val)
Convert the pattern to a typed pattern, in which an element name is treated as schema-element(N)Pattern
copy(RebindingMap rebindings)
Copy a pattern.void
export(ExpressionPresenter presenter)
Diagnostic print of expression structure.LocalBinding
getCurrentBinding()
Get the binding of the item being matched by the pattern, that is, the binding that represents the value of the current() functionint
getFingerprint()
Determine the name fingerprint of nodes to which this pattern applies.HostLanguage
getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this containerItemType
getItemType()
Get an ItemType that all the items matching this pattern must satisfyUType
getUType()
Get a UType indicating which kinds of items this Pattern can match.Pattern
getWrappedPattern()
boolean
hasVariableBinding(Binding binding)
Ask whether this expression is, or contains, the binding of a given variableboolean
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 item.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.Iterable<Operand>
operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.java.lang.String
reconstruct()
Get the original pattern textPattern
simplify()
Simplify the pattern by applying any context-independent optimisations.Pattern
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Type-check the pattern.-
Methods inherited from class net.sf.saxon.pattern.Pattern
bindCurrent, effectiveBooleanValue, getDefaultPriority, getDependencies, getOriginalText, handleDynamicError, isLiftable, isRecoverable, make, matchesCurrentGroup, optimize, patternContainsVariable, replaceCurrent, selectNodes, setOriginalText, setPriority, setRecoverable, 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, dynamicError, equals, 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, 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
-
PatternThatSetsCurrent
public PatternThatSetsCurrent(Pattern wrappedPattern)
-
PatternThatSetsCurrent
public PatternThatSetsCurrent(Pattern wrappedPattern, LocalVariableBinding binding)
-
-
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
-
getCurrentBinding
public LocalBinding getCurrentBinding()
Get the binding of the item being matched by the pattern, that is, the binding that represents the value of the current() function- Returns:
- the binding of the item being matched by the pattern
-
hasVariableBinding
public boolean hasVariableBinding(Binding binding)
Ask whether this expression is, or contains, the binding of a given variable- Overrides:
hasVariableBinding
in classExpression
- Parameters:
binding
- the variable binding- Returns:
- true if this expression is the variable binding (for example a ForExpression or LetExpression) or if it is a FLWOR expression that binds the variable in one of its clauses.
-
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- Returns:
- the next slot that is free to be allocated
-
matches
public boolean matches(Item item, XPathContext context) throws XPathException
Determine whether this Pattern matches the given item. 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 item 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 item 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)
-
getItemType
public ItemType getItemType()
Get an ItemType that all the items matching this pattern must satisfy- Specified by:
getItemType
in classPattern
- Returns:
- an ItemType, as specific as possible, which all the matching items satisfy
-
simplify
public Pattern simplify() throws XPathException
Simplify the pattern by applying any context-independent optimisations. Default implementation does nothing.- Overrides:
simplify
in classPattern
- Returns:
- the simplified expression (or the original if unchanged, or if modified in-situ)
- Throws:
XPathException
- if an error is discovered during expression rewriting
-
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)
-
getUType
public UType getUType()
Get a UType indicating which kinds of items this Pattern can match.
-
getFingerprint
public int getFingerprint()
Determine the name fingerprint of nodes to which this pattern applies. Used for optimisation.- Overrides:
getFingerprint
in classPattern
- Returns:
- A fingerprint that the nodes must match, or -1 if it can match multiple fingerprints, or it if matches atomic values
-
reconstruct
public java.lang.String reconstruct()
Get the original pattern text- Overrides:
reconstruct
in classPattern
-
getHostLanguage
public HostLanguage getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container- Overrides:
getHostLanguage
in classPattern
- Returns:
- typically
HostLanguage.XSLT
orHostLanguage.XQUERY
-
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
-
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)
-
convertToTypedPattern
public Pattern convertToTypedPattern(java.lang.String val) throws XPathException
Convert the pattern to a typed pattern, in which an element name is treated as schema-element(N)- Overrides:
convertToTypedPattern
in classPattern
- Parameters:
val
- either "strict" or "lax" depending on the value of xsl:mode/@typed- Returns:
- either the original pattern unchanged, or a new pattern as the result of the conversion
- Throws:
XPathException
- if the pattern cannot be converted
-
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.
-
getWrappedPattern
public Pattern getWrappedPattern()
-
-