Changes

Jump to navigation Jump to search
352 bytes added ,  14:56, 12 March 2018
# The [[#EXPath Packaging|EXPath Packaging]] system provides a generic mechanism for adding XQuery modules to query processors. A package is defined as a {{Code|.xar}} archive, which encapsulates one or more extension libraries.
==Accessing Modules==
Library modules can be imported with the {{Code|import module}} statement,
Import module statements must be placed at the beginning of a module:
'''Main Module''' <code>[http://files.basex.org/modules/org/basex/modules/Hello/HelloUniverse.xq HelloUniversehello-universe.xq]</code>:
<pre class="brush:xquery">
import module namespace m = 'http://basex.org/modules/Hellohello' at 'HelloWorldhello-world.xqm';
m:hello("Universe")
</pre>
'''Library Module''' <code>[http://files.basex.org/modules/org/basex/modules/Hello/HelloWorld.xqm HelloWorldhello-world.xqm]</code> (in the same directory):
<pre class="brush:xquery">
</pre>
Repository modules are stored in a directory named {{Code|BaseXRepo}} or the {{Code|repo}}directory, which resides in your [[Configuration#Home Directory|home directory]]. XQuery modules can be manually copied to the repository directory or installed and deleted via [[#Commands|commands]].
If a module has been placed in the repository (see below), there is no need to specify the location. The following example calls a function from the FunctX module:
=Commands=
There are various ways to handle organize your packages:
* Execute BaseX REPO commands (listed below)
* Use the GUI (''Options'' → ''Packages'')
You can even manually add and remove packages in the repository directory; all changes will automatically be detected by the query processorBaseX.
==Installation==
==Listing==
All currently installed packages can be listed with {{Command|REPO LIST}}. It will return the The names of all packagesare listed, along with their version, their package type, and the directory in which they are installedrepository path:
URI Name Version DirectoryType Path ----------------------------------------------------------------- <nowiki>http://www.functx.com</nowiki> 1.0 EXPath http-www.functx.com-1.0 1 package(s).
==Removal==
A package can be deleted with {{Command|REPO DELETE}} and an additional argument, containing its name or the name suffixed with a hyphen and the package version:
REPO DELETE <nowiki>http://www.functx.com</nowiki> ...or...
REPO DELETE <nowiki>http://www.functx.com-1.0</nowiki>
==XQuery==
If an XQuery file is specified as input for the install command, it will be parsed as XQuery library module. If the file can successfully be parsed, the module URI will be [[Java Bindings#URI Rewriting|rewritten]] to a file path and attached with the {{Code|.xqm}} file suffix, and the original file will possibly be renamed and copied to that path into the repository.
'''Example:'''
Java archives (JARs) may contain one or more class files. One of them will be chosen as main class, which must be specified in a {{Code|Main-Class}} entry in the manifest file ({{Code|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 the {{Code|.jar}} file suffix, and the original file will be renamed and copied to that path into the repository.
If the class will be imported in the prolog of the XQuery module, an instance of it will be created, and its public functions can then be addressed from XQuery. A class may extend the {{Code|QueryModule}} class to get access to the current query context and to be enriched by some helpful annotations (see [[Java_Bindings#Context-AwarenessAnnotations|Context-AwarenessAnnotations]]).
'''Example:'''
</pre>
After having installed the module, all of the following URIs can be used in XQuery to import this module or call its functions (see [[Java Bindings#URI Rewriting|URI Rewriting]] for more information):
<nowiki>http://basex.org/modules/Hello</nowiki>
org/basex/modules/Hello
org.basex.modules.Hello
 
===Additional Libraries===
 
{{Mark|Introduced with Version 9.0:}}
 
A Java class may depend on additional libraries. The dependencies can be resolved by creating a fat JAR file, i.e., extracting all files of the library archives and producing a single, flat JAR package.
 
Another solution is to copy the libraries into a {{Code|lib}} directory of the JAR package. If the package will be installed, the additional library archives will be extracted and copied to a hidden sub-directory in the repository. If the package will be deleted, the hidden sub-directory will be removed as well.
 
; Examplary contents of {{Code|Image.jar}}
 
lib/
Images.jar
META-INF/
MANIFEST.MF
org/basex/modules/
Image.class
 
; Directory structure of the repository directory after installing the package
 
org/basex/modules/
Image.class
.Images/
Images.jar
==Combined==
{{Mark|Introduced with Version 9.0:}}:
It makes sense to combine the advantages of XQuery and Java packages:
REPO INSTALL http://files.basex.org/modules/org/basex/modules/Hello.jar
REPO LIST
Name Version Type Path
---------------------------------------------------------------------------------------
org.basex.modules.Hello - Combined org/basex/modules/Hello.xqm
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.
=URI RewritingPerformance=
If a module is looked up Importing XQuery modules that are located in the repository, the namespace URI is rewritten to just as fast as importing any other modules. Modules that are imported several times in a local file path:project will only be compiled once.
# If the URI is a URL:## colons Imported Java archives will be replaced with slashes,## in the URI authority, dynamically added to the order of all substrings separated by dots is reversed, classpath and## dots in the authority and the path are replaced by slashesunregistered after query execution. If no path exists, a single slash is appended.# Otherwise, if the URI is a URN, colons will be replaced with slashes.# Characters other than letters, dots This requires some constant overhead and slashes will be replaced may lead to unexpected effects in scenarios with dasheshighly concurrent read operations.# If the resulting string ends with a slashyou want to get optimal performance, it is recommendable to move your JAR files into the {{Code|indexlib/custom}} string directory of BaseX. This way, the archive will be added to the classpath if BaseX is appendedstarted. If the resulting path has no file suffixyou have installed a [[#Combined|Combined Package]], it may point to either an you can simply keep your XQuery module or a in the repository, and the Java archiveclasses will be automatically detected.The following examples show some rewritings: * {{Code|<nowiki>http://basex.org/modules/hello/World</nowiki>}} → {{Code|org/basex/modules/hello/World}}* {{Code|<nowiki>http://www.example.com</nowiki>}} → {{Code|com/example/www/index}}* {{Code|a/little/example}} → {{Code|a/little/example}}* {{Code|a:b:c}} → {{Code|a/b/c}}
=Changelog=
* Added: [[#Combined|Combined]] XQuery and Java packages
 ;Version 8.2 * Added: [[#URI RewritingAdditional Libraries|URI RewritingAdditional Libraries]]: support for URNs
;Version 7.2.1
* Updated: [[#Installation|Installation]]: existing packages will be replaced without raising an error
* Updated: [[#Removal|Removal]]: remove specific version of a package
* Added: [[#Packaging|Packaging]], [[#URI Rewriting|URI Rewriting]]
;Version 7.1
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu