Package org.apache.xpath.patterns
Class NodeTest
java.lang.Object
org.apache.xpath.Expression
org.apache.xpath.patterns.NodeTest
- All Implemented Interfaces:
Serializable,SourceLocator,ExpressionNode,XPathVisitable
- Direct Known Subclasses:
PredicatedNodeTest,StepPattern
public class NodeTest extends Expression
This is the basic node test class for both match patterns and location path
steps.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected Stringm_nameThe local name to be tested for.protected intm_whatToShowThis attribute determines which node types are accepted.static XNumberSCORE_NODETESTThe match score if the pattern consists of just a NodeTest.static XNumberSCORE_NONEThe match score if no match is made.static XNumberSCORE_NSWILDThe match score if the pattern pattern has the form NCName:*.static XNumberSCORE_OTHERThe match score if the pattern consists of something other than just a NodeTest or just a qname.static XNumberSCORE_QNAMEThe match score if the pattern has the form of a QName optionally preceded by an @ character.static intSHOW_BYFUNCTIONSpecial bitmap for match patterns starting with a function.static StringSUPPORTS_PRE_STRIPPINGThe URL to pass to the Node#supports method, to see if the DOM has already been stripped of whitespace nodes.static StringWILDThe namespace or local name for node tests with a wildcard. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description protected voidcalcScore()Static calc of match score.voidcallVisitors(ExpressionOwner owner, XPathVisitor visitor)This will traverse the heararchy, calling the visitor for each member.static voiddebugWhatToShow(int whatToShow)Do a diagnostics dump of a whatToShow bit set.booleandeepEquals(Expression expr)Compare this object with another object and see if they are equal, include the sub heararchy.XObjectexecute(XPathContext xctxt)Test the current node to see if it matches the given node test.XObjectexecute(XPathContext xctxt, int context)Tell what the test score is for the given node.XObjectexecute(XPathContext xctxt, int context, DTM dtm, int expType)Tell what the test score is for the given node.voidfixupVariables(Vector vars, int globalsSize)Node tests by themselves do not need to fix up variables.doublegetDefaultScore()Get the score that this test will return if a test succeeds.StringgetLocalName()Return the local name to be tested.StringgetNamespace()Return the namespace to be tested.static intgetNodeTypeTest(int whatToShow)Tell what node type to test, if not DTMFilter.SHOW_ALL.XNumbergetStaticScore()Get the static score for this node test.intgetWhatToShow()This attribute determines which node types are accepted.voidinitNodeTest(int whatToShow)Initialize this node test by setting the whatToShow property, and calculating the score that this test will return if a test succeeds.voidinitNodeTest(int whatToShow, String namespace, String name)Initialize this node test by setting the whatToShow property and the namespace and local name, and calculating the score that this test will return if a test succeeds.voidsetLocalName(String name)Set the local name to be tested.voidsetNamespace(String ns)Set the namespace to be tested.voidsetStaticScore(XNumber score)Set the static score for this node test.voidsetWhatToShow(int what)This attribute determines which node types are accepted.Methods inherited from class org.apache.xpath.Expression
asIterator, asIteratorRaw, asNode, assertion, bool, canTraverseOutsideSubtree, error, execute, executeCharsToContentHandler, exprAddChild, exprGetChild, exprGetNumChildren, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isNodesetExpr, isSameClass, isStableNumber, num, warn, xstr
-
Field Details
-
WILD
The namespace or local name for node tests with a wildcard. -
SUPPORTS_PRE_STRIPPING
The URL to pass to the Node#supports method, to see if the DOM has already been stripped of whitespace nodes.- See Also:
- Constant Field Values
-
m_whatToShow
protected int m_whatToShowThis attribute determines which node types are accepted. -
SHOW_BYFUNCTION
public static final int SHOW_BYFUNCTIONSpecial bitmap for match patterns starting with a function. Make sure this does not conflict withNodeFilter.- See Also:
- Constant Field Values
-
m_name
The local name to be tested for. -
SCORE_NODETEST
The match score if the pattern consists of just a NodeTest. -
SCORE_NSWILD
The match score if the pattern pattern has the form NCName:*. -
SCORE_QNAME
The match score if the pattern has the form of a QName optionally preceded by an @ character. -
SCORE_OTHER
The match score if the pattern consists of something other than just a NodeTest or just a qname. -
SCORE_NONE
The match score if no match is made.
-
-
Constructor Details
-
NodeTest
Construct an NodeTest 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.
-
NodeTest
public NodeTest(int whatToShow)Construct an NodeTest that doesn't test for node names.- Parameters:
whatToShow- Bit set defined mainly byNodeFilter.
-
NodeTest
public NodeTest()Null argument constructor.
-
-
Method Details
-
getWhatToShow
public int getWhatToShow()This attribute determines which node types are accepted. These constants are defined in theNodeFilterinterface.- Returns:
- bitset mainly defined in
NodeFilter.
-
setWhatToShow
public void setWhatToShow(int what)This attribute determines which node types are accepted. These constants are defined in theNodeFilterinterface.- Parameters:
what- bitset mainly defined inNodeFilter.
-
getNamespace
Return the namespace to be tested.- Returns:
- The namespace to be tested for, or
WILD, or null.
-
setNamespace
Set the namespace to be tested.- Parameters:
ns- The namespace to be tested for, orWILD, or null.
-
getLocalName
Return the local name to be tested.- Returns:
- the local name to be tested, or
WILD, or an empty string.
-
setLocalName
Set the local name to be tested.- Parameters:
name- the local name to be tested, orWILD, or an empty string.
-
deepEquals
Description copied from class:ExpressionCompare this object with another object and see if they are equal, include the sub heararchy.- Specified by:
deepEqualsin classExpression- 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)
-
initNodeTest
public void initNodeTest(int whatToShow)Initialize this node test by setting the whatToShow property, and calculating the score that this test will return if a test succeeds.- Parameters:
whatToShow- Bit set defined mainly byNodeFilter.
-
initNodeTest
Initialize this node test by setting the whatToShow property and the namespace and local name, and calculating the score that this test will return if a test succeeds.- Parameters:
whatToShow- Bit set defined mainly byNodeFilter.namespace- The namespace to be tested.name- The local name to be tested.
-
getStaticScore
Get the static score for this node test.- Returns:
- Should be one of the SCORE_XXX constants.
-
setStaticScore
Set the static score for this node test.- Parameters:
score- Should be one of the SCORE_XXX constants.
-
calcScore
protected void calcScore()Static calc of match score. -
getDefaultScore
public double getDefaultScore()Get the score that this test will return if a test succeeds.- Returns:
- the score that this test will return if a test succeeds.
-
getNodeTypeTest
public static int getNodeTypeTest(int whatToShow)Tell what node type to test, if not DTMFilter.SHOW_ALL.- Parameters:
whatToShow- Bit set defined mainly byDTMFilter.- Returns:
- the node type for the whatToShow. Since whatToShow can specify multiple types, it will return the first bit tested that is on, so the caller of this function should take care that this is the function they really want to call. If none of the known bits are set, this function will return zero.
-
debugWhatToShow
public static void debugWhatToShow(int whatToShow)Do a diagnostics dump of a whatToShow bit set.- Parameters:
whatToShow- Bit set defined mainly byDTMFilter.
-
execute
Tell what the test score is for the given node.- Overrides:
executein classExpression- Parameters:
xctxt- XPath runtime context.context- The node being tested.- Returns:
SCORE_NODETEST,SCORE_NONE,SCORE_NSWILD,SCORE_QNAME, orSCORE_OTHER.- Throws:
TransformerException
-
execute
public XObject execute(XPathContext xctxt, int context, DTM dtm, int expType) throws TransformerExceptionTell what the test score is for the given node.- Overrides:
executein classExpression- Parameters:
xctxt- XPath runtime context.context- The node being tested.dtm- The DTM of the current node.expType- The expanded type ID of the current node.- Returns:
SCORE_NODETEST,SCORE_NONE,SCORE_NSWILD,SCORE_QNAME, orSCORE_OTHER.- Throws:
TransformerException
-
execute
Test the current node to see if it matches the given node test.- Specified by:
executein classExpression- Parameters:
xctxt- XPath runtime context.- Returns:
SCORE_NODETEST,SCORE_NONE,SCORE_NSWILD,SCORE_QNAME, orSCORE_OTHER.- Throws:
TransformerException
-
fixupVariables
Node tests by themselves do not need to fix up variables.- Specified by:
fixupVariablesin classExpression- 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). NEEDSDOC @param globalsSize
-
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.- 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)
-