net.sf.saxon.functions

Class ExtensionFunctionDefinition

public abstract class ExtensionFunctionDefinition extends Object implements Serializable

This abstract class is provided to allow user-written extension functions to be implemented with the full capabilities of functions that are an intrinsic part of the Saxon product. In particular, the class has the opportunity to save data from the static context and to optimize itself at compile time.

There should be one class implementing this interface for each function name; if there are several functions with the same name but different arity, the same class should implement them all.

Note that an IntegratedFunction is trusted; calls are allowed even if the configuration option ALLOW_EXTERNAL_FUNCTIONS is false. In cases where an IntegratedFunction is used to load and execute untrusted code, it should check this configuration option before doing so.

Since: 9.2

Method Summary
booleandependsOnFocus()
Ask whether the result of the function depends on the focus
abstract SequenceType[]getArgumentTypes()
Get the required types for the arguments of this function.
ObjectgetCompilerForJava()
Return an object capable of compiling this IntegratedFunction call to Java source code.
abstract StructuredQNamegetFunctionQName()
Get the name of the function, as a QName.
intgetMaximumNumberOfArguments()
Get the maximum number of arguments allowed by the function.
abstract intgetMinimumNumberOfArguments()
Get the minimum number of arguments required by the function

This method must be implemented in all subclasses

abstract SequenceTypegetResultType(SequenceType[] suppliedArgumentTypes)
Get the type of the result of the function

This method must be implemented in all subtypes.

booleanhasSideEffects()
Ask whether the function has side-effects.
abstract ExtensionFunctionCallmakeCallExpression()
Create a call on this function.
booleantrustResultType()
Ask whether the result actually returned by the function can be trusted, or whether it should be checked against the declared type.

Method Detail

dependsOnFocus

public boolean dependsOnFocus()
Ask whether the result of the function depends on the focus

Returns: true if the result of the function depends on the context item, position, or size. The default implementation returns false. This must be set to true if the function makes use of any of these values from the dynamic context. If this is not done, it is possible that the function will be called with incorrect values for the focus.

getArgumentTypes

public abstract SequenceType[] getArgumentTypes()
Get the required types for the arguments of this function.

This method must be implemented in all subtypes.

Returns: the required types of the arguments, as defined by the function signature. Normally this should be an array of size getMaximumNumberOfArguments; however for functions that allow a variable number of arguments, the array can be smaller than this, with the last entry in the array providing the required type for all the remaining arguments.

getCompilerForJava

public Object getCompilerForJava()
Return an object capable of compiling this IntegratedFunction call to Java source code. The returned object may be null, in which case Java code generation is not supported for this IntegratedFunction. If the returned object is not null, it must implement the interface com.saxonica.codegen.IntegratedFunctionCompiler. The default implementation returns null

Returns: an instance of com.saxonica.codegen.IntegratedFunctionCompiler that generates Java code to implement the call on this extension function

getFunctionQName

public abstract StructuredQName getFunctionQName()
Get the name of the function, as a QName.

This method must be implemented in all subclasses

Returns: the function name

getMaximumNumberOfArguments

public int getMaximumNumberOfArguments()
Get the maximum number of arguments allowed by the function.

The default implementation returns the value of ExtensionFunctionDefinition

Returns: the maximum number of arguments that may be supplied in a call to this function

getMinimumNumberOfArguments

public abstract int getMinimumNumberOfArguments()
Get the minimum number of arguments required by the function

This method must be implemented in all subclasses

Returns: the minimum number of arguments that must be supplied in a call to this function

getResultType

public abstract SequenceType getResultType(SequenceType[] suppliedArgumentTypes)
Get the type of the result of the function

This method must be implemented in all subtypes.

Parameters: suppliedArgumentTypes the static types of the supplied arguments to the function. This is provided so that a more precise result type can be returned in the common case where the type of the result depends on the types of the arguments.

Returns: the return type of the function, as defined by its function signature

hasSideEffects

public boolean hasSideEffects()
Ask whether the function has side-effects. If the function does have side-effects, the optimizer will be less aggressive in moving or removing calls to the function. However, calls on functions with side-effects can never be guaranteed.

Returns: true if the function has side-effects (including creation of new nodes, if the identity of those nodes is significant). The default implementation returns false.

makeCallExpression

public abstract ExtensionFunctionCall makeCallExpression()
Create a call on this function. This method is called by the compiler when it identifies a function call that calls this function.

trustResultType

public boolean trustResultType()
Ask whether the result actually returned by the function can be trusted, or whether it should be checked against the declared type.

Returns: true if the function implementation warrants that the value it returns will be an instance of the declared result type. The default value is false, in which case the result will be checked at run-time to ensure that it conforms to the declared type. If the value true is returned, but the function returns a value of the wrong type, the consequences are unpredictable.