Package net.sf.saxon.pattern
Class Pattern
- java.lang.Object
-
- net.sf.saxon.pattern.Pattern
-
- All Implemented Interfaces:
java.io.Serializable
,javax.xml.transform.SourceLocator
,Container
- Direct Known Subclasses:
IDPattern
,KeyPattern
,LocationPathPattern
,NodeTestPattern
,UnionPattern
public abstract class Pattern extends java.lang.Object implements java.io.Serializable, Container
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().- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Pattern()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Pattern
analyze(StaticContext env, ItemType contextItemType)
Type-check the pattern.int
getColumnNumber()
Get the column number (always -1)double
getDefaultPriority()
Determine the default priority to use if this pattern appears as a match pattern for a template with no explicit priority attribute.int
getDependencies()
Get the dependencies of the pattern.Executable
getExecutable()
Get the Executable (representing a complete stylesheet or query) of which this Container forms partint
getFingerprint()
Determine the name fingerprint of nodes to which this pattern applies.int
getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this containerint
getLineNumber()
Get the line number on which the pattern was definedLocationProvider
getLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved.int
getNodeKind()
Determine the types of nodes to which this pattern applies.abstract NodeTest
getNodeTest()
Get a NodeTest that all the nodes matching this pattern must satisfyjava.lang.String
getPublicId()
Get the public ID (always null)java.lang.String
getSystemId()
Get the system id of the entity in which the pattern occurredprotected boolean
internalMatches(NodeInfo node, XPathContext context)
Determine whether this Pattern matches the given Node.java.util.Iterator
iterateSubExpressions()
Iterate over the subexpressions within this patternstatic Pattern
make(java.lang.String pattern, StaticContext env, Executable exec)
Static method to make a Pattern by parsing a String.abstract boolean
matches(NodeInfo node, XPathContext context)
Determine whether this Pattern matches the given Node.void
promote(PromotionOffer offer)
Offer promotion for subexpressions within this pattern.boolean
replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpressionvoid
setExecutable(Executable executable)
void
setLineNumber(int lineNumber)
Set the line number where the pattern occurredvoid
setOriginalText(java.lang.String text)
Set the original text of the pattern for use in diagnosticsvoid
setSystemId(java.lang.String systemId)
Set the system ID where the pattern occurredPattern
simplify(StaticContext env)
Simplify the pattern by applying any context-independent optimisations.java.lang.String
toString()
Get the original pattern text
-
-
-
Method Detail
-
make
public static Pattern make(java.lang.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 expression- Returns:
- The pattern object
- Throws:
XPathException
-
getExecutable
public Executable getExecutable()
Description copied from interface:Container
Get the Executable (representing a complete stylesheet or query) of which this Container forms part- Specified by:
getExecutable
in interfaceContainer
-
setExecutable
public void setExecutable(Executable executable)
-
getLocationProvider
public LocationProvider getLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved.- Specified by:
getLocationProvider
in interfaceContainer
-
setOriginalText
public void setOriginalText(java.lang.String text)
Set the original text of the pattern for use in diagnostics
-
simplify
public Pattern simplify(StaticContext env) throws XPathException
Simplify the pattern by applying any context-independent optimisations. Default implementation does nothing.- Returns:
- the optimised Pattern
- Throws:
XPathException
-
analyze
public Pattern analyze(StaticContext env, ItemType contextItemType) throws XPathException
Type-check the pattern. Default implementation does nothing. This is only needed for patterns that contain variable references or function calls.- 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.
-
iterateSubExpressions
public java.util.Iterator iterateSubExpressions()
Iterate over the subexpressions within this pattern
-
promote
public void promote(PromotionOffer offer) throws XPathException
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
public void setSystemId(java.lang.String systemId)
Set the system ID where the pattern occurred
-
setLineNumber
public void setLineNumber(int lineNumber)
Set the line number where the pattern occurred
-
matches
public abstract boolean matches(NodeInfo node, 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- 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
protected boolean internalMatches(NodeInfo node, XPathContext context) throws XPathException
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
-
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
public abstract NodeTest getNodeTest()
Get a NodeTest that all the nodes matching this pattern must 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.
-
getSystemId
public java.lang.String getSystemId()
Get the system id of the entity in which the pattern occurred- Specified by:
getSystemId
in interfacejavax.xml.transform.SourceLocator
-
getLineNumber
public int getLineNumber()
Get the line number on which the pattern was defined- Specified by:
getLineNumber
in interfacejavax.xml.transform.SourceLocator
-
getColumnNumber
public int getColumnNumber()
Get the column number (always -1)- Specified by:
getColumnNumber
in interfacejavax.xml.transform.SourceLocator
-
getPublicId
public java.lang.String getPublicId()
Get the public ID (always null)- Specified by:
getPublicId
in interfacejavax.xml.transform.SourceLocator
-
toString
public java.lang.String toString()
Get the original pattern text- Overrides:
toString
in classjava.lang.Object
-
getHostLanguage
public int getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container- Specified by:
getHostLanguage
in interfaceContainer
- Returns:
- typically
Configuration.XSLT
orConfiguration.XQUERY
-
replaceSubExpression
public boolean replaceSubExpression(Expression original, Expression replacement)
Description copied from interface:Container
Replace one subexpression by a replacement subexpression- Specified by:
replaceSubExpression
in interfaceContainer
- Parameters:
original
- the original subexpressionreplacement
- the replacement subexpression- Returns:
- true if the original subexpression was found
-
-