Changes

Jump to navigation Jump to search
96 bytes removed ,  07:28, 13 November 2018
no edit summary
# The last path segment of the URI is capitalized and rewritten to [https://en.wikipedia.org/wiki/CamelCase CamelCase].
The normalization steps are skipped if the URI is prefixed with {{Code|java:}}. See the following examples:
* <code><nowiki>http://basex.org/modules/meta-data</nowiki></code> → <code>org.basex.modules.MetaData</code>
</pre>
If the result of a Java call contains invalid XML characters, it will be rejected. The validity check can be disabled by setting the [[Options#CHECKSTRINGS|CHECKSTRINGS]] option to false. The following query writes In the example below, a file with a single {{Code|00-}} byteis written, which and this file will then be successfully read accessed by via Java functions:
<pre class="brush:xquery">
An alternative solution is to access Java code by ''importing'' classes as modules. A new instance of the addressed class will be created, which can then be referenced in the query body.
The following In the (side-effecting) example returns below, the number size of distinct values added to a Java hash setis returned. The boolean values that are returned by {{Code|set:add()}} will be are swallowed:
<pre class="brush:xquery">
</pre>
The advantages of this approach is the execution of imported classes is more efficient than the execution of instances that are 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 fails if the addressed class has no default constructor, but at least one constructor with arguments.
=Integration=
* Java code is treated as ''focus-independent''. If a function accesses the current context item, position or size, it should be annotated as {{Code|@FocusDependent}}
The In the following XQuery code invokes two Java methods. The first Java function retrieves , information from the static query contextis returned by the first function, and the second one throws a query exceptionis raised by the second function:
<pre class="brush:xquery">
context:user()
},
try { element to-int { try { context:to-int('abc') }} catch basex:error { catch * element error { 'Error in line', $err:line-number description }
}
</pre>
return Integer.parseInt(value);
} catch(NumberFormatException ex) {
throw new QueryException(ex.getMessage()"Integer conversion failed: " + value);
}
}
<pre class="brush:xml">
<user>admin</admin>
<to-interror>Error in line 6Integer conversion failed: abc</to-interror>
</pre>
==Data Types==
The following table lists the mappings of XQuery and Java typesare mapped as follows:
{| class="wikitable"
# If the resulting string ends with a slash, the {{Code|index}} string is appended.
If the resulting path has no file suffix, it may point to either an XQuery module or a Java archive.The following examples show some rewritings:
* {{Code|<nowiki>http://basex.org/modules/hello/World</nowiki>}} → {{Code|org/basex/modules/hello/World}}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu