net.sf.saxon.pattern
Class Pattern

java.lang.Object
  |
  +--net.sf.saxon.pattern.Pattern
All Implemented Interfaces:
Container, java.io.Serializable, javax.xml.transform.SourceLocator
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
Pattern()
           
 
Method Summary
 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.
 Executable getExecutable()
          Get the Executable (representing a complete stylesheet or query) of which this Container forms part
 int getFingerprint()
          Determine the name fingerprint of nodes to which this pattern applies.
 int getLineNumber()
          Get the line number on which the pattern was defined
 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 satisfy
 java.lang.String getPublicId()
          Get the public ID (always null)
 java.lang.String getSystemId()
          Get the system id of the entity in which the pattern occurred
protected  boolean internalMatches(NodeInfo node, XPathContext context)
          Determine whether this Pattern matches the given Node.
static 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 setExecutable(Executable executable)
           
 void setLineNumber(int lineNumber)
          Set the line number where the pattern occurred
 void setOriginalText(java.lang.String text)
          Set the original text of the pattern for use in diagnostics
 void setSystemId(java.lang.String systemId)
          Set the system ID where the pattern occurred
 Pattern simplify(StaticContext env)
          Simplify the pattern by applying any context-independent optimisations.
 java.lang.String toString()
          Get the original pattern text
 Pattern typeCheck(StaticContext env, ItemType contextItemType)
          Type-check the pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pattern

public Pattern()
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 String
env - An object defining the compile-time context for the expression
Returns:
The pattern object
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 interface Container

setExecutable

public void setExecutable(Executable executable)

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
XPathException

typeCheck

public Pattern typeCheck(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
XPathException

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 Pattern
context - 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
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 Pattern
context - 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
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 interface javax.xml.transform.SourceLocator

getLineNumber

public int getLineNumber()
Get the line number on which the pattern was defined

Specified by:
getLineNumber in interface javax.xml.transform.SourceLocator

getColumnNumber

public int getColumnNumber()
Get the column number (always -1)

Specified by:
getColumnNumber in interface javax.xml.transform.SourceLocator

getPublicId

public java.lang.String getPublicId()
Get the public ID (always null)

Specified by:
getPublicId in interface javax.xml.transform.SourceLocator

toString

public java.lang.String toString()
Get the original pattern text

Overrides:
toString in class java.lang.Object