With any report generator, it is likely that customisation will be required. To facilitate this, new xqDocA outputs can be added to the system without modifications to the driver code. A plug-in system is provided using the dynamic loading of code modules.
This is done using custom annotations within the xqDocA code base. Functions that generate xqDocA output must have annotations in the xqDocA namespace indicating their role. At runtime, a designated directory is scanned for XQuery modules, and functions containing the appropriate annotations can be invoked without requiring any other code changes.
Three annotations are defined in the xqDocA namespace,
"https://github.com/Quodatum/xqdoca"
.
Table 3. xqDocA annotations
Name | Description | Parameters |
---|---|---|
xqdoca:global | Indicates a global renderer | (name for reference, description) |
xqdoca:module | Indicates a module renderer | (name for reference, description) |
xqdoca:output | Serialization details | (output uri, serialization type) |
Note | |
---|---|
A function will have one of |
Sample usage:
declare %xqdoca:module("module","Html5 report on the XQuery source") %xqdoca:output("index.html","html5") function xqh:xqdoc-html2($file as map(*), $opts as map(*), $model as map(*) ) as document-node()
or
declare %Q{https://github.com/Quodatum/xqdoca}global("swagger1", "Swagger file (JSON format) from restxq annotations.") %Q{https://github.com/Quodatum/xqdoca}output("swagger.json","json") function _:swagger($model as map(*), $opts as map(*) )
In order to enable runtime selection of code based on function annotations the following features must be provided by the XQuery environment:
Dynamic module loading. This is standardised in the XQuery 3.1
specification as fn:load-xquery-module
. Currently, this
feature is not widely supported; however, many implementation have
custom variants that provide equivalent functionality.
Annotation introspection. That is the ability at runtime to determine what annotations are attached to a function. This is not a feature with any standardisation but again is widely supported via vendor libraries. See Saxon [10], MarkLogic [11], BaseX [12], and eXist-db [14].