## net.sf.saxon.instruct
Class ElementCreator

    java.lang.Object
      net.sf.saxon.expr.ComputedExpression
          net.sf.saxon.instruct.Instruction
              net.sf.saxon.instruct.ElementCreator

All Implemented Interfaces:
  Container, Expression, InstructionInfoProvider, java.io.Serializable, javax.xml.transform.SourceLocator

Direct Known Subclasses:
  Copy, Element, FixedElement

public abstract class ElementCreator
extends Instruction

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
`protected Expression` `content`
`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 SchemaType` `schemaType`
`protected AttributeSet[]` `useAttributeSets`
`protected int` `validation`

Fields inherited from class net.sf.saxon.expr.ComputedExpression
`locationId, staticProperties`

Fields inherited from interface net.sf.saxon.expr.Expression
`EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD`

Constructor Summary
`ElementCreator()`

Method Summary
`Expression` `analyze(StaticContext env, ItemType contextItemType)` Perform static analysis of an expression and its subexpressions.
`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` `getCardinality()` Determine the static cardinality of the expression.
`int` `getImplementationMethod()` An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
`ItemType` `getItemType()` Get the item type of the value returned by this instruction
`protected abstract int` `getNameCode(XPathContext context)`
`int` `getValidationMode()` Get the validation mode for the constructed element
`java.util.Iterator` `iterateSubExpressions()` Get the immediate sub-expressions of this expression.
`protected abstract void` `outputNamespaceNodes(XPathContext context, Receiver receiver)` Callback to output namespace nodes for the new element.
`TailCall` `processLeavingTail(XPathContext context)` Evaluate the instruction to produce a new element node
`protected void` `promoteInst(PromotionOffer offer)` Handle promotion offers, that is, non-local tree rewrites.
`void` `setContent(Expression content)` Set the expression that constructs the content of the element
`void` `setValidationMode(int mode)` Set the validation mode for the new element
`Expression` `simplify(StaticContext env)` Simplify an expression.

Methods inherited from class net.sf.saxon.instruct.Instruction
`appendItem, assembleParams, assembleTunnelParams, computeCardinality, dynamicError, dynamicError, effectiveBooleanValue, evaluateAsString, getInstructionInfo, getInstructionNameCode, getSourceLocator, isXSLT, iterate, process, promote`

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

`adoptChildExpression, checkPermittedContents, computeDependencies, computeStaticProperties, dynamicError, dynamicError, getColumnNumber, getConstructType, getDependencies, getExecutable, getIntrinsicDependencies, getLineNumber, getLocationId, getParentExpression, getPublicId, getSpecialProperties, getSystemId, markTailFunctionCalls, resetStaticProperties, setLocationId, setParentExpression, typeError, typeError`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface javax.xml.transform.SourceLocator
`getColumnNumber, getLineNumber, getPublicId, getSystemId`

Methods inherited from interface net.sf.saxon.expr.Expression
`display`

Field Detail

### content

    protected Expression content

### useAttributeSets

    protected AttributeSet[] useAttributeSets

### schemaType

    protected SchemaType schemaType

### validation

    protected int validation

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

Constructor Detail

### ElementCreator

    public ElementCreator()

Method Detail

### setContent

    public void setContent(Expression content)

  Set the expression that constructs the content of the element

### simplify

    public Expression simplify(StaticContext env)
                        throws XPathException

  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 interface `Expression`
  Specified by:
    `simplify` in class `Instruction`
  Returns:
    the simplified expression
  Throws:
    `XPathException` - if an error is discovered during expression rewriting

### analyze

    public Expression analyze(StaticContext env,
                              ItemType contextItemType)
                       throws XPathException

  Perform static analysis of an expression and its subexpressions.

  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 will only be accurately known if they have been explicitly declared.

  Specified by:
    `analyze` in interface `Expression`
  Specified by:
    `analyze` in class `Instruction`
  Parameters:
    `env` - the static context of the expression
  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)

### promoteInst

    protected void promoteInst(PromotionOffer offer)
                        throws XPathException

  Handle promotion offers, that is, non-local tree rewrites.

  Overrides:
    `promoteInst` in class `Instruction`
  Parameters:
    `offer` - The type of rewrite being offered
  Throws:
    `XPathException`

### iterateSubExpressions

    public java.util.Iterator iterateSubExpressions()

  Get the immediate sub-expressions of this expression.

  Specified by:
    `iterateSubExpressions` in interface `Expression`
  Overrides:
    `iterateSubExpressions` in class `ComputedExpression`
  Returns:
    an iterator containing the sub-expressions of this expression

### createsNewNodes

    public final boolean createsNewNodes()

  Determine whether this instruction creates new nodes. This implementation returns true.

  Overrides:
    `createsNewNodes` in class `Instruction`

### getItemType

    public ItemType getItemType()

  Get the item type of the value returned by this instruction

  Specified by:
    `getItemType` in interface `Expression`
  Overrides:
    `getItemType` in class `Instruction`
  Returns:
    the item type

### getCardinality

    public int getCardinality()

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

  Specified by:
    `getCardinality` in interface `Expression`
  Overrides:
    `getCardinality` in class `ComputedExpression`
  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).

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

### setValidationMode

    public void setValidationMode(int mode)

  Set the validation mode for the new element

### getValidationMode

    public int getValidationMode()

  Get the validation mode for the constructed element

### getNameCode

    protected abstract int getNameCode(XPathContext context)
                                throws XPathException

  Throws:
    `XPathException`

### outputNamespaceNodes

    protected abstract void outputNamespaceNodes(XPathContext context,
                                                 Receiver receiver)
                                          throws XPathException

  Callback to output namespace nodes for the new element.

  Parameters:
    `context` - The execution context
    `receiver` - the Receiver where the namespace nodes are to be written
  Throws:
    `XPathException`

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

  Specified by:
    `getImplementationMethod` in interface `Expression`
  Overrides:
    `getImplementationMethod` in class `Instruction`

### processLeavingTail

    public TailCall processLeavingTail(XPathContext context)
                                throws XPathException

  Evaluate the instruction to produce a new element node

  Specified by:
    `processLeavingTail` in class `Instruction`
  Parameters:
    `context` -
  Returns:
    null (this instruction never returns a tail call)
  Throws:
    `XPathException`

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