org.apache.xpath.patterns
Class StepPattern

java.lang.Object
  |
  +--org.apache.xpath.Expression
        |
        +--org.apache.xpath.patterns.NodeTest
              |
              +--org.apache.xpath.patterns.StepPattern
Direct Known Subclasses:
AncestorStepPattern, FunctionPattern

public class StepPattern
extends NodeTest
implements SubContextList

**For advanced use only** This class represents a single pattern match step.

See Also:
Serialized Form

Fields inherited from class org.apache.xpath.patterns.NodeTest
SCORE_NODETEST, SCORE_NONE, SCORE_NSWILD, SCORE_OTHER, SCORE_QNAME, SHOW_BYFUNCTION, SHOW_NAMESPACE, SUPPORTS_PRE_STRIPPING, WILD
 
Constructor Summary
StepPattern(int whatToShow)
          Construct a StepPattern that doesn't test for node names.
StepPattern(int whatToShow, java.lang.String namespace, java.lang.String name)
          Construct a StepPattern that tests for namespaces and node names.
 
Method Summary
 void calcTargetString()
          Calculate the local name or psuedo name of the node that this pattern will test, for hash table lookup optimization.
 boolean canTraverseOutsideSubtree()
          Tell if this expression or it's subexpressions can traverse outside the current subtree.
 XObject execute(XPathContext xctxt)
          Test the current node to see if it matches the given node test, and if it does, and there is a relative path pattern, execute that to see if it matches also.
 XObject executeRelativePathPattern(XPathContext xctxt)
          Execute the match pattern step relative to another step.
 XObject executeStep(XPathContext xctxt)
          Execute this pattern step, including predicates.
 int getLastPos(XPathContext xctxt)
          Get the count of the nodes that match the test, which is the proximity position of the last node that can pass this test in the sub context selection.
 double getMatchScore(XPathContext xctxt, Node context)
          Get the match score of the given node.
 Expression getPredicate(int i)
          Get a predicate expression.
 int getPredicateCount()
          Get the number of predicates for this match pattern step.
 int getProximityPosition(XPathContext xctxt)
          Get the proximity position index of the current node based on this node test.
 java.lang.String getTargetString()
          Get the local name or psuedo name of the node that this pattern will test, for hash table lookup optimization.
 void setPredicates(Expression[] predicates)
          Set the predicates for this match pattern step.
 void setRelativePathPattern(StepPattern expr)
          Set the reference to nodetest and predicate for parent or ancestor.
 
Methods inherited from class org.apache.xpath.patterns.NodeTest
debugWhatToShow, execute, getDefaultScore, getLocalName, getNamespace, getWhatToShow, initNodeTest, initNodeTest
 
Methods inherited from class org.apache.xpath.Expression
assert, error, setSourceLocator, warn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StepPattern

public StepPattern(int whatToShow,
                   java.lang.String namespace,
                   java.lang.String name)
Construct a StepPattern that tests for namespaces and node names.
Parameters:
whatToShow - Bit set defined mainly by NodeFilter.
namespace - The namespace to be tested.
name - The local name to be tested.

StepPattern

public StepPattern(int whatToShow)
Construct a StepPattern that doesn't test for node names.
Parameters:
whatToShow - Bit set defined mainly by NodeFilter.
Method Detail

calcTargetString

public void calcTargetString()
Calculate the local name or psuedo name of the node that this pattern will test, for hash table lookup optimization.
See Also:
PsuedoNames

getTargetString

public java.lang.String getTargetString()
Get the local name or psuedo name of the node that this pattern will test, for hash table lookup optimization.
Returns:
local name or psuedo name of the node.
See Also:
PsuedoNames

setRelativePathPattern

public void setRelativePathPattern(StepPattern expr)
Set the reference to nodetest and predicate for parent or ancestor.
Parameters:
expr - The relative pattern expression.

canTraverseOutsideSubtree

public boolean canTraverseOutsideSubtree()
Tell if this expression or it's subexpressions can traverse outside the current subtree. NOTE: Ancestors tests with predicates are problematic, and will require special treatment.
Returns:
true if traversal outside the context node's subtree can occur.
Overrides:
canTraverseOutsideSubtree in class Expression

getPredicate

public Expression getPredicate(int i)
Get a predicate expression.
Parameters:
i - The index of the predicate.
Returns:
A predicate expression.

getPredicateCount

public final int getPredicateCount()
Get the number of predicates for this match pattern step.
Returns:
the number of predicates for this match pattern step.

setPredicates

public void setPredicates(Expression[] predicates)
Set the predicates for this match pattern step.
Parameters:
predicates - An array of expressions that define predicates for this step.

executeStep

public XObject executeStep(XPathContext xctxt)
                    throws TransformerException
Execute this pattern step, including predicates.
Parameters:
xctxt - XPath runtime context.
Returns:
NodeTest.SCORE_NODETEST, NodeTest.SCORE_NONE, NodeTest.SCORE_NSWILD, NodeTest.SCORE_QNAME, or NodeTest.SCORE_OTHER.
Throws:
TransformerException -  

getProximityPosition

public int getProximityPosition(XPathContext xctxt)
Get the proximity position index of the current node based on this node test.
Specified by:
getProximityPosition in interface SubContextList
Parameters:
xctxt - XPath runtime context.
Returns:
the proximity position index of the current node based on the node test.

getLastPos

public int getLastPos(XPathContext xctxt)
Get the count of the nodes that match the test, which is the proximity position of the last node that can pass this test in the sub context selection. In XSLT 1-based indexing, this count is the index of the last node.
Specified by:
getLastPos in interface SubContextList
Parameters:
xctxt - XPath runtime context.
Returns:
the count of the nodes that match the test.

executeRelativePathPattern

public XObject executeRelativePathPattern(XPathContext xctxt)
                                   throws TransformerException
Execute the match pattern step relative to another step.
Parameters:
xctxt - The XPath runtime context.
Returns:
NodeTest.SCORE_NODETEST, NodeTest.SCORE_NONE, NodeTest.SCORE_NSWILD, NodeTest.SCORE_QNAME, or NodeTest.SCORE_OTHER.
Throws:
TransformerException -  

execute

public XObject execute(XPathContext xctxt)
                throws TransformerException
Test the current node to see if it matches the given node test, and if it does, and there is a relative path pattern, execute that to see if it matches also.
Parameters:
xctxt - XPath runtime context.
Returns:
NodeTest.SCORE_NODETEST, NodeTest.SCORE_NONE, NodeTest.SCORE_NSWILD, NodeTest.SCORE_QNAME, or NodeTest.SCORE_OTHER.
Throws:
TransformerException -  
Overrides:
execute in class NodeTest

getMatchScore

public double getMatchScore(XPathContext xctxt,
                            Node context)
                     throws TransformerException
Get the match score of the given node.
Parameters:
xctxt - The XPath runtime context.
context - The node to be tested.
Returns:
NodeTest.SCORE_NODETEST, NodeTest.SCORE_NONE, NodeTest.SCORE_NSWILD, NodeTest.SCORE_QNAME, or NodeTest.SCORE_OTHER.
Throws:
TransformerException -  


Copyright � 2000 Apache XML Project. All Rights Reserved.