Package net.sf.saxon.s9api
Class XQueryCompiler
java.lang.Object
net.sf.saxon.s9api.XQueryCompiler
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.
- Since:
- 9.0
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
XQueryCompiler
(Processor processor) Protected constructor -
Method Summary
Modifier and TypeMethodDescriptionCompile a query supplied as a filecompile
(InputStream query) Compile a query supplied as an InputStreamCompile a query supplied as a ReaderCompile a query supplied as a string.void
declareNamespace
(String prefix, String uri) Declare a namespace binding as part of the static context for queries compiled using this XQueryCompiler.Get the static base URI for the queryGet the ErrorListener being used during this compilation episodeGet the user-defined ModuleURIResolver for resolving URIs used inimport module
declarations in the XQuery prolog; returns null if none has been explicitly set either here or in the Saxon Configuration.Get the required type of the context item.boolean
Ask whether trace hooks are included in the compiled code.boolean
Ask whether the query is allowed to use XQuery Update syntaxvoid
setBaseURI
(URI baseURI) Set the static base URI for the queryvoid
setCompileWithTracing
(boolean option) Set whether trace hooks are to be included in the compiled code.void
setEncoding
(String encoding) Set the encoding of the supplied query.void
setErrorListener
(ErrorListener listener) Set the ErrorListener to be used during this query compilation episodevoid
setModuleURIResolver
(ModuleURIResolver resolver) Set a user-defined ModuleURIResolver for resolving URIs used inimport module
declarations in the XQuery prolog.void
Declare the static type of the context item.void
setUpdatingEnabled
(boolean updating) Say whether the query is allowed to be updating.
-
Constructor Details
-
XQueryCompiler
Protected constructor- Parameters:
processor
- the Saxon Processor
-
-
Method Details
-
setBaseURI
Set the static base URI for the query- Parameters:
baseURI
- the static base URI
-
getBaseURI
Get the static base URI for the query- Returns:
- the static base URI
-
setErrorListener
Set the ErrorListener to be used during this query compilation episode- Parameters:
listener
- The error listener to be used. This is notified of all errors detected during the compilation.
-
getErrorListener
Get the ErrorListener being used during this compilation episode- Returns:
- 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.
-
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- Parameters:
option
- true if trace code is to be compiled in, false otherwise
-
isCompileWithTracing
public boolean isCompileWithTracing()Ask whether trace hooks are included in the compiled code.- Returns:
- true if trace hooks are included, false if not.
-
setModuleURIResolver
Set a user-defined ModuleURIResolver for resolving URIs used inimport module
declarations in the XQuery prolog. This will override any ModuleURIResolver that was specified as part of the configuration.- Parameters:
resolver
- the ModuleURIResolver to be used
-
getModuleURIResolver
Get the user-defined ModuleURIResolver for resolving URIs used inimport module
declarations in the XQuery prolog; returns null if none has been explicitly set either here or in the Saxon Configuration.- Returns:
- the registered ModuleURIResolver
-
setEncoding
Set the encoding of the supplied query. This is ignored if the query is supplied in character form, that is, as aString
or as aReader
. If no value is set, the query processor will attempt to infer the encoding, defaulting to UTF-8 if no information is available.- Parameters:
encoding
- the encoding of the supplied query, for example "iso-8859-1"- Since:
- 9.1
-
setUpdatingEnabled
public void setUpdatingEnabled(boolean updating) Say whether the query is allowed to be updating. XQuery update syntax will be rejected during query compilation unless this flag is set. XQuery Update is supported only under Saxon-SA.- Parameters:
updating
- true if the query is allowed to use the XQuery Update facility (requires Saxon-SA). If set to false, the query must not be an updating query. If set to true, it may be either an updating or a non-updating query.- Since:
- 9.1
-
isUpdatingEnabled
public boolean isUpdatingEnabled()Ask whether the query is allowed to use XQuery Update syntax- Returns:
- true if the query is allowed to use the XQuery Update facility. Note that this does not necessarily mean that the query is an updating query; but if the value is false, the it must definitely be non-updating.
- Since:
- 9.1
-
declareNamespace
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.- Parameters:
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.- Throws:
NullPointerException
- if either the prefix or uri is null.IllegalArgumentException
- in the event of an invalid declaration of the XML namespace
-
setRequiredContextItemType
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).- Parameters:
type
- the required type of the context item
-
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.- Returns:
- the required type of the context item
-
compile
Compile a query supplied as a string.The base URI of the query should be supplied by calling
setBaseURI(java.net.URI)
- Parameters:
query
- the text of the query- Returns:
- an XQueryExecutable representing the compiled query
- Throws:
SaxonApiException
- if the query compilation fails with a static error
-
compile
Compile a query supplied as a file- Parameters:
query
- the file containing the query. The URI corresponding to this file will be used as the base URI of the query, overriding any URI supplied usingsetBaseURI(java.net.URI)
(but not overriding any base URI specified within the query prolog)- Returns:
- an XQueryExecutable representing the compiled query
- Throws:
SaxonApiException
- if the query compilation fails with a static errorIOException
- if the file does not exist or cannot be read- Since:
- 9.1
-
compile
Compile a query supplied as an InputStreamThe base URI of the query should be supplied by calling
setBaseURI(java.net.URI)
- Parameters:
query
- the input stream on which the query is supplied. This will be consumed by this method- Returns:
- an XQueryExecutable representing the compiled query
- Throws:
SaxonApiException
- if the query compilation fails with a static errorIOException
- if the file does not exist or cannot be read- Since:
- 9.1
-
compile
Compile a query supplied as a ReaderThe base URI of the query should be supplied by calling
setBaseURI(java.net.URI)
- Parameters:
query
- the input stream on which the query is supplied. This will be consumed by this method- Returns:
- an XQueryExecutable representing the compiled query
- Throws:
SaxonApiException
- if the query compilation fails with a static errorIOException
- if the file does not exist or cannot be read- Since:
- 9.1
-