Database Reference
In-Depth Information
Java binding
eXist allows you to make arbitrary calls to Java libraries using the so-called Java bind‐
ing . For example:
declare namespace javasystem = "java:java.lang.System" ;
declare namespace javamath = "java:java.lang.Math" ;
javasystem:getenv ( 'JAVA_HOME' ),
javamath:sqrt ( 2 )
For security reasons, the Java binding is disabled by default. If you want to use it, edit
$EXIST_HOME/conf.xml , search for the enable-java-binding attribute, set its value
to "yes" , and restart eXist for the change to take effect.
There are some specifics you need to know about when using the Java binding:
• If the function name in XQuery contains a hyphen, the hyphen is removed and
the character following it is converted to uppercase. So, a call in XQuery to to-
string will call the Java method toString .
• Java constructors can be called using the new function.
• eXist adds a generic type, object , to its data-model, which is used for all Java
objects.
• Instance methods of a class (methods that work on a specific object, like most of
the Java methods) must get the object reference as their first parameter.
• When a method returns an array, it is converted to a sequence and you can iter‐
ate over it using a FLWOR expression.
Here is an example that will return a list containing the names of all files and subdir‐
ectories in the $EXIST_HOME directory:
declare namespace javafile = "java:java.io.File" ;
let $ fobject as object := javafile:new ( system:get-exist-home ())
return
for $ file in javafile:list ( $ fobject )
return
$ file
If you only want to get a list of files and directories, it is probably
easier to use the file extension module instead of the Java bind‐
ing.
Search WWH ::




Custom Search