public class ForEach extends Instruction implements ContextMappingFunction<Item<?>>, ContextSwitchingExpression
Modifier and Type | Field and Description |
---|---|
protected Operand |
actionOp |
protected boolean |
containsTailCall |
protected boolean |
isInstruction |
protected Operand |
selectOp |
protected Operand |
threadsOp |
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 and Description |
---|
ForEach(Expression select,
Expression action)
Create an xsl:for-each instruction
|
ForEach(Expression select,
Expression action,
boolean containsTailCall,
Expression threads)
Create an xsl:for-each instruction
|
Modifier and Type | Method and Description |
---|---|
PathMap.PathMapNodeSet |
addToPathMap(PathMap pathMap,
PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.
|
boolean |
alwaysCreatesNewNodes()
Ask whether it is guaranteed that every item in the result of this instruction
is a newly created node.
|
void |
checkForUpdatingSubexpressions()
Check to ensure that this expression does not contain any inappropriate updating subexpressions.
|
void |
checkPermittedContents(SchemaType parentType,
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.
|
int |
computeSpecialProperties()
Get the static properties of this expression (other than its type).
|
Expression |
copy(RebindingMap rebindings)
Copy an expression.
|
void |
evaluatePendingUpdates(XPathContext context,
PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List.
|
protected void |
explainThreads(ExpressionPresenter out) |
void |
export(ExpressionPresenter out)
Diagnostic print of expression structure.
|
Expression |
getAction()
Get the action expression (in XSLT, the body of the xsl:for-each instruction
|
Expression |
getActionExpression()
Get the subexpression that is evaluated in the new context
|
java.lang.String |
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.
|
int |
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
|
int |
getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes
|
ItemType |
getItemType()
Determine the data type of the items returned by this expression
|
Expression |
getNumberOfThreadsExpression()
Get the number of threads requested
|
Expression |
getSelect()
Get the select expression
|
Expression |
getSelectExpression()
Get the select expression
|
UType |
getStaticUType(UType contextItemType)
Get the static type of the expression as a UType, following precisely the type
inference rules defined in the XSLT 3.0 specification.
|
java.lang.String |
getStreamerName()
Get the (partial) name of a class that supports streaming of this kind of expression
|
Expression |
getThreads()
Get the expression used to determine how many threads to use when multi-threading
|
boolean |
isInstruction()
Ask whether this expression is an instruction.
|
boolean |
isUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specification
|
SequenceIterator<?> |
iterate(XPathContext context)
Return an Iterator to iterate over the values of the sequence.
|
SequenceIterator<?> |
map(XPathContext context)
Map one item to a sequence.
|
boolean |
mayCreateNewNodes()
Determine whether this instruction creates new nodes.
|
java.lang.Iterable<Operand> |
operands()
Get the operands of this expression
|
Expression |
optimize(ExpressionVisitor visitor,
ContextItemStaticInfo contextInfo)
Perform optimisation of an expression and its subexpressions.
|
TailCall |
processLeavingTail(XPathContext context)
ProcessLeavingTail: called to do the real work of this instruction.
|
void |
setAction(Expression action)
Set the action expression (in XSLT, the body of the xsl:for-each instruction)
|
void |
setActionExpression(Expression action)
Set the action expression
|
void |
setInstruction(boolean inst)
Say whether this ForEach expression originates as an XSLT instruction
|
void |
setSelect(Expression select)
Set the select expression
|
void |
setSelectExpression(Expression select)
Set the select expression
|
void |
setThreads(Expression threads)
Set the expression used to determine how many threads to use when multi-threading
|
java.lang.String |
toShortString()
Produce a short string identifying the expression for use in error messages
|
java.lang.String |
toString()
The toString() method for an expression attempts to give a representation of the expression
in an XPath-like form.
|
Expression |
typeCheck(ExpressionVisitor visitor,
ContextItemStaticInfo contextInfo)
Perform type checking of an expression and its subexpressions.
|
Expression |
unordered(boolean retainAllNodes,
boolean forStreaming)
Replace this expression by a simpler expression that delivers the results without regard
to order.
|
assembleParams, assembleTunnelParams, computeCardinality, dynamicError, evaluateAsString, evaluateItem, getConstructType, getNetCost, getSourceLocator, isXSLT, process, someOperandCreatesNewNodes
adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, computeDependencies, computeHashCode, computeStaticProperties, dynamicError, effectiveBooleanValue, equals, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getInterpretedExpression, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isVacuousExpression, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, typeCheckChildren, typeError, verifyParentPointers
protected boolean containsTailCall
protected Operand selectOp
protected Operand actionOp
protected Operand threadsOp
protected boolean isInstruction
public ForEach(Expression select, Expression action)
select
- the select expressionaction
- the body of the xsl:for-each looppublic ForEach(Expression select, Expression action, boolean containsTailCall, Expression threads)
select
- the select expressionaction
- the body of the xsl:for-each loopcontainsTailCall
- true if the body of the loop contains a tail call on the containing functionthreads
- if >1 causes multithreaded execution (Saxon-EE only)public void setInstruction(boolean inst)
inst
- true if this is an xsl:for-each instruction; false if it is the XPath "!" operatorpublic boolean isInstruction()
isInstruction
in class Instruction
public Expression getSelect()
public void setSelect(Expression select)
select
- the select expression of the for-eachpublic Expression getAction()
public void setAction(Expression action)
action
- the action expressionpublic Expression getThreads()
public void setThreads(Expression threads)
threads
- the saxon:threads expression if present, or null otherwisepublic java.lang.Iterable<Operand> operands()
operands
in class Instruction
public int getInstructionNameCode()
getInstructionNameCode
in class Instruction
public Expression getSelectExpression()
getSelectExpression
in interface ContextSwitchingExpression
public void setSelectExpression(Expression select)
select
- the select expressionpublic void setActionExpression(Expression action)
action
- the select expressionpublic Expression getActionExpression()
getActionExpression
in interface ContextSwitchingExpression
public Expression getNumberOfThreadsExpression()
public final ItemType getItemType()
getItemType
in class Instruction
public UType getStaticUType(UType contextItemType)
getStaticUType
in class Expression
contextItemType
- static type of the context itempublic final boolean mayCreateNewNodes()
mayCreateNewNodes
in class Instruction
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Expression
This checks statically that the operands of the expression have the correct type; if necessary it generates code to do run-time type checking or type conversion. A static type error is reported only if execution cannot possibly succeed, that is, if a run-time type error is inevitable. The call may return a modified form of the expression.
This method is called after all references to functions and variables have been resolved to the declaration of the function or variable. However, the types of such functions and variables may not be accurately known if they have not been explicitly declared.
typeCheck
in class Expression
visitor
- an expression visitorcontextInfo
- Information available statically about the context item: whether it is (possibly)
absent; its static type; its streaming posture.XPathException
- if an error is discovered during this phase
(typically a type error)public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Expression
This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.
optimize
in class Expression
visitor
- an expression visitorcontextInfo
- the static type of "." at the point where this expression is invoked.
The parameter is set to null if it is known statically that the context item will be undefined.
If the type of the context item is not known statically, the argument is set to
Type.ITEM_TYPE
XPathException
- if an error is discovered during this phase
(typically a type error)public Expression unordered(boolean retainAllNodes, boolean forStreaming) throws XPathException
unordered
in class Expression
retainAllNodes
- set to true if the result must contain exactly the same nodes as the
original; set to false if the result can eliminate (or introduce) duplicates.forStreaming
- set to true if optimizing for streamingXPathException
- if the rewrite failspublic PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
The default implementation of this method assumes that an expression does no navigation other than the navigation done by evaluating its subexpressions, and that the subexpressions are evaluated in the same context as the containing expression. The method must be overridden for any expression where these assumptions do not hold. For example, implementations exist for AxisExpression, ParentExpression, and RootExpression (because they perform navigation), and for the doc(), document(), and collection() functions because they create a new navigation root. Implementations also exist for PathExpression and FilterExpression because they have subexpressions that are evaluated in a different context from the calling expression.
addToPathMap
in class Expression
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
- the set of nodes in the path map that are affectedpublic Expression copy(RebindingMap rebindings)
copy
in class Expression
rebindings
- variables that need to be re-boundpublic int computeSpecialProperties()
computeSpecialProperties
in class Instruction
public boolean alwaysCreatesNewNodes()
Instruction
alwaysCreatesNewNodes
in class Instruction
public boolean isUpdatingExpression()
isUpdatingExpression
in class Expression
public void checkForUpdatingSubexpressions() throws XPathException
checkForUpdatingSubexpressions
in class Expression
XPathException
- if the expression has a non-permitted updating subexpressionpublic int getImplementationMethod()
getImplementationMethod
in class Instruction
Expression.ITERATE_METHOD
or Expression.EVALUATE_METHOD
or
Expression.PROCESS_METHOD
public void checkPermittedContents(SchemaType parentType, boolean whole) throws XPathException
checkPermittedContents
in class Expression
parentType
- the "given complex type": the method is checking that the nodes returned by this
expression are acceptable members of the content model of this typewhole
- if true, we want to check that the value of this expression satisfies the content model
as a whole; if false we want to check that the value of the expression is acceptable as one part
of the contentXPathException
- if the value delivered by this expression cannot be part of the content model
of the given typepublic TailCall processLeavingTail(XPathContext context) throws XPathException
Instruction
processLeavingTail
in interface TailCallReturner
processLeavingTail
in class Instruction
context
- The dynamic context of the transformation, giving access to the current node,
the current variables, etc.XPathException
- if a dynamic error occurs during the evaluation
of the instructionpublic SequenceIterator<?> iterate(XPathContext context) throws XPathException
iterate
in class Instruction
context
- supplies the context for evaluationXPathException
- if any dynamic error occurs evaluating the
expressionpublic SequenceIterator<?> map(XPathContext context) throws XPathException
map
in interface ContextMappingFunction<Item<?>>
context
- The processing context. The item to be mapped is the context item identified
from this context: the values of position() and last() also relate to the set of items being mappedXPathException
- if a dynamic error is detectedpublic void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException
evaluatePendingUpdates
in class Expression
context
- the XPath dynamic evaluation contextpul
- the pending update list to which the results should be writtenXPathException
- if evaluation failsjava.lang.UnsupportedOperationException
- if the expression is not an updating expressionpublic void export(ExpressionPresenter out) throws XPathException
export
in interface ExportAgent
export
in class Expression
out
- the expression presenter used to display the structureXPathException
- if the export fails, for example if an expression is found that won't work
in the target environment.protected void explainThreads(ExpressionPresenter out) throws XPathException
XPathException
public java.lang.String toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.
For subclasses of Expression that represent XPath expressions, the result should always be a string that parses as an XPath 3.0 expression
toString
in class Expression
public java.lang.String toShortString()
Expression
toShortString
in class Expression
public java.lang.String getExpressionName()
getExpressionName
in class Instruction
public java.lang.String getStreamerName()
getStreamerName
in class Expression
Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.