[xquery-talk] How do different XQuery products implement modules?
per at bothner.com
Wed Oct 15 19:53:53 PDT 2008
Answers for Qexo:
[I wrote the code a number of years ago, so in some cases my
memory might be off, so I am looking at teh code to refresh
Michael Kay wrote:
> 1. Is the module URI just an arbitrary character string, or does it have any
It can be be arbitrary string, but it is "mangled" to the name of a
"package" in the Java class hierarchy, similar to the JAXB mangling.
> 1a. In particular, is it the location of a resource on the web?
> 2. Do you allow several different modules in the same query to have the same
> module URI?
> 2a. if so, can different "import module" declarations import different
> subsets of these?
Possibly, but it isn't supported or recommended.
> 3. Can users import a module without specifying a location URI?
Yes, but the module has to either have been previously compiled
to a Java class (in the current class path), or the imported
module must have been "registered" with the module manager - which
happens when compiling multiple modules on the same "compilation line".
> If so, how is the module located?
It mangles the namespace to a package name. It then looks for a class
named $ModuleMap$ in that packages. This class contains a list of all
modules whose namespace mangle to this package name. The compiler
loads the $ModuleMap$ class, and selects the modules whose namespace
When a module is compiled, the compiler creates a class in the package
corresponding to the module's URI. The name of the class is a mangling
of the last component of the source file name, within the package
created by mangling the namespace URI. The compiler then updates the
$ModuleMap$ to include the compiled module(s). If $ModuleMap$ already
exists, then the class is first is loaded so the old contents can be
merged into the $ModuleMap$ that gets written out.
> 4. If import module specifies a location URI, is it used, and if so how?
A source file is looked for. It also mangles the source file name
and the namespace URI to yield a class name, and looks for that as well.
It will work if it finds either. If both are found, it will compre
> 5. If import module specifies more than one location URI, how are they used?
Each location URI must map to a module; all are loaded.
> 5b. If multiple location URIs are allowed, what happens if
> import module specifies the same location URI more than once?
Hm. That should be an error, but I don't think I test that,
> 6. What happens when two modules A and B both import module URI M
> 6a. specifying the same location URI
> 6b. specifying different location URIs
Not sure - it should be an error.
> 6c. without specifying a location URI
Same module, found using mangled class - see 3,
> 7. Is it possible (by means of multiple imports) to create two different
> "instances" of the same module in a query, with distinct values of global
> variables, or do all imports get the same instance with a common set of
The latter. By default a module variables are compiled to static fields
of the module class, so they're inherently shared. There is a compiler
option to compile to instance variables. In that case a single "module
instance" will be allocated, global to the current "module context".
per at bothner.com http://per.bothner.com/
More information about the talk