Package net.sf.saxon.expr
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SimpleExpression.SimpleExpressionElaborator
-
Field Summary
-
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD
-
-
Constructor Summary
Constructors Constructor Description SimpleExpression()
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
computeCardinality()
Determine the static cardinality of the expression.Expression
copy(RebindingMap rebindings)
Copy an expression.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 expressionsItem
evaluateItem(XPathContext context)
Evaluate an expression as a single item.void
export(ExpressionPresenter destination)
Diagnostic print of expression structure.Elaborator
getElaborator()
Make an elaborator for this expressionjava.lang.String
getExpressionType()
Return a distinguishing name for the expression, for use in diagnostics.ItemType
getItemType()
Determine the data type of the items returned by this expression.protected OperandArray
getOperanda()
Get the data structure holding the operands of this expression.SequenceIterator
iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.java.lang.Iterable<Operand>
operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.void
process(Outputter output, XPathContext context)
Process the instruction, without returning any tail callsvoid
setArguments(Expression[] sub)
Set the immediate sub-expressions of this expression.protected void
setOperanda(OperandArray operanda)
Set the data structure for the operands of this expression.SimpleExpression
simpleCopy()
-
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeSpecialProperties, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, equals, evaluateAsString, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExpressionName, getExtraProperty, getImplementationMethod, getIntegerBounds, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimize, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, toPattern, toShortString, toString, typeCheck, typeCheckChildren, typeError, unordered, verifyParentPointers, withLocation
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Method Detail
-
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 java.lang.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 classExpression
- 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 classExpression
- 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 classExpression
- 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 classExpression
- 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 returnStaticProperty.ALLOWS_ZERO
if the result is known to be an empty sequence, orStaticProperty.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 classExpression
- 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 classExpression
- 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 classExpression
- Parameters:
output
- the destination for the resultcontext
- 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 interfaceExportAgent
- Specified by:
export
in classExpression
- 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 java.lang.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 classExpression
- Returns:
- an appropriate
Elaborator
-
-