net.sf.saxon.query
public class StaticQueryContext extends Object implements StaticContext
Since: 8.4
Constructor Summary | |
---|---|
StaticQueryContext(Configuration config)
Create a StaticQueryContext using a given Configuration. | |
StaticQueryContext(Configuration config, StaticQueryContext importer)
Create a StaticQueryContext for a library module. |
Method Summary | |
---|---|
void | addImportedNamespace(String uri)
Register that this module imports a particular module namespace |
void | addImportedSchema(String targetNamespace)
Add an imported schema to this static context. |
void | bindUnboundFunctionCalls()
Bind function calls that could not be bound when first encountered. |
void | bindUnboundVariables()
Bind unbound variables (these are typically variables that reference another module
participating in a same-namespace cycle, since local forwards references are not allowed |
VariableReference | bindVariable(int fingerprint)
Bind a variable used in a query to the expression in which it is declared.
|
DocumentInfo | buildDocument(Source source)
Convenience method for building Saxon's internal representation of a source XML
document. |
String | checkURIForPrefix(String prefix)
Get the URI for a prefix if there is one, return null if not.
|
void | clearPassiveNamespaces()
Clear all the declared passive namespaces, except for the standard ones (xml, saxon, etc)
|
XQueryExpression | compileQuery(String query)
Prepare an XQuery query for subsequent evaluation. |
XQueryExpression | compileQuery(Reader source)
Prepare an XQuery query for subsequent evaluation. |
XQueryExpression | compileQuery(InputStream source, String encoding)
Prepare an XQuery query for subsequent evaluation. |
StaticQueryContext | copy()
Make a copy of this StaticQueryContext. |
void | declareActiveNamespace(String prefix, String uri)
Declare an active namespace, that is, a namespace which as well as affecting the static
context of the query, will also be copied to the result tree when element constructors
are evaluated. |
void | declareCollation(String name, Comparator comparator)
Declare a named collation. |
void | declareDefaultCollation(String name)
Set the default collation. |
void | declareFunction(XQueryFunction function)
Register a user-defined XQuery function.
|
void | declarePassiveNamespace(String prefix, String uri, boolean explicit)
Declare a namespace whose prefix can be used in expressions. |
void | declareVariable(VariableDeclaration var)
Declare a global variable. |
void | explainGlobalFunctions()
Output "explain" information about each declared function.
|
void | explainGlobalVariables()
Produce "explain" output for all global variables.
|
void | fixupGlobalFunctions()
Fixup all references to global functions. |
List | fixupGlobalVariables(SlotManager globalVariableMap)
Fixup all references to global variables.
|
int[] | getActiveNamespaceCodes()
Get an array containing the namespace codes of all active
namespaces.
|
HashMap | getAllCollations()
Get a HashMap that maps all registered collations to Comparators.
|
String | getBaseURI()
Get the Base URI of the query, for resolving any relative URI's used
in the expression.
|
Comparator | getCollation(String name)
Get a named collation. |
Configuration | getConfiguration()
Get the Configuration options
|
int | getConstructionMode()
Get the current validation mode
|
String | getDefaultCollationName()
Get the name of the default collation.
|
short | getDefaultElementNamespace()
Get the default XPath namespace, as a namespace URI code that can be looked up in the NamePool
|
String | getDefaultFunctionNamespace()
Get the default function namespace
|
ErrorListener | getErrorListener()
Get the ErrorListener in use for this static context |
Executable | getExecutable()
Get the Executable, an object representing the compiled query and its environment.
|
NamespaceResolver | getExternalNamespaceResolver()
Get the external namespace resolver that has been registered using
setExternalNamespaceResolver(), if any. |
FunctionLibrary | getFunctionLibrary()
Get the function library containing all the in-scope functions available in this static
context (that is, the functions available in this query module).
|
XQueryFunctionLibrary | getGlobalFunctionLibrary() |
SlotManager | getGlobalStackFrameMap()
Get the stack frame map for global variables.
|
ImportedFunctionLibrary | getImportedFunctionLibrary() |
Set | getImportedSchemaNamespaces()
Get the set of imported schemas
|
int | getLineNumber()
Get the line number of the expression within that container.
|
XQueryFunctionLibrary | getLocalFunctionLibrary()
Get the functions declared locally within this module |
LocationMap | getLocationMap()
Get the LocationMap, an data structure used to identify the location of compiled expressions within
the query source text.
|
String | getLocationURI()
Get the location URI for a module |
String | getModuleNamespace()
Get the namespace of the current library module.
|
short | getModuleNamespaceCode()
Get the namesapce code of the current library module.
|
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
on the StaticQueryContext or on the Configuration. |
Iterator | getModuleVariables()
Get global variables declared in this module |
NamePool | getNamePool()
Get the NamePool used for compiling expressions
|
NamespaceResolver | getNamespaceResolver()
Get a copy of the Namespace Context. |
SlotManager | getStackFrameMap()
Get the stack frame map for local variables in the "main" query expression.
|
String | getSystemId()
Get the system ID of the container of the expression. |
StaticQueryContext | getTopLevelModule(StaticQueryContext start)
Get the Static Query Context for the top-level module. |
List | getUndeclaredVariables(SlotManager globalVariableMap)
Get references to undeclared variables. |
String | getURIForPrefix(String prefix)
Get the URI for a prefix.
|
UserFunction | getUserDefinedFunction(String uri, String localName, int arity)
Get the function with a given name and arity. |
boolean | importsNamespace(String uri)
Test whether this module directly imports a particular namespace |
boolean | importsNamespaceIndirectly(String uri)
Test whether this module imports a particular namespace directly or indirectly |
boolean | isAllowedBuiltInType(AtomicType type)
Determine whether a built-in type is available in this context. |
boolean | isImportedSchema(String namespace)
Get the schema for a given namespace, if it has been imported
|
boolean | isInBackwardsCompatibleMode()
Determine whether Backwards Compatible Mode is used
|
boolean | isInheritNamespaces()
Get the namespace inheritance mode
|
boolean | isMainModule()
Test whether this is a "main" module, in the sense of the XQuery language specification |
boolean | isPreserveNamespaces()
Get the namespace copy mode
|
void | issueWarning(String s, SourceLocator locator)
Issue a compile-time warning. |
boolean | isTopLevelModule()
Test whether this is a "top-level" module. |
Iterator | iterateImportedNamespaces()
Get an iterator over all the module namespaces that this module imports |
XPathContext | makeEarlyEvaluationContext()
Construct a dynamic context for early evaluation of constant subexpressions |
static StaticQueryContext | makeStaticQueryContext(String baseURI, Executable executable, StaticQueryContext importer, String query, String namespaceURI)
Supporting method to load a query module. |
boolean | mayImport(String namespace)
Check whether this module is allowed to import a module with namespace N. |
void | reportFatalError(XPathException err)
Report a fatal error in the query (via the registered ErrorListener) |
void | reset()
Reset the state of this StaticQueryContext to an uninitialized state
|
void | setBaseURI(String baseURI)
Set the Base URI of the query
|
void | setConfiguration(Configuration config)
Set the Configuration options
|
void | setConstructionMode(int mode)
Set the construction mode for this module
|
void | setDefaultElementNamespace(String uri)
Set the default element namespace
|
void | setDefaultFunctionNamespace(String defaultFunctionNamespace)
Set the default function namespace
|
void | setErrorListener(ErrorListener listener)
Set the ErrorListener to be used to report compile-time errors in a query. |
void | setExecutable(Executable executable)
Set the executable.
|
void | setExternalNamespaceResolver(NamespaceResolver resolver)
Set an external namespace resolver. |
void | setFunctionLibraryList(FunctionLibraryList functionLibrary)
Set the function library used for binding any function call appearing within the query module.
|
void | setInheritNamespaces(boolean inherit)
Set the namespace inheritance mode
|
void | setLocationURI(String uri)
Set the location URI for a module |
void | setModuleNamespace(String uri)
Set the namespace for a library module.
|
void | setModuleURIResolver(ModuleURIResolver resolver)
Set a user-defined ModuleURIResolver for resolving URIs used in "import module"
declarations in the XQuery prolog.
|
void | setPreserveNamespaces(boolean inherit)
Set the namespace copy mode
|
void | typeCheckGlobalVariables(List compiledVars) |
void | undeclareNamespace()
Undeclare the most recently-declared active namespace. |
Since: 8.4
Parameters: importer the module that imported this module. This may be null, in which case the library module is treated as a "top-level" library module.
Parameters: targetNamespace The target namespace of the schema to be added
Since: 8.4
Throws: net.sf.saxon.trans.StaticError if a function call refers to a function that has not been declared
Parameters: source Any javax.xml.transform.Source object representing the document against
which queries will be executed. Note that a Saxon For additional control over the way in which the source document is processed,
supply an DocumentInfo
(indeed any NodeInfo
)
can be used as a Source. To use a third-party DOM Document as a source, create an instance of
javax.xml.transform.dom.DOMSource DOMSource
to wrap it.
AugmentedSource
object and set appropriate
options on the object.
Returns: the DocumentInfo representing the root node of the resulting document object.
Since: 8.4
Parameters: prefix The prefix. Supply "" to obtain the default namespace.
Returns: the corresponding namespace URI, or null if the prefix has not been declared. If the prefix is "" and the default namespace is the non-namespace, return "".
Since: 8.4
Parameters: query The XQuery query to be evaluated, supplied as a string.
Returns: an XQueryExpression object representing the prepared expression
Throws: net.sf.saxon.trans.XPathException if the syntax of the expression is wrong, or if it references namespaces, variables, or functions that have not been declared, or contains other static errors.
Since: 8.4
Parameters: source A Reader giving access to the text of the XQuery query to be compiled.
Returns: an XPathExpression object representing the prepared expression.
Throws: net.sf.saxon.trans.XPathException if the syntax of the expression is wrong, or if it references namespaces, variables, or functions that have not been declared, or any other static error is reported. java.io.IOException if a failure occurs reading the supplied input.
Since: 8.4
Parameters: source An InputStream giving access to the text of the XQuery query to be compiled, as a stream of octets encoding The encoding used to translate characters to octets in the query source. The parameter may be null: in this case the query parser attempts to infer the encoding by inspecting the source, and if that fails, it assumes UTF-8 encoding
Returns: an XPathExpression object representing the prepared expression.
Throws: net.sf.saxon.trans.XPathException if the syntax of the expression is wrong, or if it references namespaces, variables, or functions that have not been declared, or any other static error is reported. java.io.IOException if a failure occurs reading the supplied input.
Since: 8.5
Returns: a copy of this StaticQueryContext
Parameters: name The name of the collation (technically, a URI) comparator The Java Comparator used to implement the collating sequence
Since: 8.4
Parameters: name The collation name, as specified in the query prolog. The name is not validated until it is used.
Since: 8.4. Changed in 8.6 so it no longer validates the collation name: this is because the base URI is not necessarily known at the point where the default collation is declared.
Parameters: prefix The namespace prefix. Must not be null. uri The namespace URI. Must not be null. The value "" (zero-length string) is used to undeclare a namespace; it is not an error if there is no existing binding for the namespace prefix. explicit This parameter is set to true when Saxon calls the method internally to define a namespace declared within the query prolog. It should normally be set to false in the case of a call from a user application.
Since: 8.4
Since: 8.4
Returns: the base URI of the query
Since: 8.4
Parameters: name the name of the collation, as an absolute URI
Returns: the collation identified by the given name, as set previously using declareCollation. If no collation with this name has been declared, the method calls the CollationURIResolver to locate a collation with this name. Return null if no collation with this name is found.
Since: 8.4
Since: 8.4
Returns: the name of the default collation; or the name of the codepoint collation if no default collation has been defined. The name is returned in the form it was specified; that is, it is not yet resolved against the base URI. (This is because the base URI declaration can follow the default collation declaration in the query prolog.) If no default collation has been specified, the "default default" (that is, the Unicode codepoint collation) is returned.
Since: 8.4
Since: 8.4
Returns: the default function namespace (defaults to the fn: namespace)
Since: 8.4
Returns: the Executable
Returns: the FunctionLibrary used. For XQuery, this will always be a FunctionLibraryList.
See Also: FunctionLibraryList
Returns: a Set, the set of URIs representing the names of imported schemas
Returns: -1 always
Returns: the LocationMap
Returns: the module namespace, or null if this is a main module
Returns: the module namespace, or null if this is a main module
Returns: an Iterator whose items are GlobalVariableDefinition objects
Since: 8.4
Returns: the Base URI
Since: 8.4
Returns: a list of XPathException objects, one for each undeclared variable
Parameters: prefix The prefix
Returns: the corresponding namespace URI
Throws: net.sf.saxon.trans.XPathException if the prefix has not been declared
Parameters: uri the uri of the function name localName the local part of the function name arity the number of arguments.
Since: 8.4
Parameters: type the supposedly built-in type. This will always be a type in the XS or XDT namespace.
Returns: true if this type can be used in this static context
Parameters: namespace The namespace of the required schema. Supply "" for a no-namespace schema.
Returns: The schema if found, or null if not found.
Since: 8.4
Returns: false; XPath 1.0 compatibility mode is not supported in XQuery
Since: 8.4
Returns: true if namespaces are inherited, false if not
Since: 8.4
Returns: true if namespaces are preserved, false if not
Since: 8.4
Parameters: baseURI The base URI and location URI of the module executable The Executable importer The importing query module (used to check for cycles). This is null when loading a query module from XSLT. query The text of the query, after decoding and normalizing line endings namespaceURI namespace of the query module to be loaded
Returns: The StaticQueryContext representing the loaded query module
Throws: net.sf.saxon.trans.StaticError
Since: 8.4
Since: 8.4
Deprecated: This method serves no purpose, since it is not possible to change the configuration once the StaticQueryContext has been initialized.
Set the Configuration optionsThrows: IllegalArgumentException if the configuration supplied is different from the existing configuration
Since: 8.4
Since: 8.4
Parameters: defaultFunctionNamespace The namespace to be used for unprefixed function calls
Since: 8.4
Parameters: executable the Executable
Note that the external namespace resolver is used only for namespace prefixes that are resolved at compile time. Where namespace prefixes are resolved at run-time (which happens very rarely with XQuery: the only case is to resolve the computed name used in a computed element or attribute constructor), the external namespace resolver is not invoked.
Although the supplied object must implement the NamespaceResolver interface, the only method actually used is the method NamespaceResolver. Other methods may throw an UnsupportedOperationException.
Parameters: functionLibrary the FunctionLibrary to be used. This will typically be a FunctionLibraryList; in most cases it will be a slightly modified copy of a FunctionLibraryList constructed by the system and obtained using the StaticQueryContext method.
See Also: FunctionLibraryList
Parameters: inherit true if namespaces are inherited, false if not
Since: 8.4
Parameters: inherit true if namespaces are preserved, false if not
Since: 8.4
See Also: StaticQueryContext