Database Reference
In-Depth Information
There are many, many internal modules of extension functions already provided with
eXist, the vast majority of which are described at a high level in Appendix A . When
you are developing your own modules, these are excellent examples from which to
learn. You can find their source code in the folders $EXIST_HOME/src/org/exist/
xquery/functions
and
$EXIST_HOME/extensions/modules/src/org/exist/xquery/
modules .
If you do choose to write your own internal module for eXist, we strongly recom‐
mend reading both “Developing eXist” on page 483 and “Debugging eXist” on page 488 ,
which will assist you with developing and debugging the Java code of your module
running inside eXist.
Variable Declarations
While we have so far focused on defining functions within an internal module, you
can also declare variables that live within the namespace of the internal module. This
is most useful when your module wishes to expose a number of variables to XQuery
that either represent some static constants or confer some configuration information.
You can define variable declarations in the constructor of your module class that
extends AbstractInternalModule by calling the declareVariable method of the
super class. For example, consider a module that provides mathematical constants:
public class MathConstantsModule extends AbstractInternalModule {
protected final static String NS = "https://math/constants" ;
protected final static String NS_PREFIX = "mc" ;
public MathConstantsModule (
final Map < String , List <? extends Object >> parameters ) {
super ( functions , parameters );
final Variable piApprox =
new VariableImpl ( new QName ( "pi" , NS , NS_PREFIX ));
piApprox . setValue ( new FloatValue ( 22 f / 7 f ));
declareVariable ( piApprox );
final Variable speedOfLightApprox =
new VariableImpl ( new QName ( "speed-of-light" , NS , NS_PREFIX ));
speedOfLightApprox . setValue ( new FloatValue ( 1 f / 299792458 f ));
declareVariable ( speedOfLightApprox );
//...further variable declarations omitted for brevity
}
//...module body omitted for brevity
}
Search WWH ::




Custom Search