Writing extension functions in Java

Saxon provides three mechanisms for writing extension functions in Java:

  • The simple interface allows you to create an extension function by writing a class that implements the interface net.sf.saxon.s9api.ExtensionFunction, and registering your implementation with the net.sf.saxon.s9api.Processor object.

  • The full interface allows you to create an extension function by writing a class that implements the interface net.sf.saxon.s9api.ExtensionFunctionDefinition, and registering your implementation with the net.sf.saxon.s9api.Processor object. This interface is considerably more complex, but it gives more capability: in particular it allows the function full access to the XPath static and dynamic context.

  • The reflexive interface allows you to call arbitrary Java code (public methods in public classes found on the classpath) directly. This mechanism requires Saxon-PE or -EE. There are complex rules for mapping XPath function names to Java class and method names, and for converting between Java data types and XPath data types.

    Reflexive extension functions pose a security risk, because an untrusted stylesheet or query can make calls to Java methods that expose information on your web server (for example, they can read and write files in filestore). Unless the stylesheet or query is trusted, they should therefore be disabled: see ALLOW_EXTERNAL_FUNCTIONS.