net.sf.saxon.instruct

Class Block

public class Block extends Instruction

Implements an imaginary xsl:block instruction which simply evaluates its contents. Used for top-level templates, xsl:otherwise, etc.
Constructor Summary
Block()
Create an empty block
Method Summary
voidcheckForUpdatingSubexpressions()
Check to ensure that this expression does not contain any updating subexpressions.
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.
intcomputeSpecialProperties()
booleancontainsLocalParam()
Test whether the Block includes a LocalParam instruction (which will be true only if it is the body of an XSLT template)
Expressioncopy()
Copy an expression.
booleancreatesNewNodes()
Determine whether this instruction creates new nodes.
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.
intgetCardinality()
Determine the cardinality of the expression
Expression[]getChildren()
Get the children of this instruction
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 this expression
booleanisUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specification
booleanisVacuousExpression()
Determine whether this is a vacuous expression as defined in the XQuery update specification
SequenceIteratoriterate(XPathContext context)
Iterate over the results of all the child expressions
EventIteratoriterateEvents(XPathContext context)
Get an EventIterator over the results of all the child expressions
Iterator<Expression>iterateSubExpressions()
static ExpressionmakeBlock(Expression e1, Expression e2)
Static factory method to create a block.
static ExpressionmakeBlock(List<Expression> list)
Static factory method to create a block from a list of expressions
ExpressionmergeAdjacentTextInstructions()
Merge any adjacent instructions that create literal text nodes
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
TailCallprocessLeavingTail(XPathContext context)
voidprocessLocalParams(XPathContext context)
Process any local parameter declarations within the block.
protected voidpromoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
voidsetChildren(Expression[] children)
Set the children of this instruction
Expressionsimplify(ExpressionVisitor visitor)
Simplify an expression.
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Constructor Detail

Block

public Block()
Create an empty block

Method Detail

checkForUpdatingSubexpressions

public void checkForUpdatingSubexpressions()
Check to ensure that this expression does not contain any updating subexpressions. This check is overridden for those expressions that permit updating subexpressions.

Throws: net.sf.saxon.trans.XPathException if the expression has a non-permitted updateing subexpression

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.

computeSpecialProperties

public int computeSpecialProperties()

containsLocalParam

public boolean containsLocalParam()
Test whether the Block includes a LocalParam instruction (which will be true only if it is the body of an XSLT template)

Returns: true if the Block contains a LocalParam instruction

copy

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

Returns: the copy of the original expression

createsNewNodes

public final boolean createsNewNodes()
Determine whether this instruction creates new nodes. This implementation returns true if any child instruction returns true.

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.

getCardinality

public final int getCardinality()
Determine the cardinality of the expression

getChildren

public Expression[] getChildren()
Get the children of this instruction

Returns: the children of this instruction, as an array of Instruction objects. May return either a zero-length array or null if there are no children

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 final ItemType getItemType(TypeHierarchy th)
Determine the data type of the items returned by this expression

Parameters: th the type hierarchy cache

Returns: the data type

isUpdatingExpression

public boolean isUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specification

Returns: true if this is an updating expression

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 results of all the child expressions

iterateEvents

public EventIterator iterateEvents(XPathContext context)
Get an EventIterator over the results of all the child expressions

Parameters: context the XPath dynamic context

Returns: an EventIterator

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()

makeBlock

public static Expression makeBlock(Expression e1, Expression e2)
Static factory method to create a block. If one of the arguments is already a block, the contents will be merged into a new composite block

Parameters: e1 the first subexpression (child) of the block e2 the second subexpression (child) of the block

Returns: a Block containing the two subexpressions, and if either of them is a block, it will have been collapsed to create a flattened sequence

makeBlock

public static Expression makeBlock(List<Expression> list)
Static factory method to create a block from a list of expressions

Parameters: list the list of expressions making up this block. The members of the List must be instances of Expression

Returns: a Block containing the two subexpressions, and if either of them is a block, it will have been collapsed to create a flattened sequence

mergeAdjacentTextInstructions

public Expression mergeAdjacentTextInstructions()
Merge any adjacent instructions that create literal text nodes

Returns: the expression after merging literal text instructions

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

processLeavingTail

public TailCall processLeavingTail(XPathContext context)

processLocalParams

public void processLocalParams(XPathContext context)
Process any local parameter declarations within the block. This is used within a saxon:finally instruction within saxon:iterate to make sure that the loop parameters are properly set

Parameters: context dynamic evaluation context

Throws: XPathException

promoteInst

protected void promoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.

Parameters: offer The type of rewrite being offered

Throws: XPathException

replaceSubExpression

public boolean replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression

Parameters: original the original subexpression replacement the replacement subexpression

Returns: true if the original subexpression is found

setChildren

public void setChildren(Expression[] children)
Set the children of this instruction

Parameters: children The instructions that are children of this instruction

simplify

public Expression simplify(ExpressionVisitor visitor)
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation does nothing.

Parameters: visitor an expression visitor

Returns: the simplified expression

Throws: XPathException if an error is discovered during expression rewriting

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)