Package com.icl.saxon.expr
Class Expression
java.lang.Object
com.icl.saxon.expr.Expression
- Direct Known Subclasses:
AttributeValueTemplate
,BinaryExpression
,ErrorExpression
,Function
,IsLastExpression
,NodeSetComparison
,NodeSetExpression
,PositionRange
,SingletonComparison
,Value
,VariableReference
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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Determine whether the expression contains any references to variablesabstract void
display
(int level) Diagnostic print of expression structureReturn an enumeration of nodes in a nodeset.abstract Value
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.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.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.abstract int
Determine the data type of the expression, if possibleabstract int
Determine which aspects of the context the expression depends on.final StaticContext
Determine the static context used when the expression was parsedprotected static String
indent
(int level) Construct indent string, for diagnostic outputboolean
Determine, in the case of an expression whose data type is Value.NODESET, whether all the nodes in the node-set are guaranteed to come from the same document as the context node.static Expression
make
(String expression, StaticContext env) Parse an expressionvoid
outputStringValue
(Outputter out, Context context) Evaluate an expression as a String and write the result to the specified outputter.abstract Expression
Perform a partial evaluation of the expression, by eliminating specified dependencies on the context.final void
Set the static context used when the expression was parsedsimplify()
Simplify an expression.boolean
Determine whether the expression uses the current() function.
-
Field Details
-
staticContext
-
-
Constructor Details
-
Expression
public Expression()
-
-
Method Details
-
make
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
- Throws:
XPathException
-
simplify
Simplify an expression. Default implementation does nothing.- Returns:
- the simplified expression
- Throws:
XPathException
-
setStaticContext
Set the static context used when the expression was parsed -
getStaticContext
Determine the static context used when the expression was parsed -
containsReferences
Determine whether the expression contains any references to variables- Returns:
- true if so
- Throws:
XPathException
-
evaluate
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
- Throws:
XPathException
-
evaluateAsBoolean
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
- Throws:
XPathException
-
evaluateAsNumber
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
- Throws:
XPathException
-
evaluateAsString
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
- Throws:
XPathException
-
outputStringValue
Evaluate an expression as a String and write the result to the specified outputter.- Parameters:
out
- The required outputtercontext
- The context in which the expression is to be evaluated- Throws:
TransformerException
-
evaluateAsNodeSet
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. Note that the result is not necessarily in document order; to get it into document order, call sort() on the result.
- Throws:
XPathException
- when the expression does not return a nodeset.
-
enumerate
Return an enumeration of nodes in a nodeset.- Parameters:
context
- The context in which the expression is to be evaluatedsorted
- Indicates whether the nodes are required in document order. If this is false, they may come in any order, but there will be no duplicates.- Throws:
XPathException
- when the expression does not return a nodeset.
-
getDataType
public abstract 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)
-
isContextDocumentNodeSet
public boolean isContextDocumentNodeSet()Determine, in the case of an expression whose data type is Value.NODESET, whether all the nodes in the node-set are guaranteed to come from the same document as the context node. Used for optimization. -
usesCurrent
public boolean usesCurrent()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
Perform a partial evaluation of the expression, by eliminating specified dependencies on the context.- Parameters:
dependencies
- The dependencies to be removed, e.g. Context.VARIABLEScontext
- The context to be used for the partial evaluation- Returns:
- a new expression (or Value) that does not have any of the specified dependencies
- Throws:
XPathException
-
display
public abstract void display(int level) Diagnostic print of expression structure -
indent
Construct indent string, for diagnostic output
-