Converts a Java external object to a map, giving access to the instance methods of the object as dynamic functions.
object-map($object as jt:java.lang.Object) ➔ map(xs:string, function(*))
The supplied external object
Notes on the Saxon implementation
Available since Saxon 9.9.
The map returned by the function is as follows:
- There is one entry named "this" whose value is a zero-arity function that returns
- For each non-static public method defined on the object's class, provided the name of the method is unique, there will be an entry whose key is the method name, and whose value is a (dynamic) function corresponding to the method. The arguments expected by the function correspond to the arguments declared for the method, and the result returned by the function similarly corresponds to the result of the method.
- For each non-static public method defined on the object's class, provided the
combination of the method's name and arity is unique, there will be an entry whose key has
MMMis the method name, and
Nis the arity: for example if the object were an instance of
java.lang.String, there would be an entry with key
split_1and another with key
split_2corresponding to the two versions of the
String.split()method. There would be no entry for
replace_2because there are two arity-2 methods named
The type conversions for the arguments and return values of the dynamic functions work in the same way
as for other reflexive extension functions: see Converting Arguments.
void=this convention is used: that is, a Java method whose declared return type is
is translated to a function that returns the target object as its result, to make it easier to write code that
uses function chaining.
This function is called implicitly when an external object appears as the left-hand operand of the
lookup operator "?". This means that, for example,
returns the string
For more complex use cases, the function can be called explicitly. For example, this query:declare namespace StreamSource = "java:javax.xml.transform.stream.StreamSource"; declare namespace map = "http://www.w3.org/2005/xpath-functions/map"; StreamSource:new() => saxon:object-map() => map:keys() => sort()
produces:"equals", "equals_1", "getClass", "getClass_0", "getInputStream", "getInputStream_0", "getPublicId", "getPublicId_0", "getReader", "getReader_0", "getSystemId", "getSystemId_0", "hashCode", "hashCode_0", "notify", "notifyAll", "notifyAll_0", "notify_0", "setInputStream", "setInputStream_1", "setPublicId", "setPublicId_1", "setReader", "setReader_1", "this", "toString", "toString_0", "wait_0", "wait_1", "wait_2"