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 be enriched with two internalget access to the {{Mono|context}} variable, context-dependent variableswhich 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.
* {{Mono|context}} 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.* {{Mono|input}} is an instance of [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/util/InputInfo.java InputInfo]. It is mainly used to generate better error messages with line and column information. The following XQuery code invokes two context-aware more Java methods:
<pre class="brush:xquery">
* {@link QueryModule} class.
*/
public class ContextModule extends org.basex.query.QueryModule {
/**
* Returns the root expression of this query as stringdefault function namespace. * @return root expressiondefault function namespace
*/
public String functionNamespaceStr functionNS() { return TokenStr.stringget(context.sc.nsFunc);
}
return Integer.parseInt(value);
} catch(NumberFormatException ex) {
throw new QueryException(input, new QNm("FORM0001"), ex.getMessage());
}
}