Changes

Jump to navigation Jump to search
824 bytes added ,  08:43, 8 April 2016
no edit summary
The Java Binding feature is an extensibility mechanism which enables developers
to directly access Java variables and execute code from XQuery. Addressed Java code must either be contained in the Java classpath, or it must be located in the [[Repository]].
 
Please bear in mind that the execution of Java code may cause side effects that conflict with the functional nature of XQuery, or may introduce new security risks to your project.
=Identification=
==Classes==
{{Mark|Updated with Version 8.4}}: A Java class is identified by a namespace URI. The original URI is rewritten as follows:
# The [[Repository#URI_Rewriting|URI Rewriting]] steps are applied to the URI.
==Functions and Variables==
A Java variable is retrieved, functions and variables can be referenced and a Java function is invoked, evaluated by a usual the existing XQuery function call. syntax: * The namespace of its QName the function name identifies the Java class, and the .* The local partof the name, which is rewritten to camel case, identifies a variable or function of that class.* The middle dot character (<code>[http://www.fileformat.info/info/unicode/char/b7/index.htm ·/&amp;#xB7;]</code>) is a valid character in XQuery names, but not in Java. It can be used to append exact Java parameter types to the function name. Class types must be referenced by their full path.
{| class="wikitable"
|- valign="top"
| Variable
| <code>Q{java.lang.Integer}MIN_VALUE()</code>| <code>[https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#MAX_VALUE Integer.MIN_VALUE]</code>
|- valign="top"
| Function
| <code>Q{java.lang.Object}hash-code()</code>
| <code>[https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode()object.hashCode()]</code>|- valign="top"| Function with types| <code>Q{java.lang.String}split·java.lang.String·int(';', 3)</code>| <code>[https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#split-java.lang.String-int- string.split(";", 3)]</code>
|}
As XQuery and Java have different type systems, XQuery arguments must be are converted to equivalent Java typesvalues, and the result must be of a Java function is converted back to an XQuery types. A table with all mappings is listed value (see [[#Data Types|at the endData Types]] of this article).
If a Java function is not found, it XQuery values may help need to explicitly be cast your XQuery valuesthe target type. For example, if a Java function expects a primitive {{Code|int}}value, you will need to convert your XQuery integer value integers to {{Code|xs:int}}.
=Namespace Declarations=
</pre>
The advantages of this approach is that imported code is executed faster than instances created at runtime via {{Code|new()}}. A drawback is that no arguments can be passed on to the class constructor. As a consequence, the import only works will fail if the class provides a has at least one constructor with arguments and no argumentsdefault constructor.
=Context-Awareness=
; Version 8.4
* UpdatesUpdated: Rewriting rules
; Version 8.0
* Added: import of Java modules, context awareness
 
[[Category:XQuery]]
[[Category:API]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu