Changes

Jump to navigation Jump to search
No change in size ,  15:13, 26 May 2012
m
Text replace - "{{Mono|" to "{{Code|"
# With {{Version|7.2.1}}, we offer a simple [[#Packaging|packaging]] mechanism to directly install single XQuery and Java modules to the repository.
# The [[#EXPath Packaging|EXPath Packaging]] system provides a generic mechanism for adding XQuery modules to query processors. A package is defined as a {{MonoCode|.xar}} archive, which encapsulates one or more extension libraries.
==Usage==
All packages are stored in the ''repository''. The repository is a directory named {{MonoCode|BaseXRepo}} or {{MonoCode|repo}}, which resides in your [[Configuration#Home Directory|home directory]]. BaseX provides three commands for interaction with the package repository: <code>[[Commands#REPO_INSTALL|REPO INSTALL]]</code>, <code>[[Commands#REPO_DELETE|REPO DELETE]]</code>, and <code>[[Commands#REPO_LIST|REPO LIST]]</code>. Packages can also be managed from within XQuery, using the [[Repository Module]].
===Installation===
A module or package can be installed with the {{MonoCode|REPO INSTALL}} command. The path to the file has to be given as a parameter, as the following two examples demonstrate:
REPO INSTALL http://files.basex.org/modules/functx-1.0.xar
===XQuery===
If an XQuery file is specified as input for the install command, it will be parsed as XQuery module. If parsing was successful, the module URI will be [[#URI Rewriting|rewritten]] to a file path and attached with the {{MonoCode|.xqm}} file suffix, and the original file will be renamed and copied to that path into the repository.
'''Example:'''
</pre>
Installation (the original file will be copied to {{MonoCode|org/basex/modules/Hello.xqm}}):
REPO INSTALL HelloWorld.xqm
===Java===
Suitable JAR archives may contain one or more class files. One of them will be chosen as main class, which must be specified in a {{MonoCode|Main-Class}} entry in the manifest file ({{MonoCode|META-INF/MANIFEST.MF}}). This fully qualified Java class name will be rewritten to a file path by replacing the dots with slashes and attaching with the {{MonoCode|.jar}} file suffix, and the original file will be renamed and copied to that path into the repository.
The public functions of this class can then be addressed from XQuery, using the class or file path as namespace URI, or an alternative writing that can be [[#URI Rewriting|rewritten]] to the module file path. Moreover, a class may extend the {{MonoCode|QueryModule}} class to get access to the current query context and to be enriched by some helpful annotations (please consult [[Java_Bindings#Context-Awareness|Context Awareness of Java Bindings]] for more information).
'''Example:'''
Hello.class
Contents of the file {{MonoCode|MANIFEST.mf}} (the whitespaces are obligatory):
Manifest-Version: 1.0
Main-Class: org.basex.modules.Hello
Contents of the file {{MonoCode||Hello.java}} (comments removed):
<pre class="brush:java">
</pre>
Installation (the file will be copied to {{MonoCode|org/basex/modules/Hello.jar}}):
REPO INSTALL HelloWorld.jar
===XQuery===
Apart from the package descriptor, a {{MonoCode|.xar}} archive contains a directory which includes the actual XQuery modules. For example, the [http://www.functx.com/ FunctX XQuery Library] is packaged as follows:
<pre>
</pre>
As it can be seen, the class {{MonoCode|Printer}} is declared with its binary name as a namespace prefixed with "java" and the XQuery function is implemented using the [http://docs.basex.org/wiki/Java_Bindings Java Bindings] offered by BaseX.
On our [http://files.basex.org/modules/ file server], you can find some example libraries packaged as XML archives (xar files). You can use them to try our packaging API or just as a reference for creating your own packages.
1. If a URI authority exists, it is reversed, and its dots are replaced by slashes.<br/>
2. The URI path is appended. If no path exists, a single slash is appended instead.<br/>
3. If the resulting string ends with a slash, the {{MonoCode|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:
* {{MonoCode|<nowiki>http://basex.org/modules/hello/World</nowiki> → org/basex/modules/hello/World}}* {{MonoCode|<nowiki>http://www.example.com</nowiki> → com/example/www/index}}* {{MonoCode|a/little/example.xq → a/little/example.xq}}
==Changelog==
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu