Project

Profile

Help

Saxon Configuration to Recognize Java Extension Functions and Elements : Best Approaches

Added by Anthony Bufort 10 days ago

Hello,

Here is my situation in a nutshell:

I am developing dozens, potentially hundreds of Saxon extension functions and elements. I am doing so in Eclipse and oXygen, and for now, am adding lines to the Saxon config file as I go. Pointing to one element factory is easy enough, but I also need an entry for every function I am exposing. Fine for me as the dev, no problem. But I do not want to burden future users with even a pre-configured Saxon config file, let alone have them manually copy/paste entries into theirs. The former invites potential merge issues between any existing config and mine, and the latter is also a manual process that invites error. I am after the smoothest, best-practice way to auto-configure Saxon for the user given the number of functions I intend to provide.

I am aware of the provisions within the Saxon API for programmatic configuration, of course. However, it remains a question for me of how to leverage that ability without having the user explicitly call an initialization class. I want the user to attach the uber-JAR representing my functionality to the appropriate scenario(s) within oXygen (or have them simply locate the JAR on the classpath if they're processing XSLT in alternate venues) and then from there any needed configuration is handled automatically at Saxon runtime.

Is there an established way to do that? Or am I inviting trouble with classloader voodoo and exposing myself and my users to unnecessary points of failure? I really just want the JAR to be loaded and then an initialization class/method gets automatically called to handle all configuration behind the scenes via the s9api.

And related to this question:

Is that even worth doing??

Considering the number of functions, do I really want to be configuring Saxon to handle all of them every time someone uses something from my uber-JAR? Or is it best for performance, memory, or some other sake, to just include in the config those classes which the user intends to use at the moment?

I am thinking the answer you're going to come back to me with is - 'look, just give them a pre-filled config and let them take care of tweaking it if necessary, attaching it to any oXygen Saxon engine version being used within a scenario or passing it to Saxon via the config switch, and be done with it'.

Curious for your advice. :)

Thanks,

-Tony


Replies (2)

RE: Saxon Configuration to Recognize Java Extension Functions and Elements : Best Approaches - Added by Michael Kay 10 days ago

It's an excellent question and I don't think I know the answer.

Even with the built-in internal functions, there are now so many of them that we have had to think hard about the cost of initialising a data structure to hold details of all of them just in case they are needed; we now try to do that initialization lazily.

You could consider diving into lower-level interfaces for registering function libraries. For example, you could call ProfessionalConfiguration.setExtensionBinder() using your own implementation of FunctionLibrary, or reusing/adapting one of the existing implementations.

RE: Saxon Configuration to Recognize Java Extension Functions and Elements : Best Approaches - Added by Anthony Bufort 9 days ago

Heh, it's funny you should mention that (setExtensionBinder). I was nosing up against all of that in the documentation I was perusing pertaining to research on these questions. Was also researching the rabbit hole that is Java custom classloaders, but as indicated, that doesn't seem a very happy path.

Methinks I am in for more research and experimentation. :)

I'll update this thread with whatever useful information I find, whatever experiments I execute and the like, and any questions or solicitations for feedback I have along the way, if it's all the same to you.

My thanks once again,

-Tony Bufort

    (1-2/2)

    Please register to reply