Database Reference
In-Depth Information
tions of zero or more atomic values and/or nodes. Each item in the Java array of
Sequence
objects represents an individual parameter that was passed to your XQuery
function; even though these are
Sequence
objects, you will have already declared the
type and cardinality of the parameters for your function in its
FunctionSignature
for the internal module.
Now let's look at defining a function signature for a function that allows one person
to say hello to many other people. This function potentially needs to know:
• The name of the person who is saying hello.
• The names of the people she is saying hello to.
• We could also optionally allow the greeting to be customized so that instead of
saying “Hello,” she could say “Bonjour” or use any other desired form of greet‐
ing.
If we imagine the function signature for such an XQuery function, it might look
something like:
h:say-hello
(
$
greeter
as
xs:string
,
$
greeting
as
xs:string
?
,
$
visitors
as
xs:string
+
)
as
xs:string
+
Such a function could be called like so:
xquery
version
"1.0"
;
declare
namespace
h
=
"http://hello"
;
h:say-hello
(
"adam"
,
"Hi"
(
"Erik"
,
"Simon"
))
and we might expect to see a result similar to:
(
"Adam says Hi to Erik"
,
"Adam says Hi to Simon"
)
Now that we know what we want our XQuery function to do and we know what the
signature should look like, we need to implement this in our internal module just as
we did before (in
Example 16-14
) by defining another
FunctionSignature
:
private
final
static
QName
qnSayHello
=
new
QName
(
"say-hello"
,
HelloModule
.
NS
,
HelloModule
.
NS_PREFIX
);
public
final
static
FunctionSignature
FNS_SAY_HELLO
=
new
FunctionSignature
(
qnSayHello
,
"Say \"hello world\"!"
,
new
SequenceType
[]
{
new
FunctionParameterSequenceType
(
"greeter"
,
Type
.
STRING
,
Cardinality
.
EXACTLY_ONE
,
"The greeter, i.e. the name of the person that is saying 'hello'."
),
new
FunctionParameterSequenceType
(
"greeting"
,
Search WWH ::
Custom Search