com.icl.saxon.expr
Class Expression

java.lang.Object
  |
  +--com.icl.saxon.expr.Expression
Direct Known Subclasses:
AttributeValueTemplate, Function, NodeSetExpression, SingletonComparison, Value, VariableReference

public abstract class Expression
extends java.lang.Object

This class serves two purposes: it is an abstract superclass for different kinds of XPath expression, and it contains a static method to invoke the expression parser


Field Summary
protected static java.util.Vector emptyVector
           
protected  StaticContext staticContext
           
 
Constructor Summary
Expression()
           
 
Method Summary
 boolean containsReferences()
          Determine whether the expression contains any references to variables
 NodeEnumeration enumerate(Context context)
          Return an enumeration of nodes in a nodeset.
abstract  Value evaluate(Context context)
          Evaluate an expression.
 boolean evaluateAsBoolean(Context context)
          Evaluate an expression as a Boolean.
The result of x.evaluateAsBoolean(c) must be equivalent to x.evaluate(c).asBoolean(); but optimisations are possible when it is known that a boolean result is required, especially in the case of a NodeSet.
 NodeSetValue evaluateAsNodeSet(Context context)
          Evaluate an expression as a NodeSet.
 double evaluateAsNumber(Context context)
          Evaluate an expression as a Number.
The result of x.evaluateAsNumber(c) must be equivalent to x.evaluate(c).asNumber(); but optimisations are possible when it is known that a numeric result is required, especially in the case of a NodeSet.
 java.lang.String evaluateAsString(Context context)
          Evaluate an expression as a String.
The result of x.evaluateAsString(c) must be equivalent to x.evaluate(c).asString(); but optimisations are possible when it is known that a string result is required, especially in the case of a NodeSet.
 int getDataType()
          Determine the data type of the expression, if possible
abstract  int getDependencies()
          Determine which aspects of the context the expression depends on.
 StaticContext getStaticContext()
          Determine the static context used when the expression was parsed
 boolean isNumeric()
          Determine whether the return the type of the expression is numeric.
 boolean isRelative()
          Determine whether the value of the expression is dependent on the position of the current node in the current node list or on the size of the current node list.
static Expression make(java.lang.String expression)
          Parse an expression using a default compile-time context.
static Expression make(java.lang.String expression, StaticContext env)
          Parse an expression
abstract  Expression reduce(int dependencies, Context context)
          Perform a partial evaluation of the expression, by eliminating specified dependencies on the context.
 void setStaticContext(StaticContext sc)
          Set the static context used when the expression was parsed
 Expression simplify()
          Simplify an expression.
 boolean usesCurrent()
          Determine whether the expression uses the current() function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

staticContext

protected StaticContext staticContext

emptyVector

protected static java.util.Vector emptyVector
Constructor Detail

Expression

public Expression()
Method Detail

make

public static Expression make(java.lang.String expression,
                              StaticContext env)
                       throws org.xml.sax.SAXException
Parse an expression
Parameters:
expression - The expression (as a character string)
env - An object giving information about the compile-time context of the expression
Returns:
an object of type Expression

make

public static Expression make(java.lang.String expression)
                       throws org.xml.sax.SAXException
Parse an expression using a default compile-time context. This default context does not support the use of context-dependent facilities in expressions, including namespaces, use of variables, or use of the document() function (which needs to know a base URI)
Parameters:
expression - The expression (as a character string)
env - An object giving information about the compile-time context of the expression
Returns:
an object of type Expression

simplify

public Expression simplify()
                    throws org.xml.sax.SAXException
Simplify an expression. Default implementation does nothing.
Returns:
the simplified expression

setStaticContext

public final void setStaticContext(StaticContext sc)
Set the static context used when the expression was parsed

getStaticContext

public final StaticContext getStaticContext()
Determine the static context used when the expression was parsed

containsReferences

public boolean containsReferences()
                           throws org.xml.sax.SAXException
Determine whether the expression contains any references to variables
Returns:
true if so

evaluate

public abstract Value evaluate(Context context)
                        throws org.xml.sax.SAXException
Evaluate an expression.
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the value of the expression, evaluated in the current context

evaluateAsBoolean

public boolean evaluateAsBoolean(Context context)
                          throws org.xml.sax.SAXException
Evaluate an expression as a Boolean.
The result of x.evaluateAsBoolean(c) must be equivalent to x.evaluate(c).asBoolean(); but optimisations are possible when it is known that a boolean result is required, especially in the case of a NodeSet.
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the value of the expression, evaluated in the current context

evaluateAsNumber

public double evaluateAsNumber(Context context)
                        throws org.xml.sax.SAXException
Evaluate an expression as a Number.
The result of x.evaluateAsNumber(c) must be equivalent to x.evaluate(c).asNumber(); but optimisations are possible when it is known that a numeric result is required, especially in the case of a NodeSet.
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the value of the expression, evaluated in the current context

evaluateAsString

public java.lang.String evaluateAsString(Context context)
                                  throws org.xml.sax.SAXException
Evaluate an expression as a String.
The result of x.evaluateAsString(c) must be equivalent to x.evaluate(c).asString(); but optimisations are possible when it is known that a string result is required, especially in the case of a NodeSet.
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the value of the expression, evaluated in the current context

evaluateAsNodeSet

public NodeSetValue evaluateAsNodeSet(Context context)
                               throws org.xml.sax.SAXException
Evaluate an expression as a NodeSet.
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the value of the expression, evaluated in the current context
Throws:
org.xml.sax.SAXException - when the expression is not a nodeset expression.

enumerate

public NodeEnumeration enumerate(Context context)
                          throws org.xml.sax.SAXException
Return an enumeration of nodes in a nodeset.
Parameters:
context - The context in which the expression is to be evaluated
Throws:
org.xml.sax.SAXException - when the expression is not a nodeset expression.

getDataType

public int getDataType()
Determine the data type of the expression, if possible
Returns:
one of the values Value.STRING, Value.BOOLEAN, Value.NUMBER, Value.NODESET, Value.FRAGMENT, or Value.ANY (meaning not known in advance)

isNumeric

public boolean isNumeric()
Determine whether the return the type of the expression is numeric.
This information is needed if the expression is used as a filter in a path expression or pattern. If false, the value MAY be numeric (e.g. a variable reference)
Returns:
true if the expression will definitely return a numeric value.

isRelative

public final boolean isRelative()
                         throws org.xml.sax.SAXException
Determine whether the value of the expression is dependent on the position of the current node in the current node list or on the size of the current node list.
This information is useful when the expression is used as a filter in a pattern: if the expression is not relative, there is no need to evaluate the current node list.
Returns:
true if the value of the expression depends on position() or last() or if it uses a numeric predicate. This default implementation returns true only if one of the subexpressions is relative.

usesCurrent

public boolean usesCurrent()
                    throws org.xml.sax.SAXException
Determine whether the expression uses the current() function. This is an error if the expression is within a pattern

getDependencies

public abstract int getDependencies()
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as Context.VARIABLES and Context.CURRENT_NODE

reduce

public abstract Expression reduce(int dependencies,
                                  Context context)
                           throws org.xml.sax.SAXException
Perform a partial evaluation of the expression, by eliminating specified dependencies on the context.
Parameters:
dependencies - The dependencies to be removed, e.g. Context.VARIABLES
context - The context to be used for the partial evaluation
Returns:
a new expression (or Value) that does not have any of the specified dependencies