Database Reference
In-Depth Information
We have to return a string that describes which version of eXist this module
became available in. This is just for documentation purposes and is not further
processed.
To implement the actual “Hello World” function, which will be named
hello-world
,
we need to extend the abstract class class
org.exist.xquery.Function
. To assist in
this, eXist provides the abstract subclass
org.exist.xquery.BasicFunction
, which
makes life much easier by dealing with the necessary mechanics for the
XQuery pro‐
filer
and extracting argument values that are passed to our function from the
XQuery
context
. Almost all of the internal module functions already implemented in eXist
extend
BasicFunction
, and we would recommend that you do the same unless you
need more control over processing (which is unlikely in most use cases). So now that
we have seen the preceding internal module implementation, which tells eXist about
our
hello-world
function, let's see how we actually implement the function in
Example 16-14
.
Example 16-14. HelloWorld Java XQuery function
public
class
HelloFunctions
extends
BasicFunction
{
private
final
static
QName
qnHelloWorld
=
new
QName
(
"hello-world"
,
HelloModule
.
NS
,
HelloModule
.
NS_PREFIX
);
//signature of our XQuery h:hello-world() function
public
final
static
FunctionSignature
FNS_HELLO_WORLD
=
new
FunctionSignature
(
qnHelloWorld
,
"Say \”hello world\”!"
,
null
,
new
FunctionReturnSequenceType
(
Type
.
DOCUMENT
,
Cardinality
.
ONE
,
"The hello!"
)
);
//standard constructor, which allows multiple functions to be
//implemented in one class
public
HelloFunctions
(
final
XQueryContext
context
,
final
FunctionSignature
signature
)
{
super
(
context
,
signature
);
}
//called when the xquery function is executed
@Override
public
Sequence
eval
(
final
Sequence
[]
args
,
final
Sequence
contextSequence
)
throws
XPathException
{
final
Sequence
result
;
Search WWH ::
Custom Search