Package org.loboevolution.apache.xpath
Class Expression
java.lang.Object
org.loboevolution.apache.xpath.Expression
- All Implemented Interfaces:
SourceLocator,ExpressionNode,XPathVisitable
- Direct Known Subclasses:
Function,NodeTest,Operation,UnaryOperation,UnionPattern,XObject
This abstract class serves as the base for all expression objects. An Expression can be executed
to return a
XObject, normally has a location
within a document or DOM, can send error and warning events, and normally do not hold state and
are meant to be immutable once construction has completed. An exception to the immutibility rule
is iterators and walkers, which must be cloned in order to be used -- the original must still be
immutable.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasIterator(XPathContext xctxt, int contextNode) Given an select expression and a context, evaluate the XPath and return the resulting iterator.intasNode(XPathContext xctxt) Return the first node out of the nodeset, if this expression is a nodeset expression.voidTell the user of an assertion error, and probably throw an exception.booleanbool(XPathContext xctxt) Evaluate expression to a boolean.booleanTell if this expression or it's subexpressions can traverse outside the current subtree.abstract booleandeepEquals(Expression expr) Compare this object with another object and see if they are equal, include the sub heararchy.voiderror(XPathContext xctxt, String msg, Object[] args) Tell the user of an error, and probably throw an exception.abstract XObjectexecute(XPathContext xctxt) Execute an expression in the XPath runtime context, and return the result of the expression.execute(XPathContext xctxt, boolean destructiveOK) Execute an expression in the XPath runtime context, and return the result of the expression, but tell that a "safe" object doesn't have to be returned.execute(XPathContext xctxt, int currentNode) Execute an expression in the XPath runtime context, and return the result of the expression.execute(XPathContext xctxt, int currentNode, DTM dtm, int expType) Execute an expression in the XPath runtime context, and return the result of the expression.voidThis pair of methods are used to inform the node of its parent.intGet the first non-Expression parent of this node.intprotected final booleanisSameClass(Expression expr) This is a utility method to tell if the passed in class is the same class as this.booleanTell if this expression returns a stable number that will not change during iterations within the expression.doublenum(XPathContext xctxt) Evaluate expression to a number.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.loboevolution.apache.xpath.XPathVisitable
callVisitors
-
Constructor Details
-
Expression
public Expression()
-
-
Method Details
-
canTraverseOutsideSubtree
public boolean canTraverseOutsideSubtree()Tell if this expression or it's subexpressions can traverse outside the current subtree.- Returns:
- true if traversal outside the context node's subtree can occur.
-
execute
Execute an expression in the XPath runtime context, and return the result of the expression.- Parameters:
xctxt- The XPath runtime context.currentNode- The currentNode.- Returns:
- The result of the expression in the form of a
XObject. - Throws:
TransformerException- if a runtime exception occurs.
-
execute
public XObject execute(XPathContext xctxt, int currentNode, DTM dtm, int expType) throws TransformerException Execute an expression in the XPath runtime context, and return the result of the expression.- 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.
-
execute
Execute an expression in the XPath runtime context, and return the result of the expression.- Parameters:
xctxt- The XPath runtime context.- Returns:
- The result of the expression in the form of a
XObject. - Throws:
TransformerException- if a runtime exception occurs.
-
execute
Execute an expression in the XPath runtime context, and return the result of the expression, but tell that a "safe" object doesn't have to be returned. The default implementation just calls execute(xctxt).- Parameters:
xctxt- The XPath runtime context.destructiveOK- true if a "safe" object doesn't need to be returned.- Returns:
- The result of the expression in the form of a
XObject. - Throws:
TransformerException- if a runtime exception occurs.
-
num
Evaluate expression to a number.- Parameters:
xctxt- The XPath runtime context.- Returns:
- The expression evaluated as a double.
- Throws:
TransformerException- if any
-
bool
Evaluate expression to a boolean.- Parameters:
xctxt- The XPath runtime context.- Returns:
- false
- Throws:
TransformerException- if any
-
asNode
Return the first node out of the nodeset, if this expression is a nodeset expression.- Parameters:
xctxt- The XPath runtime context.- Returns:
- the first node out of the nodeset, or DTM.NULL.
- Throws:
TransformerException- if any
-
asIterator
Given an select expression and a context, evaluate the XPath and return the resulting iterator.- Parameters:
xctxt- The execution context.contextNode- The node that "." expresses.- Returns:
- A valid DTMIterator.
- Throws:
TransformerException- thrown if the active ProblemListener decides the error condition is severe enough to halt processing.TransformerException- if any
-
isStableNumber
public boolean isStableNumber()Tell if this expression returns a stable number that will not change during iterations within the expression. This is used to determine if a proximity position predicate can indicate that no more searching has to occur.- Returns:
- true if the expression represents a stable number.
-
deepEquals
Compare this object with another object and see if they are equal, include the sub heararchy.- 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.
-
isSameClass
This is a utility method to tell if the passed in class is the same class as this. It is to be used by the deepEquals method. I'm bottlenecking it here because I'm not totally confident that comparing the class objects is the best way to do this.- Returns:
- true of the passed in class is the exact same class as this class.
-
assertion
Tell the user of an assertion error, and probably throw an exception.- Parameters:
b- If false, a runtime exception will be thrown.msg- The assertion message, which should be informative.- Throws:
RuntimeException- if the b argument is false.
-
error
Tell the user of an error, and probably throw an exception.- Parameters:
xctxt- The XPath runtime context.msg- An error msgkey that corresponds to one of the constants found inXPATHErrorResources, which is a key for a format string.args- An array of arguments represented in the format string, which may be null.- Throws:
TransformerException- if the current ErrorListoner determines to throw an exception.TransformerException- if any
-
getExpressionOwner
Get the first non-Expression parent of this node.- Returns:
- null or first ancestor that is not an Expression.
-
exprSetParent
This pair of methods are used to inform the node of its parent.- Specified by:
exprSetParentin interfaceExpressionNode
-
exprGetParent
- Specified by:
exprGetParentin interfaceExpressionNode
-
getPublicId
- Specified by:
getPublicIdin interfaceSourceLocator
-
getSystemId
- Specified by:
getSystemIdin interfaceSourceLocator
-
getLineNumber
public int getLineNumber()- Specified by:
getLineNumberin interfaceSourceLocator
-
getColumnNumber
public int getColumnNumber()- Specified by:
getColumnNumberin interfaceSourceLocator
-