Class UnionConstructorFunction

java.lang.Object
net.sf.saxon.functions.AbstractFunction
net.sf.saxon.expr.UnionConstructorFunction
All Implemented Interfaces:
Callable, FunctionItem, GroundedValue, Item, Sequence
Direct Known Subclasses:
UnionCastableFunction

public class UnionConstructorFunction extends AbstractFunction
Function to perform a cast to a union type
  • Field Details

    • targetType

      protected UnionType targetType
    • resolver

      protected NamespaceResolver resolver
    • allowEmpty

      protected boolean allowEmpty
  • Constructor Details

    • 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
      resolver - used for resolving namespace prefixes if the type is namespace-sensitive
      allowEmpty - true if an empty sequence may be supplied as input, converting to an empty sequence on output
  • Method Details

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