com.caucho.xpath.pattern
Class AbstractPattern

java.lang.Object
  extended by com.caucho.xpath.pattern.AbstractPattern
Direct Known Subclasses:
CurrentPattern, FilterPattern, FromAncestors, FromAny, FromAttributes, FromChildren, FromContext, FromDescendants, FromExpr, FromNamespace, FromNext, FromNextSibling, FromParent, FromPrevious, FromPreviousSibling, FromRoot, FromSelf, NamespacePattern, NodePattern, NodeTypePattern, NSNamePattern, UnionPattern

public abstract class AbstractPattern
extends java.lang.Object

A node selection pattern. AbstractPatterns represent compiled XPath node selectors. They can be used to find nodes, select nodes, and test if a node matches a pattern.

There are two types of patterns: select patterns and match patterns.

Select patterns match a node relative to another node. find and select use select patterns.

Match patterns match a node in isolation. isMatch uses match patterns.


Field Summary
protected  AbstractPattern _child
           
protected  AbstractPattern _parent
           
protected static java.util.logging.Logger log
           
static java.lang.String XMLNS
           
 
Method Summary
 AbstractPattern copyAxis()
          Returns the owning axis for the pattern.
 AbstractPattern copyPosition()
          Returns the position matching pattern.
 int count(org.w3c.dom.Node node, Env env, AbstractPattern pattern)
          Returns the number of nodes in its context for a match pattern.
 NodeIterator createNodeIterator(org.w3c.dom.Node node, ExprEnvironment env, AbstractPattern pattern)
          Creates a new node iterator.
 org.w3c.dom.Node findAny(org.w3c.dom.Node node, ExprEnvironment env)
          Find any node matching the pattern.
 org.w3c.dom.Node firstNode(org.w3c.dom.Node node, ExprEnvironment env)
          Returns the first node in the selection order.
 java.lang.String getNodeName()
          Returns the name of the matching node or '*' if many nodes match.
 AbstractPattern getParent()
          Returns the parent pattern.
protected  java.lang.String getPrefix()
          For string conversion, returns the string prefix corresponding to the parents.
 double getPriority()
          Returns the pattern's default priority as defined by the XSLT draft.
 boolean isAscending()
          Return true if the iterator is in document-order.
 boolean isStrictlyAscending()
          Returns true if the pattern is strictly ascending.
 boolean isUnique()
          Returns true if the pattern's iterator returns unique nodes.
 org.w3c.dom.Node lastNode(org.w3c.dom.Node node)
          Returns the last node in the selection order.
abstract  boolean match(org.w3c.dom.Node node, ExprEnvironment env)
          The core match function test if the pattern matches the node.
 org.w3c.dom.Node nextNode(org.w3c.dom.Node node, org.w3c.dom.Node last)
          Returns the next node in the selection order.
 int position(org.w3c.dom.Node node, Env env, AbstractPattern pattern)
          Returns the position of the node in its context for a match pattern.
 NodeIterator select(org.w3c.dom.Node node, ExprEnvironment env)
          Returns an iterator selecting nodes in document order.
 NodeIterator selectUnique(org.w3c.dom.Node node, ExprEnvironment env)
          Returns an iterator selecting unique nodes.
 java.lang.String toPatternString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final java.util.logging.Logger log

XMLNS

public static final java.lang.String XMLNS
See Also:
Constant Field Values

_parent

protected AbstractPattern _parent

_child

protected AbstractPattern _child
Method Detail

getParent

public AbstractPattern getParent()
Returns the parent pattern.


getPriority

public double getPriority()
Returns the pattern's default priority as defined by the XSLT draft.


getNodeName

public java.lang.String getNodeName()
Returns the name of the matching node or '*' if many nodes match.

The Xsl package uses this to speed template matching.


select

public NodeIterator select(org.w3c.dom.Node node,
                           ExprEnvironment env)
                    throws XPathException
Returns an iterator selecting nodes in document order.

Parameters:
node - the starting node.
env - the variable environment.
Returns:
an iterator selecting nodes in document order.
Throws:
XPathException

selectUnique

public NodeIterator selectUnique(org.w3c.dom.Node node,
                                 ExprEnvironment env)
                          throws XPathException
Returns an iterator selecting unique nodes. The nodes are not necessarily in document order.

Parameters:
node - the starting node.
env - the variable environment.
context - the context node.
Returns:
an iterator selecting unique nodes.
Throws:
XPathException

findAny

public org.w3c.dom.Node findAny(org.w3c.dom.Node node,
                                ExprEnvironment env)
                         throws XPathException
Find any node matching the pattern.

Parameters:
node - the current node
env - the xpath environment
Returns:
one of the matching nodes
Throws:
XPathException

isStrictlyAscending

public boolean isStrictlyAscending()
Returns true if the pattern is strictly ascending.


isUnique

public boolean isUnique()
Returns true if the pattern's iterator returns unique nodes.


createNodeIterator

public NodeIterator createNodeIterator(org.w3c.dom.Node node,
                                       ExprEnvironment env,
                                       AbstractPattern pattern)
                                throws XPathException
Creates a new node iterator.

Parameters:
node - the starting node
env - the variable environment
pattern - the level pattern
Returns:
the node iterator
Throws:
XPathException

firstNode

public org.w3c.dom.Node firstNode(org.w3c.dom.Node node,
                                  ExprEnvironment env)
                           throws XPathException
Returns the first node in the selection order.

Parameters:
node - the current node
variable - environment
Returns:
the first node
Throws:
XPathException

lastNode

public org.w3c.dom.Node lastNode(org.w3c.dom.Node node)
Returns the last node in the selection order.

Parameters:
node - the current node
Returns:
the last node

nextNode

public org.w3c.dom.Node nextNode(org.w3c.dom.Node node,
                                 org.w3c.dom.Node last)
                          throws XPathException
Returns the next node in the selection order.

Parameters:
node - the current node
last - the last node
Returns:
the next node
Throws:
XPathException

match

public abstract boolean match(org.w3c.dom.Node node,
                              ExprEnvironment env)
                       throws XPathException
The core match function test if the pattern matches the node.

Parameters:
node - the node to test
env - the variable environment.
Returns:
true if the node matches the pattern.
Throws:
XPathException

isAscending

public boolean isAscending()
Return true if the iterator is in document-order.


position

public int position(org.w3c.dom.Node node,
                    Env env,
                    AbstractPattern pattern)
             throws XPathException
Returns the position of the node in its context for a match pattern.

Parameters:
node - the current node
env - the variable environment
pattern - the position pattern
Returns:
the node's position.
Throws:
XPathException

count

public int count(org.w3c.dom.Node node,
                 Env env,
                 AbstractPattern pattern)
          throws XPathException
Returns the number of nodes in its context for a match pattern.

Parameters:
node - the current node
env - the variable environment
pattern - the position pattern
Returns:
the count of nodes in the match selection
Throws:
XPathException

copyAxis

public AbstractPattern copyAxis()
Returns the owning axis for the pattern.


copyPosition

public AbstractPattern copyPosition()
Returns the position matching pattern.


getPrefix

protected java.lang.String getPrefix()
For string conversion, returns the string prefix corresponding to the parents.


toPatternString

public java.lang.String toPatternString()