net.sf.saxon.instruct

Class ElementCreator

public abstract class ElementCreator extends ParentNodeConstructor

An instruction that creates an element node. There are two subtypes, FixedElement for use where the name is known statically, and Element where it is computed dynamically. To allow use in both XSLT and XQuery, the class acts both as an Instruction and as an Expression.
Field Summary
protected booleaninheritNamespaces
The inheritNamespaces flag indicates that the namespace nodes on the element created by this instruction are to be inherited (copied) on the children of this element.
protected booleanpreservingTypes
Flag set to true if validation=preserve and no schema type supplied for validation
Constructor Summary
ElementCreator()
Construct an ElementCreator.
Method Summary
protected voidcheckContentSequence(StaticContext env)
Check statically whether the content of the element creates attributes or namespaces after creating any child nodes
intcomputeSpecialProperties()
Get the static properties of this expression (other than its type).
ItemevaluateItem(XPathContext context)
Evaluate the constructor, returning the constructed element node.
int[]getActiveNamespaces()
Callback to get a list of the intrinsic namespaces that need to be generated for the element.
intgetImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
ItemTypegetItemType(TypeHierarchy th)
Get the item type of the value returned by this instruction
abstract intgetNameCode(XPathContext context)
Determine (at run-time) the name code of the element being constructed
abstract StringgetNewBaseURI(XPathContext context)
Get the base URI for the element being constructed
booleanisInheritNamespaces()
Determine whether the inherit namespaces flag is set
booleanisPreservingTypes()
Determine whether this elementCreator performs validation or strips type annotations
EventIteratoriterateEvents(XPathContext context)
protected abstract voidoutputNamespaceNodes(XPathContext context, Receiver receiver, int nameCode)
Callback to output namespace nodes for the new element.
TailCallprocessLeavingTail(XPathContext context)
Evaluate the instruction to produce a new element node.
voidprocessLeft(Stack<XPathContext> contextStack, Stack state)
In streaming mode, process the first half of the instruction (to start a new document or element)
voidprocessRight(Stack<XPathContext> contextStack, Stack state)
In streaming mode, proecss the right half of the instruction (to end a new document or element)
voidsetValidationMode(int mode)
Set the validation mode for the new element
voidsuppressValidation(int validationMode)
Suppress validation on contained element constructors, on the grounds that the parent element is already performing validation.

Field Detail

inheritNamespaces

protected boolean inheritNamespaces
The inheritNamespaces flag indicates that the namespace nodes on the element created by this instruction are to be inherited (copied) on the children of this element. That is, if this flag is false, the child elements must carry a namespace undeclaration for all the namespaces on the parent, unless they are redeclared in some way.

preservingTypes

protected boolean preservingTypes
Flag set to true if validation=preserve and no schema type supplied for validation

Constructor Detail

ElementCreator

public ElementCreator()
Construct an ElementCreator. Exists for the benefit of subclasses.

Method Detail

checkContentSequence

protected void checkContentSequence(StaticContext env)
Check statically whether the content of the element creates attributes or namespaces after creating any child nodes

Parameters: env the static context

Throws: XPathException

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

evaluateItem

public Item evaluateItem(XPathContext context)
Evaluate the constructor, returning the constructed element node. If lazy construction mode is in effect, then an UnconstructedParent object is returned instead.

getActiveNamespaces

public int[] getActiveNamespaces()
Callback to get a list of the intrinsic namespaces that need to be generated for the element.

Returns: an array of namespace codes, the codes either occupy the whole array or are terminated by a -1 entry. A result of null is equivalent to a zero-length array.

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.

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the item type of the value returned by this instruction

Parameters: th the type hierarchy cache

Returns: the item type

getNameCode

public abstract int getNameCode(XPathContext context)
Determine (at run-time) the name code of the element being constructed

Parameters: context the XPath dynamic evaluation context

Returns: the integer name code representing the element name

Throws: XPathException if a failure occurs

getNewBaseURI

public abstract String getNewBaseURI(XPathContext context)
Get the base URI for the element being constructed

Parameters: context the XPath dynamic evaluation context

Returns: the base URI of the constructed element

isInheritNamespaces

public boolean isInheritNamespaces()
Determine whether the inherit namespaces flag is set

Returns: true if namespaces constructed on a parent element are to be inherited by its children

isPreservingTypes

public boolean isPreservingTypes()
Determine whether this elementCreator performs validation or strips type annotations

Returns: false if the instruction performs validation of the constructed output or if it strips type annotations, otherwise true

iterateEvents

public EventIterator iterateEvents(XPathContext context)

outputNamespaceNodes

protected abstract void outputNamespaceNodes(XPathContext context, Receiver receiver, int nameCode)
Callback to output namespace nodes for the new element. This method is responsible for ensuring that a namespace node is always generated for the namespace of the element name itself.

Parameters: context The execution context receiver the Receiver where the namespace nodes are to be written nameCode the name code of the element being created

Throws: net.sf.saxon.trans.XPathException

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
Evaluate the instruction to produce a new element node. This method is typically used when there is a parent element or document in a result tree, to which the new element is added.

Parameters: context XPath dynamic evaluation context

Returns: null (this instruction never returns a tail call)

Throws: XPathException

processLeft

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

Parameters: contextStack state a stack on which the instruction can save state information for use during the corresponding

processRight

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

Parameters: contextStack state a stack on which the instruction can save state information for use during the corresponding

setValidationMode

public void setValidationMode(int mode)
Set the validation mode for the new element

suppressValidation

public void suppressValidation(int validationMode)
Suppress validation on contained element constructors, on the grounds that the parent element is already performing validation. The default implementation does nothing.