Package org.apache.xpath.patterns
Class StepPattern
java.lang.Object
org.apache.xpath.Expression
org.apache.xpath.patterns.NodeTest
org.apache.xpath.patterns.StepPattern
- All Implemented Interfaces:
Serializable,SourceLocator,SubContextList,ExpressionNode,ExpressionOwner,XPathVisitable
- Direct Known Subclasses:
ContextMatchStepPattern,FunctionPattern
public class StepPattern extends NodeTest implements SubContextList, ExpressionOwner
This class represents a single pattern match step.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected intm_axisThe axis for this test.Fields inherited from class org.apache.xpath.patterns.NodeTest
m_name, m_whatToShow, SCORE_NODETEST, SCORE_NONE, SCORE_NSWILD, SCORE_OTHER, SCORE_QNAME, SHOW_BYFUNCTION, SUPPORTS_PRE_STRIPPING, WILD -
Constructor Summary
Constructors Constructor Description StepPattern(int whatToShow, int axis, int axisForPredicate)Construct a StepPattern that doesn't test for node names.StepPattern(int whatToShow, String namespace, String name, int axis, int axisForPredicate)Construct a StepPattern that tests for namespaces and node names. -
Method Summary
Modifier and Type Method Description voidcalcScore()Static calc of match score.voidcalcTargetString()Calculate the local name or psuedo name of the node that this pattern will test, for hash table lookup optimization.protected voidcallSubtreeVisitors(XPathVisitor visitor)Call the visitors on the subtree.voidcallVisitors(ExpressionOwner owner, XPathVisitor visitor)This will traverse the heararchy, calling the visitor for each member.booleancanTraverseOutsideSubtree()Tell if this expression or it's subexpressions can traverse outside the current subtree.booleandeepEquals(Expression expr)Compare this object with another object and see if they are equal, include the sub heararchy.XObjectexecute(XPathContext xctxt)Execute this pattern step, including predicates.XObjectexecute(XPathContext xctxt, int currentNode)Execute this pattern step, including predicates.XObjectexecute(XPathContext xctxt, int currentNode, DTM dtm, int expType)Execute an expression in the XPath runtime context, and return the result of the expression.protected booleanexecutePredicates(XPathContext xctxt, DTM dtm, int currentNode)Execute the predicates on this step to determine if the current node should be filtered or accepted.protected XObjectexecuteRelativePathPattern(XPathContext xctxt, DTM dtm, int currentNode)Execute the match pattern step relative to another step.voidfixupVariables(Vector vars, int globalsSize)This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.intgetAxis()Get the axis that this step follows.ExpressiongetExpression()Get the raw Expression object that this class wraps.intgetLastPos(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.doublegetMatchScore(XPathContext xctxt, int context)Get the match score of the given node.ExpressiongetPredicate(int i)Get a predicate expression.intgetPredicateCount()Get the number of predicates for this match pattern step.Expression[]getPredicates()Set the list of predicate expressions for this pattern step.intgetProximityPosition(XPathContext xctxt)Get the proximity position index of the current node based on this node test.StepPatterngetRelativePathPattern()Get the reference to nodetest and predicate for parent or ancestor.StringgetTargetString()Get the local name or psuedo name of the node that this pattern will test, for hash table lookup optimization.voidsetAxis(int axis)Set the axis that this step should follow.voidsetExpression(Expression exp)Set the raw expression object for this object.voidsetPredicates(Expression[] predicates)Set the predicates for this match pattern step.voidsetRelativePathPattern(StepPattern expr)Set the reference to nodetest and predicate for parent or ancestor.StringtoString()Get the string represenentation of this step for diagnostic purposes.Methods inherited from class org.apache.xpath.patterns.NodeTest
debugWhatToShow, getDefaultScore, getLocalName, getNamespace, getNodeTypeTest, getStaticScore, getWhatToShow, initNodeTest, initNodeTest, setLocalName, setNamespace, setStaticScore, setWhatToShowMethods inherited from class org.apache.xpath.Expression
asIterator, asIteratorRaw, asNode, assertion, bool, error, execute, executeCharsToContentHandler, exprAddChild, exprGetChild, exprGetNumChildren, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isNodesetExpr, isSameClass, isStableNumber, num, warn, xstr
-
Field Details
-
m_axis
protected int m_axisThe axis for this test.
-
-
Constructor Details
-
StepPattern
Construct a StepPattern that tests for namespaces and node names.- Parameters:
whatToShow- Bit set defined mainly byNodeFilter.namespace- The namespace to be tested.name- The local name to be tested.axis- The Axis for this test, one of of Axes.ANCESTORORSELF, etc.axisForPredicate- No longer used.
-
StepPattern
public StepPattern(int whatToShow, int axis, int axisForPredicate)Construct a StepPattern that doesn't test for node names.- Parameters:
whatToShow- Bit set defined mainly byNodeFilter.axis- The Axis for this test, one of of Axes.ANCESTORORSELF, etc.axisForPredicate- No longer used.
-
-
Method Details
-
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
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
-
fixupVariables
This function is used to fixup variables from QNames to stack frame indexes at stylesheet build time.- Overrides:
fixupVariablesin classNodeTest- Parameters:
vars- List of QNames that correspond to variables. This list should be searched backwards for the first qualified name that corresponds to the variable reference qname. The position of the QName in the vector from the start of the vector will be its position in the stack frame (but variables above the globalsTop value will need to be offset to the current stack frame).globalsSize- The number of variables in the global variable area.
-
setRelativePathPattern
Set the reference to nodetest and predicate for parent or ancestor.- Parameters:
expr- The relative pattern expression.
-
getRelativePathPattern
Get the reference to nodetest and predicate for parent or ancestor.- Returns:
- The relative pattern expression.
-
getPredicates
Set the list of predicate expressions for this pattern step.- Returns:
- List of expression objects.
-
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.- Overrides:
canTraverseOutsideSubtreein classExpression- Returns:
- true if traversal outside the context node's subtree can occur.
-
getPredicate
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
Set the predicates for this match pattern step.- Parameters:
predicates- An array of expressions that define predicates for this step.
-
calcScore
public void calcScore()Static calc of match score. -
execute
Execute this pattern step, including predicates.- Overrides:
executein classNodeTest- Parameters:
xctxt- XPath runtime context.currentNode- The current node context.- Returns:
NodeTest.SCORE_NODETEST,NodeTest.SCORE_NONE,NodeTest.SCORE_NSWILD,NodeTest.SCORE_QNAME, orNodeTest.SCORE_OTHER.- Throws:
TransformerException
-
execute
Execute this pattern step, including predicates.- Overrides:
executein classNodeTest- Parameters:
xctxt- XPath runtime context.- Returns:
NodeTest.SCORE_NODETEST,NodeTest.SCORE_NONE,NodeTest.SCORE_NSWILD,NodeTest.SCORE_QNAME, orNodeTest.SCORE_OTHER.- Throws:
TransformerException
-
execute
public XObject execute(XPathContext xctxt, int currentNode, DTM dtm, int expType) throws TransformerExceptionExecute an expression in the XPath runtime context, and return the result of the expression.- Overrides:
executein classNodeTest- Parameters:
xctxt- The XPath runtime context.currentNode- The currentNode.dtm- The DTM of the current node.expType- The expanded type ID of the current node.- Returns:
- The result of the expression in the form of a
XObject. - Throws:
TransformerException- if a runtime exception occurs.
-
getProximityPosition
Get the proximity position index of the current node based on this node test.- Specified by:
getProximityPositionin interfaceSubContextList- Parameters:
xctxt- XPath runtime context.- Returns:
- the proximity position index of the current node based on the node test.
-
getLastPos
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:
getLastPosin interfaceSubContextList- Parameters:
xctxt- XPath runtime context.- Returns:
- the count of the nodes that match the test.
-
executeRelativePathPattern
protected final XObject executeRelativePathPattern(XPathContext xctxt, DTM dtm, int currentNode) throws TransformerExceptionExecute the match pattern step relative to another step.- Parameters:
xctxt- The XPath runtime context.dtm- The DTM of the current node.currentNode- The current node context.- Returns:
NodeTest.SCORE_NODETEST,NodeTest.SCORE_NONE,NodeTest.SCORE_NSWILD,NodeTest.SCORE_QNAME, orNodeTest.SCORE_OTHER.- Throws:
TransformerException
-
executePredicates
protected final boolean executePredicates(XPathContext xctxt, DTM dtm, int currentNode) throws TransformerExceptionExecute the predicates on this step to determine if the current node should be filtered or accepted.- Parameters:
xctxt- The XPath runtime context.dtm- The DTM of the current node.currentNode- The current node context.- Returns:
- true if the node should be accepted, false otherwise.
- Throws:
TransformerException
-
toString
Get the string represenentation of this step for diagnostic purposes. -
getMatchScore
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, orNodeTest.SCORE_OTHER.- Throws:
TransformerException
-
setAxis
public void setAxis(int axis)Set the axis that this step should follow.- Parameters:
axis- The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
-
getAxis
public int getAxis()Get the axis that this step follows.- Returns:
- The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
-
callVisitors
Description copied from interface:XPathVisitableThis will traverse the heararchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.- Specified by:
callVisitorsin interfaceXPathVisitable- Overrides:
callVisitorsin classNodeTest- Parameters:
owner- The owner of the visitor, where that path may be rewritten if needed.visitor- The visitor whose appropriate method will be called.- See Also:
XPathVisitable.callVisitors(ExpressionOwner, XPathVisitor)
-
callSubtreeVisitors
Call the visitors on the subtree. Factored out from callVisitors so it may be called by derived classes. -
getExpression
Description copied from interface:ExpressionOwnerGet the raw Expression object that this class wraps.- Specified by:
getExpressionin interfaceExpressionOwner- Returns:
- the raw Expression object, which should not normally be null.
- See Also:
ExpressionOwner.getExpression()
-
setExpression
Description copied from interface:ExpressionOwnerSet the raw expression object for this object.- Specified by:
setExpressionin interfaceExpressionOwner- Parameters:
exp- the raw Expression object, which should not normally be null.- See Also:
ExpressionOwner.setExpression(Expression)
-
deepEquals
Description copied from class:ExpressionCompare this object with another object and see if they are equal, include the sub heararchy.- Overrides:
deepEqualsin classNodeTest- Parameters:
expr- Another expression object.- Returns:
- true if this objects class and the expr object's class are the same, and the data contained within both objects are considered equal.
- See Also:
Expression.deepEquals(Expression)
-