Package net.sf.saxon.expr

## Class UnionConstructorFunction

- java.lang.Object
- - net.sf.saxon.functions.AbstractFunction
  - - net.sf.saxon.expr.UnionConstructorFunction

- All Implemented Interfaces:
    `Callable`, `Function`, `GroundedValue`, `Item`, `Sequence`
  Direct Known Subclasses:
    `UnionCastableFunction`

      public class UnionConstructorFunction
      extends AbstractFunction

  Function to perform a cast to a union type

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected boolean` | `allowEmpty` |
    `protected NamespaceResolver` | `resolver` |
    `protected UnionType` | `targetType` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `UnionConstructorFunction​(UnionType targetType, NamespaceResolver resolver, boolean allowEmpty)` | Create a cast expression to a union type

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `AtomicSequence` | `call​(XPathContext context, Sequence[] args)` | Invoke the function
    `AtomicSequence` | `cast​(AtomicValue value, XPathContext context)` | Method to perform the cast of an atomic value to a union type
    `static AtomicSequence` | `cast​(AtomicValue value, UnionType targetType, NamespaceResolver nsResolver, ConversionRules rules)` | Static method to perform the cast of an atomic value to a union type
    `int` | `getArity()` | Get the arity of the function
    `java.lang.String` | `getDescription()` | Get a description of this function for use in error messages.
    `FunctionItemType` | `getFunctionItemType()` | Get the item type of the function item
    `StructuredQName` | `getFunctionName()` | Get the name of the function, or null if it is anonymous
    `NamespaceResolver` | `getNamespaceResolver()` | Get the namespace resolver that will be used to resolve any namespace-sensitive values (such as QNames) when casting
    `protected OperandRole` | `getOperandRole()` | Get the usage (in terms of streamability analysis) of the single operand
    `UnionType` | `getTargetType()` | Get the union type that is the target of this cast operation
    `boolean` | `isAllowEmpty()` | Ask whether the value of the operand is allowed to be empty

    - ### Methods inherited from class net.sf.saxon.functions.AbstractFunction

      `atomize, deepEquals, effectiveBooleanValue, export, getAnnotations, getOperandRoles, getStringValue, getStringValueCS, isArray, isMap, isTrustedResultType, makeNewContext, simplify, typeCheck`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface net.sf.saxon.om.Function

      `getGenre, toShortString`

    - ### Methods inherited from interface net.sf.saxon.om.GroundedValue

      `asIterable, concatenate, containsNode, materialize`

    - ### Methods inherited from interface net.sf.saxon.om.Item

      `getLength, head, isStreamed, itemAt, iterate, reduce, subsequence`

    - ### Methods inherited from interface net.sf.saxon.om.Sequence

      `makeRepeatable`

- - ### Field Detail

    - #### targetType

          protected UnionType targetType

    - #### resolver

          protected NamespaceResolver resolver

    - #### allowEmpty

          protected boolean allowEmpty

  - ### Constructor Detail

    - #### UnionConstructorFunction

          public UnionConstructorFunction​(UnionType targetType,
                                          NamespaceResolver resolver,
                                          boolean allowEmpty)

      Create a cast expression to a union type
      Parameters:
        `targetType` - the union type that is the result of the cast
        `allowEmpty` - true if an empty sequence may be supplied as input, converting to an empty sequence on output

  - ### Method Detail

    - #### getOperandRole

          protected OperandRole getOperandRole()

      Get the usage (in terms of streamability analysis) of the single operand
      Returns:
        the operand usage

    - #### isAllowEmpty

          public boolean isAllowEmpty()

      Ask whether the value of the operand is allowed to be empty
      Returns:
        true if an empty sequence may be supplied as input, converting to an empty sequence on output

    - #### getTargetType

          public UnionType getTargetType()

      Get the union type that is the target of this cast operation
      Returns:
        the target type of the cast

    - #### getNamespaceResolver

          public NamespaceResolver getNamespaceResolver()

      Get the namespace resolver that will be used to resolve any namespace-sensitive values (such as QNames) when casting
      Returns:
        the namespace resolver, or null if there is none.

    - #### getFunctionItemType

          public FunctionItemType getFunctionItemType()

      Get the item type of the function item
      Returns:
        the function item's type

    - #### getFunctionName

          public StructuredQName getFunctionName()

      Get the name of the function, or null if it is anonymous
      Returns:
        the function name, or null for an anonymous inline function

    - #### getDescription

          public java.lang.String getDescription()

      Get a description of this function for use in error messages. For named functions, the description is the function name (as a lexical QName). For others, it might be, for example, "inline function", or "partially-applied ends-with function".
      Returns:
        a description of the function for use in error messages

    - #### getArity

          public int getArity()

      Get the arity of the function
      Returns:
        the number of arguments in the function signature

    - #### cast

          public AtomicSequence cast​(AtomicValue value,
                                     XPathContext context)
                              throws XPathException

      Method to perform the cast of an atomic value to a union type
      Parameters:
        `value` - the input value to be converted. Must not be null.
        `context` - the evaluation context
      Returns:
        the result of the conversion (may be a sequence if the union includes list types in its membership)
      Throws:
        `XPathException` - if the conversion fails

    - #### call

          public AtomicSequence call​(XPathContext context,
                                     Sequence[] args)
                              throws XPathException

      Invoke the function
      Parameters:
        `context` - the XPath dynamic evaluation context
        `args` - the actual arguments to be supplied
      Returns:
        the result of invoking the function
      Throws:
        `XPathException` - if a dynamic error occurs within the function

    - #### cast

          public static AtomicSequence cast​(AtomicValue value,
                                            UnionType targetType,
                                            NamespaceResolver nsResolver,
                                            ConversionRules rules)
                                     throws XPathException

      Static method to perform the cast of an atomic value to a union type
      Parameters:
        `value` - the input value to be converted. Must not be null.
        `targetType` - the union type to which the value is to be converted
        `nsResolver` - the namespace context, required if the type is namespace-sensitive
        `rules` - the conversion rules
      Returns:
        the result of the conversion (may be a sequence if the union includes list types in its membership)
      Throws:
        `XPathException` - if the conversion fails