Package net.sf.saxon.pattern
Class Pattern
java.lang.Object
net.sf.saxon.pattern.Pattern
- All Implemented Interfaces:
Serializable,SourceLocator,Container,PatternFinder
- Direct Known Subclasses:
IDPattern,KeyPattern,LocationPathPattern,NodeTestPattern,UnionPattern
A Pattern represents the result of parsing an XSLT pattern string.
Patterns are created by calling the static method Pattern.make(string).
The pattern is used to test a particular node by calling match().
Patterns are created by calling the static method Pattern.make(string).
The pattern is used to test a particular node by calling match().
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintallocateSlots(StaticContext env, SlotManager slotManager, int nextFree) Allocate slots to any variables used within the patternanalyze(ExpressionVisitor visitor, ItemType contextItemType) Type-check the pattern.intGet the column number (always -1)doubleDetermine the default priority to use if this pattern appears as a match pattern for a template with no explicit priority attribute.intGet the dependencies of the pattern.Get the executable containing this patternintDetermine the name fingerprint of nodes to which this pattern applies.intGet the host language (XSLT, XQuery, XPath) used to implement the code in this containerintGet the line number on which the pattern was definedGet the LocationProvider allowing location identifiers to be resolved.intDetermine the types of nodes to which this pattern applies.abstract NodeTestGet a NodeTest that all the nodes matching this pattern must satisfyGet the public ID (always null)Get the system id of the entity in which the pattern occurredprotected booleaninternalMatches(NodeInfo node, XPathContext context) Determine whether this Pattern matches the given Node.Iterate over the subexpressions within this patternstatic Patternmake(String pattern, StaticContext env, Executable exec) Static method to make a Pattern by parsing a String.Make an expression whose effect is to select all the nodes that match this pattern in a given document.abstract booleanmatches(NodeInfo node, XPathContext context) Determine whether this Pattern matches the given Node.voidpromote(PromotionOffer offer) Offer promotion for subexpressions within this pattern.booleanreplaceSubExpression(Expression original, Expression replacement) Replace one subexpression by a replacement subexpressionselectNodes(DocumentInfo doc, XPathContext context) Select nodes in a document using this PatternFinder.voidsetExecutable(Executable executable) Set the executable containing this patternvoidsetLineNumber(int lineNumber) Set the line number where the pattern occurredvoidsetOriginalText(String text) Set the original text of the pattern for use in diagnosticsvoidsetSystemId(String systemId) Set the system ID where the pattern occurredsimplify(ExpressionVisitor visitor) Simplify the pattern by applying any context-independent optimisations.toString()Get the original pattern text
-
Constructor Details
-
Pattern
public Pattern()
-
-
Method Details
-
make
public static Pattern make(String pattern, StaticContext env, Executable exec) throws XPathException Static method to make a Pattern by parsing a String.- Parameters:
pattern- The pattern text as a Stringenv- An object defining the compile-time context for the expressionexec- The executable containing this pattern- Returns:
- The pattern object
- Throws:
XPathException
-
getExecutable
Get the executable containing this pattern- Specified by:
getExecutablein interfaceContainer- Returns:
- the executable
-
setExecutable
Set the executable containing this pattern- Parameters:
executable- the executable
-
getLocationProvider
Get the LocationProvider allowing location identifiers to be resolved.- Specified by:
getLocationProviderin interfaceContainer- Returns:
- the location provider
-
setOriginalText
Set the original text of the pattern for use in diagnostics- Parameters:
text- the original text of the pattern
-
simplify
Simplify the pattern by applying any context-independent optimisations. Default implementation does nothing.- Parameters:
visitor- the expression visitor- Returns:
- the optimised Pattern
- Throws:
XPathException
-
analyze
Type-check the pattern. Default implementation does nothing. This is only needed for patterns that contain variable references or function calls.- Parameters:
visitor- the expression visitorcontextItemType- the type of the context item, if known, at the point where the pattern is defined- Returns:
- the optimised Pattern
- Throws:
XPathException
-
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.- Returns:
- the dependencies, as a bit-significant mask
-
iterateSubExpressions
Iterate over the subexpressions within this pattern- Returns:
- an iterator over the subexpressions. Default implementation returns an empty sequence
-
allocateSlots
Allocate slots to any variables used within the pattern- Parameters:
env- the static context in the XSLT stylesheetslotManager- 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
-
promote
Offer promotion for subexpressions within this pattern. The offer will be accepted if the subexpression is not dependent on the factors (e.g. the context item) identified in the PromotionOffer. By default the offer is not accepted - this is appropriate in the case of simple expressions such as constant values and variable references where promotion would give no performance advantage. This method is always called at compile time.Unlike the corresponding method on
Expression, this method does not return anything: it can make internal changes to the pattern, but cannot return a different pattern. Only certain kinds of promotion are applicable within a pattern: specifically, promotions affecting local variable references within the pattern.- Parameters:
offer- details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression- Throws:
XPathException- if any error is detected
-
setSystemId
Set the system ID where the pattern occurred- Parameters:
systemId- the URI of the module containing the pattern
-
setLineNumber
public void setLineNumber(int lineNumber) Set the line number where the pattern occurred- Parameters:
lineNumber- the line number of the pattern in the source module
-
matches
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- Parameters:
node- 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
-
internalMatches
Determine whether this Pattern matches the given Node. This is an internal interface used for matching sub-patterns; it does not alter the value of current(). The default implementation is identical to matches().- Parameters:
node- 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
-
selectNodes
Select nodes in a document using this PatternFinder.- Specified by:
selectNodesin interfacePatternFinder- 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
-
makeSearchExpression
Make an expression whose effect is to select all the nodes that match this pattern in a given document. This expression takes the root of the tree (always a document node) as the context node; it takes into account all the constraints expressed by the pattern including the parent and ancestor nodes and the filters -
getNodeKind
public int getNodeKind()Determine the types of nodes to which this pattern applies. Used for optimisation. For patterns that match nodes of several types, return Type.NODE- Returns:
- the type of node matched by this pattern. e.g. Type.ELEMENT or Type.TEXT
-
getFingerprint
public int getFingerprint()Determine the name fingerprint of nodes to which this pattern applies. Used for optimisation.- Returns:
- A fingerprint that the nodes must match, or -1 if it can match multiple fingerprints
-
getNodeTest
Get a NodeTest that all the nodes matching this pattern must satisfy- Returns:
- a NodeTest, as specific as possible, which all the matching nodes satisfy
-
getDefaultPriority
public double getDefaultPriority()Determine the default priority to use if this pattern appears as a match pattern for a template with no explicit priority attribute.- Returns:
- the default priority for the pattern
-
getSystemId
Get the system id of the entity in which the pattern occurred- Specified by:
getSystemIdin interfaceSourceLocator
-
getLineNumber
public int getLineNumber()Get the line number on which the pattern was defined- Specified by:
getLineNumberin interfaceSourceLocator
-
getColumnNumber
public int getColumnNumber()Get the column number (always -1)- Specified by:
getColumnNumberin interfaceSourceLocator
-
getPublicId
Get the public ID (always null)- Specified by:
getPublicIdin interfaceSourceLocator
-
toString
Get the original pattern text -
getHostLanguage
public int getHostLanguage()Get the host language (XSLT, XQuery, XPath) used to implement the code in this container- Specified by:
getHostLanguagein interfaceContainer- Returns:
- typically
Configuration.XSLTorConfiguration.XQUERY
-
replaceSubExpression
Description copied from interface:ContainerReplace one subexpression by a replacement subexpression- Specified by:
replaceSubExpressionin interfaceContainer- Parameters:
original- the original subexpressionreplacement- the replacement subexpression- Returns:
- true if the original subexpression was found
-