Class CoercedFunction

java.lang.Object
net.sf.saxon.functions.AbstractFunction
net.sf.saxon.functions.hof.CoercedFunction
All Implemented Interfaces:
Callable, FunctionItem, GroundedValue, Item, Sequence

public class CoercedFunction extends AbstractFunction
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 Details

    • CoercedFunction

      public CoercedFunction(FunctionItem targetFunction, SpecificFunctionType requiredType, boolean allowReducedArity) throws XPathException
      Create a CoercedFunction as a wrapper around a target function
      Parameters:
      targetFunction - the function to be wrapped by a type-checking layer
      requiredType - the type of the coerced function, that is the type required by the context in which the target function is being used
      allowReducedArity - true if the 4.0 rules apply: the supplied function may have lower arity than the required type
      Throws:
      XPathException - if the arity of the supplied function does not match the arity of the required type
    • CoercedFunction

      public CoercedFunction(SpecificFunctionType requiredType)
      Create a CoercedFunction whose target function is not yet known (happens during package re-loading)
      Parameters:
      requiredType - the type of the coerced function, that is the type required by the context in which the target function is being used
  • Method Details

    • setTargetFunction

      public void setTargetFunction(FunctionItem targetFunction) throws XPathException
      Set the target function
      Parameters:
      targetFunction - the function to be wrapped by a type-checking layer
      Throws:
      XPathException - if the arity of the supplied function does not match the arity of the required type
    • typeCheck

      public void typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
      Type check the function (may modify it by adding code for converting the arguments)
      Overrides:
      typeCheck in class AbstractFunction
      Parameters:
      visitor - the expression visitor, supplies context information
      contextItemType - the context item type at the point where the function definition appears
      Throws:
      XPathException - if type checking of the target function fails
    • 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:
      null indicating that this is 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
    • getAnnotations

      public AnnotationList getAnnotations()
      Get the function annotations. These are the same as the annotations of the base function
      Specified by:
      getAnnotations in interface FunctionItem
      Overrides:
      getAnnotations in class AbstractFunction
      Returns:
      the annotations of the base function
    • 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 - if execution of the function fails
    • export

      public void export(ExpressionPresenter out) throws XPathException
      Export information about this function item to the SEF file
      Specified by:
      export in interface FunctionItem
      Overrides:
      export in class AbstractFunction
      Parameters:
      out - the SEF output destination
      Throws:
      XPathException - if things go wrong