com.saxonica.hof
Class CoercedFunction

java.lang.Object
  extended by com.saxonica.hof.AbstractFunctionItem
      extended by com.saxonica.hof.CoercedFunction
All Implemented Interfaces:
Serializable, PullEvent, FunctionItem, Item, ValueRepresentation

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.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
 
Constructor Summary
CoercedFunction(FunctionItem targetFunction)
          Create a CoercedFunction as a wrapper around a target function
 
Method Summary
static CoercedFunction coerce(FunctionItem suppliedFunction, FunctionType requiredType, RoleLocator role, ExpressionVisitor 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()
          Get the item type of the function item
 StructuredQName getFunctionName()
          Get the name of the function, or null if it is anonymous
 ValueRepresentation invoke(ValueRepresentation[] args, XPathContext context)
          Invoke the function
 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
 
Methods inherited from class com.saxonica.hof.AbstractFunctionItem
bind, curry, explain, getStringValue, getStringValueCS, getTypedValue, optimize, typeCheck
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 -

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

getArity

public int getArity()
Get the arity of the function

Returns:
the number of arguments in the function signature

invoke

public ValueRepresentation invoke(ValueRepresentation[] args,
                                  XPathContext context)
                           throws XPathException
Invoke the function

Parameters:
args - the actual arguments to be supplied
context - the XPath dynamic evaluation context
Returns:
the result of invoking the function
Throws:
XPathException

coerce

public static CoercedFunction coerce(FunctionItem suppliedFunction,
                                     FunctionType requiredType,
                                     RoleLocator role,
                                     ExpressionVisitor 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) Saxonica Limited. All rights reserved.