net.sf.saxon.instruct

Class SimpleNodeConstructor

Implemented Interfaces:
SourceLocator, EvaluableItem, InstructionInfoProvider, SequenceIterable, Serializable, SourceLocator, TailCallReturner
Known Direct Subclasses:
Comment, ComputedAttribute, FixedAttribute, Namespace, ProcessingInstruction, ValueOf

public abstract class SimpleNodeConstructor
extends Instruction

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 Expression
select

Fields inherited from class net.sf.saxon.expr.Expression

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

SimpleNodeConstructor()
Default constructor used by subclasses

Method Summary

protected String
checkContent(String data, XPathContext context)
Check the content of the node, and adjust it if necessary.
int
computeCardinality()
Get the cardinality of the sequence returned by evaluating this instruction
int
computeSpecialProperties()
Get the static properties of this expression (other than its type).
boolean
createsNewNodes()
Determine whether this instruction creates new nodes.
Item
evaluateItem(XPathContext context)
Evaluate as an expression.
int
evaluateNameCode(XPathContext context)
Run-time method to compute the name of the node being constructed.
CharSequence
expandChildren(XPathContext context)
Expand the stylesheet elements subordinate to this one, returning the result as a string.
Expression
getSelect()
Get the expression that determines the string value of the constructed node
SequenceIterator
iterate(XPathContext context)
Iterator
iterateSubExpressions()
abstract void
localTypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Method to perform type-checking specific to the kind of instruction
Expression
optimize(ExpressionVisitor visitor, ItemType contextItemType)
protected void
promoteInst(PromotionOffer offer)
Offer promotion for subexpressions.
boolean
replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
void
setSelect(Expression select, Configuration config)
Set the select expression: the value of this expression determines the string-value of the node
Expression
simplify(ExpressionVisitor visitor)
Expression
typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
The typeCheck() method is called in XQuery, where node constructors are implemented as Expressions.

Methods inherited from class net.sf.saxon.instruct.Instruction

assembleParams, assembleTunnelParams, computeCardinality, computeSpecialProperties, createsNewNodes, dynamicError, evaluateAsString, evaluateItem, getImplementationMethod, getInstructionInfo, getInstructionNameCode, getItemType, getSourceLocator, isXSLT, iterate, process, processLeavingTail, promote, promoteInst, simplify

Methods inherited from class net.sf.saxon.expr.Expression

addToPathMap, adoptChildExpression, checkPermittedContents, computeCardinality, computeDependencies, computeSpecialProperties, computeStaticProperties, copy, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, explain, findParentOf, getCardinality, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getItemType, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, iterate, iterateEvents, iterateSubExpressions, markTailFunctionCalls, optimize, process, promote, replaceSubExpression, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, simplify, staticTypeCheck, suppressValidation, toString, typeCheck, typeError

Field Details

select

protected Expression select

Constructor Details

SimpleNodeConstructor

public SimpleNodeConstructor()
Default constructor used by subclasses

Method Details

checkContent

protected String checkContent(String data,
                              XPathContext context)
            throws XPathException
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
Overrides:
computeCardinality in interface 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.
Overrides:
computeSpecialProperties in interface Instruction
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.
Overrides:
createsNewNodes in interface Instruction

evaluateItem

public Item evaluateItem(XPathContext context)
            throws XPathException
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
Specified by:
evaluateItem in interface EvaluableItem
Overrides:
evaluateItem in interface Instruction

evaluateNameCode

public int evaluateNameCode(XPathContext context)
            throws XPathException
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 CharSequence expandChildren(XPathContext context)
            throws XPathException
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)
            throws XPathException
Specified by:
iterate in interface SequenceIterable
Overrides:
iterate in interface Instruction

iterateSubExpressions

public Iterator iterateSubExpressions()
Overrides:
iterateSubExpressions in interface Expression

localTypeCheck

public abstract void localTypeCheck(ExpressionVisitor visitor,
                                    ItemType contextItemType)
            throws XPathException
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)
            throws XPathException
Overrides:
optimize in interface Expression

promoteInst

protected void promoteInst(PromotionOffer offer)
            throws XPathException
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.
Overrides:
promoteInst in interface Instruction
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
Overrides:
replaceSubExpression in interface Expression
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)
            throws XPathException
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)
            throws XPathException
Overrides:
simplify in interface Instruction

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
            throws XPathException
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.
Overrides:
typeCheck in interface Expression
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