net.sf.saxon.expr.instruct
Class SimpleNodeConstructor

java.lang.Object
  extended by net.sf.saxon.expr.Expression
      extended by net.sf.saxon.expr.instruct.Instruction
          extended by net.sf.saxon.expr.instruct.SimpleNodeConstructor
All Implemented Interfaces:
Serializable, SourceLocator, LocationProvider, SaxonLocator, TailCallReturner, InstructionInfo, Locator
Direct Known Subclasses:
AttributeCreator, Comment, NamespaceConstructor, 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

See Also:
Serialized Form

Field Summary
protected  Expression select
           
 
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, EVENT_FEED_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, PUSH_SELECTION, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, WATCH_METHOD
 
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.
 NodeInfo evaluateItem(XPathContext context)
          Evaluate as an expression.
 NodeName evaluateNodeName(XPathContext context)
          Run-time method to compute the name of the node being constructed.
 Expression getContentExpression()
          Get the expression that determines the string value of the constructed node
 SequenceIterator<NodeInfo> iterate(XPathContext context)
          Return an Iterator to iterate over the values of a sequence.
 Iterator<Expression> iterateSubExpressions()
          Get the immediate sub-expressions of this expression.
abstract  void localTypeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)
          Method to perform type-checking specific to the kind of instruction
 Expression optimize(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)
          Perform optimisation of an expression and its subexpressions.
 TailCall processLeavingTail(XPathContext context)
          Process this instruction
abstract  void processValue(CharSequence value, XPathContext context)
          Process the value of the node, to create the new node.
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)
          Simplify an expression.
 Expression typeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)
          The typeCheck() method is called in XQuery, where node constructors are implemented as Expressions.
 
Methods inherited from class net.sf.saxon.expr.instruct.Instruction
assembleParams, assembleTunnelParams, dynamicError, evaluateAsString, getConstructType, getExpressionName, getImplementationMethod, getInstructionName, getInstructionNameCode, getItemType, getIteratorFromProcessMethod, getSourceLocator, isXSLT, process, promote
 
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, copy, doPromotion, dynamicError, effectiveBooleanValue, evaluatePendingUpdates, explain, explain, getCardinality, getColumnNumber, getColumnNumber, getContainer, getDependencies, getEvaluationMethod, getExecutable, getHostLanguage, getIntegerBounds, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, hasLoopingSubexpression, hasVariableBinding, implementsStaticTypeCheck, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterateEvents, iterateSameFocusSubExpressions, markTailFunctionCalls, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, toString, typeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.xml.transform.SourceLocator
getColumnNumber, getLineNumber, getPublicId, getSystemId
 

Field Detail

select

protected Expression select
Constructor Detail

SimpleNodeConstructor

public SimpleNodeConstructor()
Default constructor used by subclasses

Method Detail

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)

getContentExpression

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

Returns:
the select expression

createsNewNodes

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

Overrides:
createsNewNodes in class Instruction
Returns:
true if the instruction creates new nodes (or if it can't be proved that it doesn't)

computeCardinality

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

Overrides:
computeCardinality in class Instruction
Returns:
the static cardinality

simplify

public Expression simplify(ExpressionVisitor visitor)
                    throws XPathException
Description copied from class: Instruction
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation does nothing.

Specified by:
simplify in class Instruction
Parameters:
visitor - an expression visitor
Returns:
the simplified expression
Throws:
XPathException - if an error is discovered during expression rewriting

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 class Instruction
Returns:
a set of flags indicating static properties of this expression

localTypeCheck

public abstract void localTypeCheck(ExpressionVisitor visitor,
                                    ExpressionVisitor.ContextItemType 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 - if a type error is detected

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ExpressionVisitor.ContextItemType 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 class Expression
Parameters:
visitor - an expression visitor
contextItemType - 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
Returns:
the rewritten expression
Throws:
XPathException - if any static errors are found in this expression or any of its children

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ExpressionVisitor.ContextItemType contextItemType)
                    throws XPathException
Description copied from class: Expression
Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.

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.

Overrides:
optimize in class Expression
Parameters:
visitor - an expression visitor
contextItemType - 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
Returns:
the original expression, rewritten if appropriate to optimize execution
Throws:
XPathException - if an error is discovered during this phase (typically a type error)

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()
Description copied from class: Expression
Get the immediate sub-expressions of this expression. Default implementation returns a zero-length array, appropriate for an expression that has no sub-expressions.

Overrides:
iterateSubExpressions in class Expression
Returns:
an iterator containing the sub-expressions of this expression

replaceSubExpression

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

Overrides:
replaceSubExpression in class Expression
Parameters:
original - the original subexpression
replacement - the replacement subexpression
Returns:
true if the original subexpression is found

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
                            throws XPathException
Process this instruction

Specified by:
processLeavingTail in interface TailCallReturner
Specified by:
processLeavingTail in class Instruction
Parameters:
context - the dynamic context of the transformation
Returns:
a TailCall to be executed by the caller, always null for this instruction
Throws:
XPathException - if a dynamic error occurs during the evaluation of the instruction

processValue

public abstract void processValue(CharSequence value,
                                  XPathContext context)
                           throws XPathException
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 - if a dynamic error occurs

evaluateItem

public NodeInfo evaluateItem(XPathContext context)
                      throws XPathException
Evaluate as an expression.

Overrides:
evaluateItem in class Instruction
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
Throws:
XPathException - if any dynamic error occurs evaluating the expression

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

evaluateNodeName

public NodeName evaluateNodeName(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

iterate

public SequenceIterator<NodeInfo> iterate(XPathContext context)
                                   throws XPathException
Description copied from class: Instruction
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.

Overrides:
iterate in class Instruction
Parameters:
context - supplies the context for evaluation
Returns:
a SequenceIterator that can be used to iterate over the result of the expression
Throws:
XPathException - if any dynamic error occurs evaluating the 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 class 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


Copyright (c) 2004-2011 Saxonica Limited. All rights reserved.