Class SimpleExpression

java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.SimpleExpression
All Implemented Interfaces:
Callable, ExportAgent, Locatable, IdentityComparable, Traceable
Direct Known Subclasses:
SQLConnect.ConnectInstruction

public abstract class SimpleExpression extends Expression implements Callable
An abstract implementation of Expression designed to make it easy to implement new expressions, in particular, expressions to support extension instructions.

An implementation of this class must supply the Callable.call(XPathContext, net.sf.saxon.om.Sequence[]) method to evaluate the expression and return its result.

  • Constructor Details

    • SimpleExpression

      public SimpleExpression()
      Constructor
  • Method Details

    • setOperanda

      protected void setOperanda(OperandArray operanda)
      Set the data structure for the operands of this expression. This must be created during initialisation of the expression and must not be subsequently changed
      Parameters:
      operanda - the data structure for expression operands
    • getOperanda

      protected OperandArray getOperanda()
      Get the data structure holding the operands of this expression.
      Returns:
      the data structure holding expression operands
    • operands

      public Iterable<Operand> operands()
      Description copied from class: Expression
      Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.

      If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.

      Overrides:
      operands in class Expression
      Returns:
      an iterator containing the sub-expressions of this expression
    • setArguments

      public void setArguments(Expression[] sub)
      Set the immediate sub-expressions of this expression.
      Parameters:
      sub - an array containing the sub-expressions of this expression
    • copy

      public Expression copy(RebindingMap rebindings)
      Copy an expression. This makes a deep copy.
      Specified by:
      copy in class Expression
      Parameters:
      rebindings - variables that need to be re-bound
      Returns:
      the copy of the original expression
    • simpleCopy

      public SimpleExpression simpleCopy()
    • copyOperandsFrom

      protected SimpleExpression copyOperandsFrom(SimpleExpression se1)
      Helper method for subclasses to implement the copy() operation: this method can be applied to the new expression to copy operands from the old expressions
      Parameters:
      se1 - the expression being copied
      Returns:
      the target object of this method (for convenience)
    • getItemType

      public ItemType getItemType()
      Determine the data type of the items returned by this expression. This implementation returns "item()", which can be overridden in a subclass.
      Specified by:
      getItemType in class Expression
      Returns:
      the data type
    • computeCardinality

      protected int computeCardinality()
      Determine the static cardinality of the expression. This implementation returns "zero or more", which can be overridden in a subclass.
      Specified by:
      computeCardinality in class Expression
      Returns:
      the computed cardinality, as one of the values StaticProperty.ALLOWS_ZERO_OR_ONE, StaticProperty.EXACTLY_ONE, StaticProperty.ALLOWS_ONE_OR_MORE, StaticProperty.ALLOWS_ZERO_OR_MORE. May also return StaticProperty.ALLOWS_ZERO if the result is known to be an empty sequence, or StaticProperty.ALLOWS_MANY if if is known to return a sequence of length two or more.
    • evaluateItem

      public final Item evaluateItem(XPathContext context) throws XPathException
      Evaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.
      Overrides:
      evaluateItem in class Expression
      Parameters:
      context - The context in which the expression is to be evaluated
      Returns:
      the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
      Throws:
      XPathException - if any dynamic error occurs evaluating the expression
    • iterate

      public final SequenceIterator iterate(XPathContext context) throws XPathException
      Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.
      Overrides:
      iterate in class Expression
      Parameters:
      context - supplies the context for evaluation
      Returns:
      a SequenceIterator that can be used to iterate over the result of the expression
      Throws:
      XPathException - if any dynamic error occurs evaluating the expression
    • process

      public final void process(Outputter output, XPathContext context) throws XPathException
      Process the instruction, without returning any tail calls
      Overrides:
      process in class Expression
      Parameters:
      output - the destination for the result
      context - The dynamic context, giving access to the current node,
      Throws:
      XPathException - if a dynamic error occurs
    • export

      public void export(ExpressionPresenter destination) throws XPathException
      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Specified by:
      export in interface ExportAgent
      Specified by:
      export in class Expression
      Parameters:
      destination - the expression presenter used to display the structure
      Throws:
      XPathException - if the export fails, for example if an expression is found that won't work in the target environment.
    • getExpressionType

      public String getExpressionType()
      Return a distinguishing name for the expression, for use in diagnostics. By default the class name is used.
      Returns:
      a distinguishing name for the expression (defaults to the name of the implementation class)
    • getElaborator

      public Elaborator getElaborator()
      Description copied from class: Expression
      Make an elaborator for this expression
      Overrides:
      getElaborator in class Expression
      Returns:
      an appropriate Elaborator