com.saxonica.functions.hof

## Class CoercedFunction

- java.lang.Object
- - net.sf.saxon.om.AbstractItem
  - - com.saxonica.functions.hof.AbstractFunctionItem
    - - com.saxonica.functions.hof.CoercedFunction

- All Implemented Interfaces:
    PullEvent, Callable, FunctionItem, GroundedValue, Item, Sequence

      public class CoercedFunction
      extends AbstractFunctionItem

  A function item obtained by coercing a supplied function; this adds a wrapper to perform dynamic type checking of the arguments in any call, and type checking of the result.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CoercedFunction(FunctionItem targetFunction)` Create a CoercedFunction as a wrapper around a target function

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Sequence` | `call(XPathContext context, Sequence[] args)` Invoke the function
    `static CoercedFunction` | `coerce(FunctionItem suppliedFunction, SpecificFunctionType requiredType, RoleLocator role, TypeCheckerEnvironment visitor)` Factory method to create a CoercedFunction with a given type, for a given targetFunction.
    `int` | `getArity()` Get the arity of the function
    `FunctionItemType` | `getFunctionItemType(TypeHierarchy th)` Get the item type of the function item
    `StructuredQName` | `getFunctionName()` Get the name of the function, or null if it is anonymous
    `void` | `setArgumentConverter(int arg, Expression converter)` Set the argument converter for one argument
    `void` | `setResultConverter(Expression converter)` Set the converter used to process the returned value
    `void` | `setStackFrameMap(SlotManager stackFrame)` Set the stack frame map identifying the arguments for conversion
    `void` | `typeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)` Type check the function (may modify it by adding code for converting the arguments)

    - ### Methods inherited from class com.saxonica.functions.hof.AbstractFunctionItem

      `deepEquals, effectiveBooleanValue, explain, getStringValue, getStringValueCS, getTypedValue, optimize, simplify`

    - ### Methods inherited from class net.sf.saxon.om.AbstractItem

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

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

      `getLength, itemAt, reduce, subsequence`

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

      `head, iterate`

- - ### Constructor Detail

    - #### CoercedFunction

          public CoercedFunction(FunctionItem targetFunction)

      Create a CoercedFunction as a wrapper around a target function
      Parameters:
        `targetFunction` - the function to be wrapped by a type-checking layer

  - ### Method Detail

    - #### setArgumentConverter

          public void setArgumentConverter(int arg,
                                  Expression converter)

      Set the argument converter for one argument
      Parameters:
        `arg` - identifies the argument to be converted
        `converter` - the expression used to perform the conversion

    - #### setResultConverter

          public void setResultConverter(Expression converter)

      Set the converter used to process the returned value
      Parameters:
        `converter` - the expression used to perform the conversion

    - #### setStackFrameMap

          public void setStackFrameMap(SlotManager stackFrame)

      Set the stack frame map identifying the arguments for conversion
      Parameters:
        `stackFrame` -

    - #### typeCheck

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

      Type check the function (may modify it by adding code for converting the arguments)
      Overrides:
        `typeCheck` in class `AbstractFunctionItem`
      Parameters:
        `visitor` - the expression visitor, supplies context information
        `contextItemType` - the context item type at the point where the function definition appears
      Throws:
        `XPathException`

    - #### getFunctionItemType

          public FunctionItemType getFunctionItemType(TypeHierarchy th)

      Get the item type of the function item
      Parameters:
        `th` -
      Returns:
        the function item's type

    - #### getFunctionName

          public StructuredQName getFunctionName()

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

    - #### getArity

          public int getArity()

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

    - #### call

          public Sequence 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`

    - #### coerce

          public static CoercedFunction coerce(FunctionItem suppliedFunction,
                               SpecificFunctionType requiredType,
                               RoleLocator role,
                               TypeCheckerEnvironment visitor)
                                        throws XPathException

      Factory method to create a CoercedFunction with a given type, for a given targetFunction. It is assumed that we have already established that coercion is needed
      Throws:
        `XPathException`

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