net.sf.saxon.expr

Class ForExpression

public class ForExpression extends Assignation

A ForExpression maps an expression over a sequence. This version works with range variables, it doesn't change the context information
Nested Class Summary
protected static classForExpression.EventMappingAction
The EventMappingAction represents the action to be taken for each item in the source sequence.
protected static classForExpression.MappingAction
The MappingAction represents the action to be taken for each item in the source sequence.
Field Summary
protected PositionVariablepositionVariable
Constructor Summary
ForExpression()
Create a "for" expression (for $x at $p in SEQUENCE return ACTION)
Method Summary
voidcheckPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type.
intcomputeCardinality()
Determine the static cardinality of the expression
Expressioncopy()
Copy an expression.
voidevaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List.
voidexplain(ExpressionPresenter out)
Diagnostic print of expression structure.
protected voidexplainSpecializedAttributes(ExpressionPresenter out)
protected Binding[]extendBindingList(Binding[] in)
Extend an array of variable bindings to include the binding(s) defined in this expression
intgetConstructType()
Get the type of this expression for use in tracing and diagnostics
intgetImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the items returned by the expression, if possible
StructuredQNamegetPositionVariableName()
Get the name of the position variable
protected intgetRangeVariableCardinality()
Get the cardinality of the range variable
intgetRequiredSlots()
Get the number of slots required.
booleanhasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly
booleanisVacuousExpression()
Determine whether this is a vacuous expression as defined in the XQuery update specification
SequenceIteratoriterate(XPathContext context)
Iterate over the sequence of values
EventIteratoriterateEvents(XPathContext context)
Deliver the result of the expression as a sequence of events.
intmarkTailFunctionCalls(StructuredQName qName, int arity)
Mark tail function calls: only possible if the for expression iterates zero or one times.
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression
voidprocess(XPathContext context)
Process this expression as an instruction, writing results to the current outputter
voidsetPositionVariable(PositionVariable decl)
Set the reference to the position variable (XQuery only)
voidsetSlotNumber(int nr)
Set the slot number for the range variable
StringtoString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath.
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression

Field Detail

positionVariable

protected PositionVariable positionVariable

Constructor Detail

ForExpression

public ForExpression()
Create a "for" expression (for $x at $p in SEQUENCE return ACTION)

Method Detail

checkPermittedContents

public void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type. It's always OK to say yes, since the check will be repeated at run-time. The process of checking element and attribute constructors against the content model of a complex type also registers the type of content expected of those constructors, so the static validation can continue recursively.

computeCardinality

public int computeCardinality()
Determine the static cardinality of the expression

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

evaluatePendingUpdates

public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List. The default implementation of this method, which is used for non-updating expressions, throws an UnsupportedOperationException

Parameters: context the XPath dynamic evaluation context pul the pending update list to which the results should be written

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

explainSpecializedAttributes

protected void explainSpecializedAttributes(ExpressionPresenter out)

extendBindingList

protected Binding[] extendBindingList(Binding[] in)
Extend an array of variable bindings to include the binding(s) defined in this expression

getConstructType

public int getConstructType()
Get the type of this expression for use in tracing and diagnostics

Returns: the type of expression, as enumerated in class Location

getImplementationMethod

public int getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided. This implementation provides both iterate() and process() methods natively.

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the items returned by the expression, if possible

Parameters: th the type hierarchy cache

Returns: one of the values Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known in advance)

getPositionVariableName

public StructuredQName getPositionVariableName()
Get the name of the position variable

Returns: the name of the position variable ("at $p") if there is one, or null if not

getRangeVariableCardinality

protected int getRangeVariableCardinality()
Get the cardinality of the range variable

Returns: the cardinality of the range variable (StaticProperty.EXACTLY_ONE). Can be overridden in a subclass

getRequiredSlots

public int getRequiredSlots()
Get the number of slots required.

Returns: normally 1, except for a FOR expression with an AT clause, where it is 2.

hasLoopingSubexpression

public boolean hasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly

Parameters: child the immediate subexpression

Returns: true if the child expression is evaluated repeatedly

isVacuousExpression

public boolean isVacuousExpression()
Determine whether this is a vacuous expression as defined in the XQuery update specification

Returns: true if this expression is vacuous

iterate

public SequenceIterator iterate(XPathContext context)
Iterate over the sequence of values

iterateEvents

public EventIterator iterateEvents(XPathContext context)
Deliver the result of the expression as a sequence of events.

Parameters: context The dynamic evaluation context

Returns: the result of the expression as an iterator over a sequence of PullEvent objects

Throws: XPathException if a dynamic error occurs during expression evaluation

markTailFunctionCalls

public int markTailFunctionCalls(StructuredQName qName, int arity)
Mark tail function calls: only possible if the for expression iterates zero or one times. (This arises in XSLT/XPath, which does not have a LET expression, so FOR gets used instead)

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression

process

public void process(XPathContext context)
Process this expression as an instruction, writing results to the current outputter

setPositionVariable

public void setPositionVariable(PositionVariable decl)
Set the reference to the position variable (XQuery only)

Parameters: decl the range variable declaration for the position variable

setSlotNumber

public void setSlotNumber(int nr)
Set the slot number for the range variable

Parameters: nr the slot number allocated to the range variable on the local stack frame. This implicitly allocates the next slot number to the position variable if there is one.

toString

public String toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax

Returns: a representation of the expression as a string

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression