Let's try to answer your question "is there another way to do this?", and ignore the curious problem of the Xalan xpath class in which the failure occurred.
 
The new "integrated extension function" mechanism in 9.2 is ideally suited to this kind of situation. It gives you much better capability to design extension functions that look exactly like built-in functions as far as the stylesheet/query/xpath author is concerned.
 
With 9.1 you could do this by writing your own extension function binder, but this would be far more complicated.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Rob Brown [mailto:rlb.south@gmail.com]
Sent: 30 April 2010 19:50
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Alternative to java extension functions?

Hello,

I'm hoping there is another design idea I can use for this problem. I have to implement xpath functions that map to various xforms functions for our users. My solution was to use java extension functions and do some mapping between my own java namespace and what the users see (i.e. the users see xforms functions but I map these before evaluation to my own java namespace).

The main problem is that I cannot change the function signature. This means I cannot use java extension functions that access instance methods (which require an extra parameter) and I have to use an awful hack that uses static methods. Basically I store an instance of my value resolver in a synchronized static field and map static java extension functions to this object. Ugly, but at least it worked until now.

Now I find this is failing when I try to run the app in Amazon's cloud environment. Somewhere inside jaxp classes as called by saxon (com.sun.org.apache.xpath.internal.functions.FuncExtFunction.execute(FuncExtFunction.java:206)) I'm getting a NullPointerException. Just to be clear, this app runs fine outside of the virtualized Amazon environment. I suspect the root cause is how jaxp classes are being loaded because I've seen that happen with jaxp in other VPS enviornments.

Whatever the cause, I'm hoping that if I redesign this hack I can clean up my code and hopefully make this bug disappear.

Is there another design alternative to implementing xforms (or similar) functions in xpath? I'm ok using s9 exclusively if that will help - jaxp causes me nothing but trouble so I'm ready to toss it out the window anyway. The function signatures (now(), index(), instance(), etc.) cannot be changed, require object instances to resolve, and I need to evaluate them within xpath alone (i.e. not within xslt or xquery).

I hope there is an answer because it looks like we can't host our application in Amazon if this doesn't get resolved.

Thanks