Changes

Jump to navigation Jump to search
956 bytes added ,  00:13, 6 April 2012
Context-aware classes represent a powerful interface for writing Java modules that are more closely coupled with the BaseX core library.
If an instantiated class inherits the abstract [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/query/QueryModule.java QueryModule] class of BaseX, it will get access to the {{Mono|context}} variable, which is an instance of the [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/query/QueryContext.java QueryContext] class. It provides access to all static and dynamic properties of the current query.Additionally, the default properties of functions can be changed via annotations:
* Java functions can only be executed by users with {{Mono|ADMIN}} permissions. You may annotate a function with {{Mono|Requires(Permission)}} to also make it accessible to other users with less permissions.* Java code is treated as "non-deterministic", as its behavior cannot be predicted from the XQuery processor. You may annotate a function as {{Mono|Deterministic}} if you know that it will have no side-effects and will always yield the same result.* Java code is treated as "context-independent". If a function accesses the query context, it should be annotated as {{Mono|ContextDependent}}* Java code is treated as "focus-independent". If a function accesses the current context item, position or size, it should be annotated as {{Mono|FocusDependent}} The following XQuery code invokes two more Java methods. The first Java function retrieves information from the static query context, and the second one throws a query exception:
<pre class="brush:xquery">
* @return default function namespace
*/
@Requires(Permissions.NONE)
@Deterministic
@ContextDependent
public Str functionNS() {
return Str.get(context.sc.nsFunc);
* @throws QueryException query exception
*/
@Requires(Permissions.NONE)
@Deterministic
public int toInt(final String value) throws QueryException {
try {
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu