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

public abstract class Expression extends Object implements ExpressionNode, XPathVisitable
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 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

      public XObject execute(XPathContext xctxt, int currentNode) 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.
      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

      public abstract XObject execute(XPathContext xctxt) throws TransformerException
      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

      public XObject execute(XPathContext xctxt, boolean destructiveOK) throws TransformerException
      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

      public double num(XPathContext xctxt) throws TransformerException
      Evaluate expression to a number.
      Parameters:
      xctxt - The XPath runtime context.
      Returns:
      The expression evaluated as a double.
      Throws:
      TransformerException - if any
    • bool

      public boolean bool(XPathContext xctxt) throws TransformerException
      Evaluate expression to a boolean.
      Parameters:
      xctxt - The XPath runtime context.
      Returns:
      false
      Throws:
      TransformerException - if any
    • asNode

      public int asNode(XPathContext xctxt) throws TransformerException
      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

      public DTMIterator asIterator(XPathContext xctxt, int contextNode) throws TransformerException
      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

      public abstract boolean deepEquals(Expression expr)
      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

      protected final boolean isSameClass(Expression expr)
      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

      public void assertion(boolean b, String msg)
      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

      public void error(XPathContext xctxt, String msg, Object[] args) throws TransformerException
      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 in XPATHErrorResources, 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

      public ExpressionNode getExpressionOwner()
      Get the first non-Expression parent of this node.
      Returns:
      null or first ancestor that is not an Expression.
    • exprSetParent

      public void exprSetParent(ExpressionNode n)
      This pair of methods are used to inform the node of its parent.
      Specified by:
      exprSetParent in interface ExpressionNode
    • exprGetParent

      public ExpressionNode exprGetParent()
      Specified by:
      exprGetParent in interface ExpressionNode
    • getPublicId

      public String getPublicId()
      Specified by:
      getPublicId in interface SourceLocator
    • getSystemId

      public String getSystemId()
      Specified by:
      getSystemId in interface SourceLocator
    • getLineNumber

      public int getLineNumber()
      Specified by:
      getLineNumber in interface SourceLocator
    • getColumnNumber

      public int getColumnNumber()
      Specified by:
      getColumnNumber in interface SourceLocator