Qexo Extensions to XQuery

Qexo has various beyond the XQuery standard:

Calling Java Methods

Qexo (following many XSLT implementations) uses special namespaces to name Java classes. For example:

declare namespace Integer = "class:java.lang.Integer"

You can use this namespace to invoke methods in the Java class java.lang.Integer class:

Integer:toHexString(255)

This invokes the static toHexString(int) method, evaluating to the string "ff".

More generally, if you call a function whose name is a QName for which there is no in-scope function, but the QName's namepace-URI starts with the string class: then the rest of the namespace-URI will be interpreted as a Java class name, and the QName's local-part will be interpreted as a Java method name defined in that Java class. The compiler will look for the "best" matching public method (using the available type information), and try to pick a specific method at compile-time. (If it cannot, it will print a warning message, and instead emit code that try to pick the best method at run-time.) Both static and non-static methods are eligible; for non-static methods the first parameter is used as the this argument.

Specifically how the compiler picks the "best" method is as follows. It finds all the public methods in the named class and its superclasses that match the name and argument count. It first looks for any methods whose parameter types match the actual argument types (to the extent known at compile-time) without requiring any run-time type casts (narrowing). If there is one or more such method, the most specific such method is selected. If there is no most specific method, a warning is printed. Otherwise, if there is a single method that matches, but requiring a run-time cast, that method is selected. Otherwise, a warning is printed, and the most spectic method is selected using the actual run-time argument values.

If the local-name is "new" then a constructor will be picked. For example:

Integer:new("1234")

This is equivalent to the Java expression new Integer("1234"), which creates a new java.lang.Integer instance whose intValue is 1234.

As a convenience, if the QName in a function call has a namespace-prefix for which there is no in-scope namespace definition, but the namespace-prefix is the fully-qualified name of a Java class (existing at compile-time), then that is equivalent to using a class: namespace-uri. For example:

java.lang.Object:toString(3+4)
evaluates to the string 7. The expression is equivalent to:
declare namespace obj = "class:java.lang.Object"
obj:toString(3+4)

assuming obj is some otherwise-unused namespace-prefix.

Implementation-specific functions

These will probably be moved into some Qexo-specific namespace.
index-of(str, pat)
Returns the (one-based) index of the first substring string of str that matches the string pat.
last-index-of(str, pat)
Returns the (one-based) index of the last substring string of str that matches the string pat.
write-to(value, filename)
Writes the value(s) given by value in XML syntax to the file named by filename
iterator-items(iterator)
The iterator must be an instance of java.util.Iterator. Returns the sequence of items generated by the iterator. (The Qexo compiler may re-arrange when the iterator hasNext and next methods are called, so do not assume a partiular evaluation order.)
list-items(list)
The list must be an instance of java.util.List. Returns the sequence of elements in the list.
unescaped-data(string)
Evaluates to a special string that is printed without XML escaping. Thus unescaped-data("<-->") is printed as "<-->" while "<-->" is printed as "&lt;--&gt;".

Servlets

You can compile a Qexo program to a
servlet.
Per Bothner
Last modified: Thu Feb 3 18:37:40 PST 2005