net.sf.saxon.s9api
Class XQueryCompiler
java.lang.Object
net.sf.saxon.s9api.XQueryCompiler
public class XQueryCompiler
extends java.lang.Object
An XQueryCompiler object allows XQuery 1.0 queries to be compiled. The compiler holds information that
represents the static context for the compilation.
To construct an XQueryCompiler, use the factory method
Processor.newXQueryCompiler()
.
An XQueryCompiler may be used repeatedly to compile multiple queries. Any changes made to the
XQueryCompiler (that is, to the static context) do not affect queries that have already been compiled.
An XQueryCompiler may be used concurrently in multiple threads, but it should not then be modified once
initialized.
XQueryCompiler
protected XQueryCompiler(Processor processor)
Protected constructor
processor
- the Saxon Processor
compile
public XQueryExecutable compile(String query)
throws SaxonApiException
Compile a query supplied as a string
query
- the text of the query
- an XQueryExecutable representing the compiled query
declareNamespace
public void declareNamespace(String prefix,
String uri)
Declare a namespace binding as part of the static context for queries compiled using this
XQueryCompiler. This binding may be overridden by a binding that appears in the query prolog.
The namespace binding will form part of the static context of the query, but it will not be copied
into result trees unless the prefix is actually used in an element or attribute name.
prefix
- The namespace prefix. If the value is a zero-length string, this method sets the default
namespace for elements and types.uri
- The namespace URI. It is possible to specify a zero-length string to "undeclare" a namespace;
in this case the prefix will not be available for use, except in the case where the prefix
is also a zero length string, in which case the absence of a prefix implies that the name
is in no namespace.
getBaseURI
public URI getBaseURI()
Get the static base URI for the query
getErrorListener
public ErrorListener getErrorListener()
Get the ErrorListener being used during this compilation episode
- listener The error listener in use. This is notified of all errors detected during the
compilation. If no user-supplied ErrorListener has been set, returns the system-supplied
ErrorListener.
getModuleURIResolver
public ModuleURIResolver getModuleURIResolver()
Get the user-defined ModuleURIResolver for resolving URIs used in import module
declarations in the XQuery prolog; returns null if none has been explicitly set either
here or in the Saxon Configuration.
- the registered ModuleURIResolver
getRequiredContextItemType
public ItemType getRequiredContextItemType()
Get the required type of the context item. If no type has been explicitly declared for the context
item, an instance of AnyItemType (representing the type item()) is returned.
- the required type of the context item
isCompileWithTracing
public boolean isCompileWithTracing()
Ask whether trace hooks are included in the compiled code.
- true if trace hooks are included, false if not.
setBaseURI
public void setBaseURI(URI baseURI)
Set the static base URI for the query
baseURI
- the static base URI
setCompileWithTracing
public void setCompileWithTracing(boolean option)
Set whether trace hooks are to be included in the compiled code. To use tracing, it is necessary
both to compile the code with trace hooks included, and to supply a TraceListener at run-time
option
- true if trace code is to be compiled in, false otherwise
setErrorListener
public void setErrorListener(ErrorListener listener)
Set the ErrorListener to be used during this query compilation episode
listener
- The error listener to be used. This is notified of all errors detected during the
compilation.
setModuleURIResolver
public void setModuleURIResolver(ModuleURIResolver resolver)
Set a user-defined ModuleURIResolver for resolving URIs used in import module
declarations in the XQuery prolog.
This will override any ModuleURIResolver that was specified as part of the configuration.
resolver
- the ModuleURIResolver to be used
setRequiredContextItemType
public void setRequiredContextItemType(ItemType type)
Declare the static type of the context item. If this type is declared, and if a context item
is supplied when the query is invoked, then the context item must conform to this type (no
type conversion will take place to force it into this type).
type
- the required type of the context item