Saxon.Api

 

 

Saxon.Api

Class ExtensionFunctionDefinition


public abstract class ExtensionFunctionDefinition

Abstract superclass for user-written extension functions. An extension function may be implemented as a subclass of this class, with appropriate implementations of the defined methods.

More precisely, a subclass of ExtensionFunctionDefinition identifies a family of extension functions with the same (namespace-qualified) name but potentially having different arity (number of arguments).

A user-defined extension function is typically implemented using a pair of classes: a class that extends ExtensionFunctionDefinition, whose purpose is to define the properties of the extension function (in particular, its signature -- the types of its arguments and result); and a class that extends ExtensionFunctionCall, whose purpose is to perform the actual evaluation.

The ExtensionFunctionDefinition is immutable and will normally have a singleton instance for each subclass; this singleton instance is registered with the Processor to associate the name of the extension function with its definition.

The ExtensionFunctionCall has one instance for each call on the extension function appearing in the source code of a stylesheet or query; this instance is created when Saxon calls the method MakeFunctionCall provided by the ExtensionFunctionDefinition object. The instance of ExtensionFunctionCall holds information about the static context of the function call, and its Call method is called (by Saxon) to evaluate the extension function at run-time.

Property Summary

 XdmSequenceType[] ArgumentTypes

Read-only property giving the required types of the arguments to this extension function. If the number of items in the array is less than the maximum number of arguments, then the last entry in the returned ArgumentTypes is assumed to apply to all the rest; if the returned array is empty, then all arguments are assumed to be of type item()*

 bool DependsOnFocus

This property must return true for a subclass if the evaluation of the function makes use of the context item, position, or size from the dynamic context. It should also return true (despite the property name) if the function makes use of parts of the static context that vary from one part of the query or stylesheet to another. Setting the property to true inhibits certain Saxon optimizations, such as extracting the call from a loop, or moving it into a global variable.

 QName FunctionName

Read-only property returning the name of the extension function, as a QName.

 bool HasSideEffects

This property should return true for a subclass if the evaluation of the function has side-effects. Saxon never guarantees the result of calling functions with side-effects, but if this property is set, then certain aggressive optimizations will be avoided, making it more likely that the function behaves as expected.

 int MaximumNumberOfArguments

Read-only property giving the maximum number of arguments in a call to this extension function.

 int MinimumNumberOfArguments

Read-only property giving the minimum number of arguments in a call to this extension function.

 bool TrustResultType

This property may return true for a subclass if it guarantees that the returned result of the function will always be of the declared return type: setting this to true by-passes the run-time checking of the type of the value, together with code that would otherwise perform atomization, numeric type promotion, and similar conversions. If the value is set to true and the value is not of the correct type, the effect is unpredictable and probably disastrous.

 

Method Summary

 ExtensionFunctionCall MakeFunctionCall()

Factory method to create an ExtensionFunctionCall object, representing a specific function call in the XSLT or XQuery source code. Saxon will call this method once it has identified that a specific call relates to this extension function.

 XdmSequenceType ResultType(XdmSequenceType[] ArgumentTypes)

Method returning the declared type of the return value from the function. The type of the return value may be known more precisely if the types of the arguments are known (for example, some functions return a value that is the same type as the first argument). The method is therefore called supplying the static types of the actual arguments present in the call.

 

Property Detail

ArgumentTypes

public abstract XdmSequenceType[] ArgumentTypes {get; }

Read-only property giving the required types of the arguments to this extension function. If the number of items in the array is less than the maximum number of arguments, then the last entry in the returned ArgumentTypes is assumed to apply to all the rest; if the returned array is empty, then all arguments are assumed to be of type item()*

A getter for this property must be implemented in every subclass.

Returns:

An array of XdmSequenceType objects representing the required types of the arguments to the extension function.

DependsOnFocus

public virtual bool DependsOnFocus {get; }

This property must return true for a subclass if the evaluation of the function makes use of the context item, position, or size from the dynamic context. It should also return true (despite the property name) if the function makes use of parts of the static context that vary from one part of the query or stylesheet to another. Setting the property to true inhibits certain Saxon optimizations, such as extracting the call from a loop, or moving it into a global variable.

The default value of this property is false. A getter for this property may be implemented in a subclass to return a different value.

FunctionName

public abstract QName FunctionName {get; }

Read-only property returning the name of the extension function, as a QName.

A getter for this property must be implemented in every subclass.

HasSideEffects

public virtual bool HasSideEffects {get; }

This property should return true for a subclass if the evaluation of the function has side-effects. Saxon never guarantees the result of calling functions with side-effects, but if this property is set, then certain aggressive optimizations will be avoided, making it more likely that the function behaves as expected.

The default value of this property is false. A getter for this property may be implemented in a subclass to return a different value.

MaximumNumberOfArguments

public abstract int MaximumNumberOfArguments {get; }

Read-only property giving the maximum number of arguments in a call to this extension function.

A getter for this property must be implemented in every subclass.

MinimumNumberOfArguments

public abstract int MinimumNumberOfArguments {get; }

Read-only property giving the minimum number of arguments in a call to this extension function.

A getter for this property must be implemented in every subclass.

TrustResultType

public virtual bool TrustResultType {get; }

This property may return true for a subclass if it guarantees that the returned result of the function will always be of the declared return type: setting this to true by-passes the run-time checking of the type of the value, together with code that would otherwise perform atomization, numeric type promotion, and similar conversions. If the value is set to true and the value is not of the correct type, the effect is unpredictable and probably disastrous.

The default value of this property is false. A getter for this property may be implemented in a subclass to return a different value.

Method Detail

MakeFunctionCall

public abstract ExtensionFunctionCall MakeFunctionCall()

Factory method to create an ExtensionFunctionCall object, representing a specific function call in the XSLT or XQuery source code. Saxon will call this method once it has identified that a specific call relates to this extension function.

This method must be implemented in every subclass. The implementation should normally instantiate the relevant subclass of ExtensionFunctionCall, and return the new instance.

Returns:

An instance of the appropriate implementation of ExtensionFunctionCall

ResultType

public abstract XdmSequenceType ResultType(XdmSequenceType[] ArgumentTypes)

Method returning the declared type of the return value from the function. The type of the return value may be known more precisely if the types of the arguments are known (for example, some functions return a value that is the same type as the first argument). The method is therefore called supplying the static types of the actual arguments present in the call.

This method must be implemented in every subclass.

Parameters:

ArgumentTypes -  The static types of the arguments present in the function call

Returns:

An XdmSequenceType representing the declared return type of the extension function