net.sf.saxon.instruct

Class SimpleNodeConstructor

public abstract class SimpleNodeConstructor extends Instruction implements DivisibleInstruction

Common superclass for XSLT instructions whose content template produces a text value: xsl:attribute, xsl:comment, xsl:processing-instruction, xsl:namespace, and xsl:text, and their XQuery equivalents
Field Summary
protected Expressionselect
Constructor Summary
SimpleNodeConstructor()
Default constructor used by subclasses
Method Summary
protected StringcheckContent(String data, XPathContext context)
Check the content of the node, and adjust it if necessary.
intcomputeCardinality()
Get the cardinality of the sequence returned by evaluating this instruction
intcomputeSpecialProperties()
Get the static properties of this expression (other than its type).
booleancreatesNewNodes()
Determine whether this instruction creates new nodes.
ItemevaluateItem(XPathContext context)
Evaluate as an expression.
intevaluateNameCode(XPathContext context)
Run-time method to compute the name of the node being constructed.
CharSequenceexpandChildren(XPathContext context)
Expand the stylesheet elements subordinate to this one, returning the result as a string.
ExpressiongetSelect()
Get the expression that determines the string value of the constructed node
SequenceIteratoriterate(XPathContext context)
Iterator<Expression>iterateSubExpressions()
abstract voidlocalTypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Method to perform type-checking specific to the kind of instruction
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
TailCallprocessLeavingTail(XPathContext context)
Process this instruction
voidprocessLeft(Stack<XPathContext> contextStack, Stack state)
In streaming mode, process the first half of the instruction (for example, to start a new document or element)
voidprocessRight(Stack<XPathContext> contextStack, Stack state)
In streaming mode, process the right half of the instruction (for example, to end a new document or element)
protected abstract voidprocessValue(CharSequence value, XPathContext context)
Process the value of the node, to create the new node.
protected voidpromoteInst(PromotionOffer offer)
Offer promotion for subexpressions.
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
voidsetSelect(Expression select, Configuration config)
Set the select expression: the value of this expression determines the string-value of the node
Expressionsimplify(ExpressionVisitor visitor)
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
The typeCheck() method is called in XQuery, where node constructors are implemented as Expressions.

Field Detail

select

protected Expression select

Constructor Detail

SimpleNodeConstructor

public SimpleNodeConstructor()
Default constructor used by subclasses

Method Detail

checkContent

protected String checkContent(String data, XPathContext context)
Check the content of the node, and adjust it if necessary. The checks depend on the node kind.

Parameters: data the supplied content context the dynamic context

Returns: the original content, unless adjustments are needed

Throws: XPathException if the content is invalid

computeCardinality

public int computeCardinality()
Get the cardinality of the sequence returned by evaluating this instruction

Returns: the static cardinality

computeSpecialProperties

public int computeSpecialProperties()
Get the static properties of this expression (other than its type). The result is bit-signficant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.

Returns: a set of flags indicating static properties of this expression

createsNewNodes

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

evaluateItem

public Item evaluateItem(XPathContext context)
Evaluate as an expression. We rely on the fact that when these instructions are generated by XQuery, there will always be a valueExpression to evaluate the content

evaluateNameCode

public int evaluateNameCode(XPathContext context)
Run-time method to compute the name of the node being constructed. This is overridden for nodes that have a name. The default implementation returns -1, which is suitable for unnamed nodes such as comments

Parameters: context the XPath dynamic evaluation context

Returns: the name pool nameCode identifying the name of the constructed node

Throws: XPathException if any failure occurs

expandChildren

public final CharSequence expandChildren(XPathContext context)
Expand the stylesheet elements subordinate to this one, returning the result as a string. The expansion must not generate any element or attribute nodes.

Parameters: context The dynamic context for the transformation

Returns: the value that will be used as the string value of the constructed node

Throws: XPathException if any error occurs

getSelect

public Expression getSelect()
Get the expression that determines the string value of the constructed node

Returns: the select expression

iterate

public SequenceIterator iterate(XPathContext context)

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()

localTypeCheck

public abstract void localTypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Method to perform type-checking specific to the kind of instruction

Parameters: visitor an expression visitor contextItemType the static type of the context item

Throws: XPathException

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
Process this instruction

Parameters: context the dynamic context of the transformation

Returns: a TailCall to be executed by the caller, always null for this instruction

processLeft

public final void processLeft(Stack<XPathContext> contextStack, Stack state)
In streaming mode, process the first half of the instruction (for example, to start a new document or element)

Parameters: contextStack state a stack on which the instruction can save state information during the call on processLeft()

processRight

public final void processRight(Stack<XPathContext> contextStack, Stack state)
In streaming mode, process the right half of the instruction (for example, to end a new document or element)

Parameters: contextStack state a stack on which the instruction can save state information during the call on processLeft()

processValue

protected abstract void processValue(CharSequence value, XPathContext context)
Process the value of the node, to create the new node.

Parameters: value the string value of the new node context the dynamic evaluation context

Throws: XPathException

promoteInst

protected void promoteInst(PromotionOffer offer)
Offer promotion for subexpressions. The offer will be accepted if the subexpression is not dependent on the factors (e.g. the context item) identified in the PromotionOffer. By default the offer is not accepted - this is appropriate in the case of simple expressions such as constant values and variable references where promotion would give no performance advantage. This method is always called at compile time.

Parameters: offer details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression

Throws: XPathException if any error is detected

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

setSelect

public void setSelect(Expression select, Configuration config)
Set the select expression: the value of this expression determines the string-value of the node

Parameters: select the expression that computes the string value of the node config the Saxon configuration (used for example to do early validation of the content of an attribute against the schema-defined type)

Throws: XPathException

simplify

public Expression simplify(ExpressionVisitor visitor)

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
The typeCheck() method is called in XQuery, where node constructors are implemented as Expressions. In this case the required type for the select expression is a single string.

Parameters: visitor an expression visitor

Returns: the rewritten expression

Throws: XPathException if any static errors are found in this expression or any of its children