Patch #1421
closedmiscellaneous improvements to FunctionProxy.java
0%
Description
SourceForge user: gschadow
Michael, please consider the attached patch to
FunctionProxy.java. It does a number of improvements.
- The rendition of retrurned java nulls to empty
sequences (as discussed earlier.)
- Adding a debug clause in which the actual calling of a
method is announced (with the -TJ flag.) BTW: would be
nice if the TraceListener would handle these XPath
expression-level tracings too.
- Nesting exceptions thrown from extension functions
inside the XPathException. Previously the
XPathExceptions came without a trace as to what went
wrong inside the extension funcitons!
- Add support for member fields to be accessed. This is
the bulk of the patch and described in detail below.
Problem: Often a class' methods use static final fields as
enumeration values to act as modifiers to a method call.
Even though these are typically int or other values that
could be submitted without reference to the static final
field, it is unsafe to do so because these values may
change with changing (versions of) the class
implementation.
Solution: This solution treats member fields as functions
with no arguments. For example, if class oracle.sql.CLOB
has the static final int DURATION_SESSION, then this
value can be accessed through:
<xsl:sequence xmlns:clob="java:oracle.sql.CLOB"
select="clob:DURATION_SESSION()"/>
I implemented this solution in analogy to the Method
handling, and it works for both static and instance fields
as one would expect (using an argument with the object
whose field is being accessed.)
Clearly this doesn't allow assignments to fields, but such
assignments are exceedingly unneccessary since most
objects (except for some odd java.awt struct-like
objects) will have proper mutator methods.
Alternatives: As an alternative, I would have liked to
implement such static field references as variables, e.g.,
the above example would look like this:
<xsl:sequence xmlns:clob="java:oracle.sql.CLOB"
select="$clob:DURATION_SESSION"/>
however, I still don't quite understand how variables are
implemented in saxon and this wouldn't work for instance
fields anyway. In order to allow setting instance fields
one could imagine a pair of functions getf(object,string)
and setf(object,string,object), but setting instance
fields is not so important.
I'd appreciate if you could accept these patches in
principle.
thank you,
-Gunther
Files
Please register to edit this issue