net.sf.saxon.expr.instruct

## Class ElementCreator

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - net.sf.saxon.expr.instruct.Instruction
    - - net.sf.saxon.expr.instruct.ParentNodeConstructor
      - - net.sf.saxon.expr.instruct.ElementCreator

- All Implemented Interfaces:
    DivisibleInstruction, Serializable, SourceLocator, LocationProvider, SaxonLocator, TailCallReturner, ValidatingInstruction, InstructionInfo, Locator
  Direct Known Subclasses:
    ComputedElement, Copy, FixedElement

      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.
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `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.
    `protected Expression` | `onEmpty` The onEmpty expression is used in XSLT 3.0 to supply an alternative result to be returned when the content of the element (including attributes) is empty.

    - ### Fields inherited from class net.sf.saxon.expr.instruct.ParentNodeConstructor

      `content, preservingTypes`

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

      `EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, EVENT_FEED_METHOD, INHERITED_CONTEXT, INSPECTION_CONTEXT, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, NAVIGATION_CONTEXT, NODE_VALUE_CONTEXT, PROCESS_METHOD, PUSH_SELECTION, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, W3C_CONSUMING, W3C_FREE_RANGING, W3C_GROUP_CONSUMING, W3C_MOTIONLESS, WATCH_METHOD`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ElementCreator()` Construct an ElementCreator.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `checkContentSequence(StaticContext env)` Check statically whether the content of the element creates attributes or namespaces after creating any child nodes
    `int` | `computeSpecialProperties()` Get the static properties of this expression (other than its type).
    `Item` | `evaluateItem(XPathContext context)` Evaluate the constructor, returning the constructed element node.
    `NamespaceBinding[]` | `getActiveNamespaces()` Callback to get a list of the intrinsic namespaces that need to be generated for the element.
    `int` | `getCardinality()` Determine the static cardinality of the expression.
    `abstract NodeName` | `getElementName(XPathContext context, NodeInfo copiedNode)` Determine (at run-time) the name code of the element being constructed
    `int` | `getImplementationMethod()` An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
    `ItemType` | `getItemType(TypeHierarchy th)` Get the item type of the value returned by this instruction
    `abstract String` | `getNewBaseURI(XPathContext context, NodeInfo copiedNode)` Get the base URI for the element being constructed
    `Expression` | `getOnEmpty()` Get the on-empty expression, which defines the value to be returned if the element would otherwise be empty
    `StreamingAdjunct` | `getStreamingAdjunct()` Get a class that supports streamed evaluation of this expression
    `boolean` | `isInheritNamespaces()` Determine whether the inherit namespaces flag is set
    `EventIterator` | `iterateEvents(XPathContext context)` Deliver the result of the expression as a sequence of events.
    `protected EventIterator` | `iterateEvents(XPathContext context, NodeInfo copiedNode)`
    `Iterator<SubExpressionInfo>` | `iterateSubExpressionInfo()` Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.
    `Iterator<Expression>` | `iterateSubExpressions()` Get the immediate sub-expressions of this expression.
    `Expression` | `optimize(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)` Perform optimisation of an expression and its subexpressions.
    `abstract void` | `outputNamespaceNodes(XPathContext context, Receiver receiver, NodeName nameCode, NodeInfo copiedNode)` Callback to output namespace nodes for the new element.
    `TailCall` | `processLeavingTail(XPathContext context)` Evaluate the instruction to produce a new element node.
    `TailCall` | `processLeavingTail(XPathContext context, NodeInfo copiedNode)` Evaluate the instruction to produce a new element node.
    `void` | `processLeft(Stack<XPathContext> contextStack, Stack<Object> state)` In streaming mode, process the first half of the instruction (to start a new document or element)
    `void` | `processRight(Stack<XPathContext> contextStack, Stack<Object> state)` In streaming mode, process the right half of the instruction (to end a new document or element)
    `void` | `setOnEmpty(Expression onEmpty)` Set the on-empty expression, which defines the value to be returned if the element would otherwise be empty
    `Expression` | `simplify(ExpressionVisitor visitor)` Simplify an expression.
    `void` | `suppressValidation(int parentValidationMode)` Suppress validation on contained element constructors, on the grounds that the parent element is already performing validation.
    `Expression` | `typeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)` Perform type checking of an expression and its subexpressions.

    - ### Methods inherited from class net.sf.saxon.expr.instruct.ParentNodeConstructor

      `addToPathMap, computeCardinality, createsNewNodes, getBaseURI, getContentExpression, getSchemaType, getValidationAction, getValidationOptions, isLazyConstruction, isPreservingTypes, promoteInst, replaceSubExpression, setBaseURI, setContentExpression, setLazyConstruction, setNoNeedToStrip, setValidationAction`

    - ### Methods inherited from class net.sf.saxon.expr.instruct.Instruction

      `assembleParams, assembleTunnelParams, dynamicError, evaluateAsString, getConstructType, getExpressionName, getInstructionName, getInstructionNameCode, getIteratorFromProcessMethod, getSourceLocator, isXSLT, iterate, process, promote`

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

      `adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, copy, doPromotion, dynamicError, effectiveBooleanValue, evaluatePendingUpdates, explain, explain, getColumnNumber, getColumnNumber, getContainer, getDependencies, getEvaluationMethod, getExecutable, getExpressionCompiler, getHostLanguage, getIntegerBounds, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getStreamability, getSystemId, getSystemId, hasVariableBinding, implementsStaticTypeCheck, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, markTailFunctionCalls, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, staticTypeCheck, toPattern, toStreamingPattern, 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

    - #### 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.

    - #### onEmpty

          protected Expression onEmpty

      The onEmpty expression is used in XSLT 3.0 to supply an alternative result to be returned when the content of the element (including attributes) is empty. The most common case is to return an empty sequence instead of constructing the element.

  - ### Constructor Detail

    - #### ElementCreator

          public ElementCreator()

      Construct an ElementCreator. Exists for the benefit of subclasses.

  - ### Method Detail

    - #### simplify

          public Expression simplify(ExpressionVisitor visitor)
                              throws XPathException

      Description copied from class: `ParentNodeConstructor`
      Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation does nothing.
      Overrides:
        `simplify` in class `ParentNodeConstructor`
      Parameters:
        `visitor` - an expression visitor
      Returns:
        the simplified expression
      Throws:
        `XPathException` - if an error is discovered during expression rewriting

    - #### typeCheck

          public Expression typeCheck(ExpressionVisitor visitor,
                             ExpressionVisitor.ContextItemType contextItemType)
                               throws XPathException

      Description copied from class: `Expression`
      Perform type checking of an expression and its subexpressions. This is the second phase of static optimization.

      This checks statically that the operands of the expression have the correct type; if necessary it generates code to do run-time type checking or type conversion. A static type error is reported only if execution cannot possibly succeed, that is, if a run-time type error is inevitable. The call may return a modified form of the expression.

      This method is called after all references to functions and variables have been resolved to the declaration of the function or variable. However, the types of such functions and variables may not be accurately known if they have not been explicitly declared.

      If the implementation returns a value other than "this", then it is required to ensure that the location information in the returned expression have been set up correctly. It should not rely on the caller to do this, although for historical reasons many callers do so.

      Overrides:
        `typeCheck` in class `ParentNodeConstructor`
      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 to perform necessary run-time type checks, and to perform other type-related optimizations
      Throws:
        `XPathException` - if an error is discovered during this phase (typically a type error)

    - #### 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 `ParentNodeConstructor`
      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)

    - #### getItemType

          public ItemType getItemType(TypeHierarchy th)

      Get the item type of the value returned by this instruction
      Overrides:
        `getItemType` in class `Instruction`
      Parameters:
        `th` - the type hierarchy cache
      Returns:
        the item type

    - #### getCardinality

          public int getCardinality()

      Description copied from class: `Expression`
      Determine the static cardinality of the expression. This establishes how many items there will be in the result of the expression, at compile time (i.e., without actually evaluating the result.
      Overrides:
        `getCardinality` in class `ParentNodeConstructor`
      Returns:
        one of the values Cardinality.ONE_OR_MORE, Cardinality.ZERO_OR_MORE, Cardinality.EXACTLY_ONE, Cardinality.ZERO_OR_ONE, Cardinality.EMPTY. This default implementation returns ZERO_OR_MORE (which effectively gives no information).

    - #### iterateSubExpressions

          public Iterator<Expression> iterateSubExpressions()

      Description copied from class: `ParentNodeConstructor`
      Get the immediate sub-expressions of this expression.
      Overrides:
        `iterateSubExpressions` in class `ParentNodeConstructor`
      Returns:
        an iterator containing the sub-expressions of this expression

    - #### iterateSubExpressionInfo

          public Iterator<SubExpressionInfo> iterateSubExpressionInfo()

      Description copied from class: `ParentNodeConstructor`
      Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression. Default implementation returns a zero-length array, appropriate for an expression that has no sub-expressions.
      Overrides:
        `iterateSubExpressionInfo` in class `ParentNodeConstructor`
      Returns:
        an iterator containing the sub-expressions of this expression

    - #### 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

    - #### setOnEmpty

          public void setOnEmpty(Expression onEmpty)

      Set the on-empty expression, which defines the value to be returned if the element would otherwise be empty
      Parameters:
        `onEmpty` - the expression to be evaluated if the element would otherwise be empty

    - #### getOnEmpty

          public Expression getOnEmpty()

      Get the on-empty expression, which defines the value to be returned if the element would otherwise be empty
      Returns:
        the on-empty expression if there is one, or null otherwise

    - #### 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

    - #### suppressValidation

          public void suppressValidation(int parentValidationMode)

      Suppress validation on contained element constructors, on the grounds that the parent element is already performing validation. The default implementation does nothing.
      Overrides:
        `suppressValidation` in class `Expression`
      Parameters:
        `parentValidationMode` - the kind of validation being performed on the parent expression

    - #### checkContentSequence

          protected void checkContentSequence(StaticContext env)
                                       throws XPathException

      Check statically whether the content of the element creates attributes or namespaces after creating any child nodes
      Specified by:
        `checkContentSequence` in class `ParentNodeConstructor`
      Parameters:
        `env` - the static context
      Throws:
        `XPathException`

    - #### getElementName

          public abstract NodeName getElementName(XPathContext context,
                                NodeInfo copiedNode)
                                           throws XPathException

      Determine (at run-time) the name code of the element being constructed
      Parameters:
        `context` - the XPath dynamic evaluation context
        `copiedNode` - for the benefit of xsl:copy, the node being copied; otherwise null
      Returns:
        the integer name code representing the element name
      Throws:
        `XPathException` - if a failure occurs

    - #### getNewBaseURI

          public abstract String getNewBaseURI(XPathContext context,
                             NodeInfo copiedNode)

      Get the base URI for the element being constructed
      Parameters:
        `context` - the XPath dynamic evaluation context
        `copiedNode` - the node being copied (for xsl:copy), otherwise null
      Returns:
        the base URI of the constructed element

    - #### outputNamespaceNodes

          public abstract void outputNamespaceNodes(XPathContext context,
                                  Receiver receiver,
                                  NodeName nameCode,
                                  NodeInfo copiedNode)
                                             throws XPathException

      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
        `copiedNode` - the node being copied (for xsl:copy) or null otherwise
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### getActiveNamespaces

          public NamespaceBinding[] getActiveNamespaces()
                                                 throws XPathException

      Callback to get a list of the intrinsic namespaces that need to be generated for the element.
      Returns:
        the set of namespace bindings.
      Throws:
        `XPathException` - if an error occurs

    - #### 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 class `Instruction`
      Returns:
        the implementation method, for example `Expression.ITERATE_METHOD` or `Expression.EVALUATE_METHOD` or `Expression.PROCESS_METHOD`

    - #### iterateEvents

          public EventIterator iterateEvents(XPathContext context)
                                      throws XPathException

      Description copied from class: `Expression`
      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 class `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

    - #### iterateEvents

          protected EventIterator iterateEvents(XPathContext context,
                                    NodeInfo copiedNode)
                                         throws XPathException

      Throws:
        `XPathException`

    - #### processLeavingTail

          public TailCall processLeavingTail(XPathContext context)
                                      throws XPathException

      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.
      Specified by:
        `processLeavingTail` in interface `TailCallReturner`
      Specified by:
        `processLeavingTail` in class `Instruction`
      Parameters:
        `context` - XPath dynamic evaluation context
      Returns:
        null (this instruction never returns a tail call)
      Throws:
        `XPathException`

    - #### processLeavingTail

          public final TailCall processLeavingTail(XPathContext context,
                                    NodeInfo copiedNode)
                                            throws XPathException

      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
        `copiedNode` - null except in the case of xsl:copy, when it is the node being copied; otherwise null
      Returns:
        null (this instruction never returns a tail call)
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### evaluateItem

          public Item evaluateItem(XPathContext context)
                            throws XPathException

      Evaluate the constructor, returning the constructed element node. If lazy construction mode is in effect, then an UnconstructedParent object is returned instead.
      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

    - #### getStreamingAdjunct

          public StreamingAdjunct getStreamingAdjunct()

      Get a class that supports streamed evaluation of this expression
      Overrides:
        `getStreamingAdjunct` in class `Expression`
      Returns:
        the relevant StreamingAdjunct, or null if none is available

    - #### processLeft

          public void processLeft(Stack<XPathContext> contextStack,
                         Stack<Object> state)
                           throws XPathException

      In streaming mode, process the first half of the instruction (to start a new document or element)
      Parameters:
        `contextStack` - the dynamic evaluation context
        `state` - a stack on which the instruction can save state information for use during the corresponding
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### processRight

          public void processRight(Stack<XPathContext> contextStack,
                          Stack<Object> state)
                            throws XPathException

      In streaming mode, process the right half of the instruction (to end a new document or element)
      Parameters:
        `contextStack` - the stack of XPath context objects for the current execution state
        `state` - a stack on which the instruction can save state information for use during the corresponding
      Throws:
        `XPathException` - if a dynamic error occurs

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