net.sf.saxon.instruct

Class DocumentInstr

Implemented Interfaces:
SourceLocator, EvaluableItem, InstructionInfoProvider, SequenceIterable, Serializable, SourceLocator, TailCallReturner

public class DocumentInstr
extends ParentNodeConstructor

An instruction to create a document node. This corresponds to the xsl:document-node instruction in XSLT. It is also used to support the document node constructor expression in XQuery, and is generated implicitly within an xsl:variable that constructs a temporary tree.

Conceptually it represents an XSLT instruction xsl:document-node, with no attributes, whose content is a complex content constructor for the children of the document node.

Field Summary

Fields inherited from class net.sf.saxon.instruct.ParentNodeConstructor

content

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

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

DocumentInstr(boolean textOnly, String constantText, String baseURI)
Create a document constructor instruction

Method Summary

protected void
checkContentSequence(StaticContext env)
Check statically that the sequence of child instructions doesn't violate any obvious constraints on the content of the node
protected static void
checkContentSequence(StaticContext env, Expression content, int validation, SchemaType type)
Expression
copy()
Copy an expression.
Item
evaluateItem(XPathContext context)
Evaluate as an expression.
void
explain(ExpressionPresenter out)
Diagnostic print of expression structure.
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 (the string "document-constructor")
ItemType
getItemType(TypeHierarchy th)
Get the item type
Expression
getStringValueExpression(StaticContext env)
In the case of a text-only instruction (xsl:variable containing a text node or one or more xsl:value-of instructions), return an expression that evaluates to the textual content as an instance of xs:untypedAtomic
boolean
isTextOnly()
Determine whether this is a "text only" document: essentially, an XSLT xsl:variable that contains a single text node or xsl:value-of instruction.
EventIterator
iterateEvents(XPathContext context)
Deliver the result of the expression as a sequence of events.
TailCall
processLeavingTail(XPathContext context)
ProcessLeavingTail: called to do the real work of this instruction.
void
setValidationAction(int action)
Set the validation action
Expression
simplify(ExpressionVisitor visitor)
Simplify an expression.

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

addToPathMap, checkContentSequence, computeCardinality, createsNewNodes, getBaseURI, getCardinality, getContentExpression, getSchemaType, getValidationMode, isLazyConstruction, isNamespaceSensitive, iterateSubExpressions, optimize, promoteInst, replaceSubExpression, setBaseURI, setContentExpression, setLazyConstruction, setSchemaType, setValidationMode, simplify, typeCheck

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

Constructor Details

DocumentInstr

public DocumentInstr(boolean textOnly,
                     String constantText,
                     String baseURI)
Create a document constructor instruction
Parameters:
textOnly - true if the content contains text nodes only
constantText - if the content contains text nodes only and the text is known at compile time, supplies the textual content
baseURI - the base URI of the instruction

Method Details

checkContentSequence

protected void checkContentSequence(StaticContext env)
            throws XPathException
Check statically that the sequence of child instructions doesn't violate any obvious constraints on the content of the node
Overrides:
checkContentSequence in interface ParentNodeConstructor
Parameters:
env - the static context
Throws:
XPathException -

checkContentSequence

protected static void checkContentSequence(StaticContext env,
                                           Expression content,
                                           int validation,
                                           SchemaType type)
            throws XPathException

copy

public Expression copy()
Copy an expression. This makes a deep copy.
Overrides:
copy in interface Expression
Returns:
the copy of the original expression

evaluateItem

public Item evaluateItem(XPathContext context)
            throws XPathException
Evaluate as an expression.
Specified by:
evaluateItem in interface EvaluableItem
Overrides:
evaluateItem in interface Instruction

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
Overrides:
explain in interface Expression

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 prefered. For instructions this is the process() method.
Overrides:
getImplementationMethod in interface Instruction

getInstructionNameCode

public int getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes (the string "document-constructor")
Overrides:
getInstructionNameCode in interface Instruction

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the item type
Overrides:
getItemType in interface Instruction
Parameters:
th - The TypeHierarchy
Returns:
the in

getStringValueExpression

public Expression getStringValueExpression(StaticContext env)
In the case of a text-only instruction (xsl:variable containing a text node or one or more xsl:value-of instructions), return an expression that evaluates to the textual content as an instance of xs:untypedAtomic
Parameters:
env - the static evaluation context
Returns:
an expression that evaluates to the textual content

isTextOnly

public boolean isTextOnly()
Determine whether this is a "text only" document: essentially, an XSLT xsl:variable that contains a single text node or xsl:value-of instruction.
Returns:
true if this is a text-only document

iterateEvents

public EventIterator iterateEvents(XPathContext context)
            throws XPathException
Deliver the result of the expression as a sequence of events.

The events (of class PullEvent) are either complete items, or one of startElement, endElement, startDocument, or endDocument, known as semi-nodes. The stream of events may also include a nested EventIterator. If a start-end pair exists in the sequence, then the events between this pair represent the content of the document or element. The content sequence will have been processed to the extent that any attribute and namespace nodes in the content sequence will have been merged into the startElement event. Namespace fixup will have been performed: that is, unique prefixes will have been allocated to element and attribute nodes, and all namespaces will be declared by means of a namespace node in the startElement event or in an outer startElement forming part of the sequence. However, duplicate namespaces may appear in the sequence.

The content of an element or document may include adjacent or zero-length text nodes, atomic values, and nodes represented as nodes rather than broken down into events.

Overrides:
iterateEvents in interface Expression
Parameters:
context - The dynamic evaluation context
Returns:
the result of the expression as an iterator over a sequence of PullEvent objects
Throws:
XPathException - if a dynamic error occurs during expression evaluation

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
            throws XPathException
ProcessLeavingTail: called to do the real work of this instruction. This method must be implemented in each subclass. The results of the instruction are written to the current Receiver, which can be obtained via the Controller.
Specified by:
processLeavingTail in interface TailCallReturner
Overrides:
processLeavingTail in interface Instruction
Parameters:
context - The dynamic context of the transformation, giving access to the current node, the current variables, etc.
Returns:
null if the instruction has completed execution; or a TailCall indicating a function call or template call that is delegated to the caller, to be made after the stack has been unwound so as to save stack space.

setValidationAction

public void setValidationAction(int action)
Set the validation action
Parameters:
action - the validation action required

simplify

public Expression simplify(ExpressionVisitor visitor)
            throws XPathException
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation does nothing.
Overrides:
simplify in interface ParentNodeConstructor
Parameters:
visitor - an expression visitor
Returns:
the simplified expression
Throws:
XPathException - if an error is discovered during expression rewriting