|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.saxon.query.StaticQueryContext
public class StaticQueryContext
StaticQueryContext is the implementation of StaticContext used when processing XQuery expressions.
The StaticQueryContext object has two different usages. The application constructs a StaticQueryContext and initializes it with information about the context, for example, default namespaces, base URI, and so on. When a query is compiled using this StaticQueryContext, the query parser makes a copy of the StaticQueryContext and uses this internally, modifying it with information obtained from the query prolog, as well as information such as namespace and variable declarations that can occur at any point in the query. The query parser does not modify the original StaticQueryContext supplied by the calling application, which may therefore be used for compiling multiple queries, serially or even in multiple threads. This class forms part of Saxon's published XQuery API. Note that some of the methods are intended for use internally by the query processor itself: these are labelled as such. Methods that are considered stable are labelled with the JavaDoc "since" tag. The value 8.4 indicates a method introduced at or before Saxon 8.4; other values indicate the version at which the method was introduced. In the longer term, this entire API may at some stage be superseded by a proposed standard Java API for XQuery.
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. |
void |
checkImportedType(SequenceType importedType,
Declaration declaration)
Check that a SequenceType used in the definition of an imported variable or function is available in the importing module |
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(InputStream source,
String encoding)
Prepare an XQuery query for subsequent evaluation. |
XQueryExpression |
compileQuery(Reader source)
Prepare an XQuery query for subsequent evaluation. |
XQueryExpression |
compileQuery(String query)
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 |
declareCollation(String name,
StringCollator 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(PrintStream out)
Output "explain" information about each declared function. |
void |
explainGlobalVariables(PrintStream out)
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. |
CollationMap |
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. |
StringCollator |
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. |
String |
getDefaultElementNamespace()
Get the default XPath namespace for elements and types |
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. |
ItemType |
getRequiredContextItemType()
Get the required type of the context item. |
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. |
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 |
void |
lookForModuleCycles(Stack referees,
int lineNumber)
Look for module cycles. |
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,
boolean allowCycles)
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)
Deprecated. This method serves no purpose, since it is not possible to change the configuration once the StaticQueryContext has been initialized. |
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 |
setRequiredContextItemType(ItemType type)
Declare the static type of the context item. |
void |
typeCheckGlobalVariables(List compiledVars)
Get references to undeclared variables. |
void |
undeclareNamespace()
Undeclare the most recently-declared active namespace. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StaticQueryContext(Configuration config)
public StaticQueryContext(Configuration config, StaticQueryContext importer)
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.Method Detail |
---|
public void reset()
public boolean isTopLevelModule()
public boolean isMainModule()
public boolean mayImport(String namespace)
public XQueryFunctionLibrary getGlobalFunctionLibrary()
public ImportedFunctionLibrary getImportedFunctionLibrary()
public void addImportedNamespace(String uri)
public boolean importsNamespace(String uri)
public boolean importsNamespaceIndirectly(String uri)
public Iterator iterateImportedNamespaces()
public StaticQueryContext getTopLevelModule(StaticQueryContext start)
public StaticQueryContext copy()
public void setConfiguration(Configuration config)
IllegalArgumentException
- if the configuration supplied is different from the existing
configurationpublic Configuration getConfiguration()
getConfiguration
in interface StaticContext
public XPathContext makeEarlyEvaluationContext()
makeEarlyEvaluationContext
in interface StaticContext
public DocumentInfo buildDocument(Source source) throws XPathException
This method is retained for backwards compatibility; however, it is merely a wrapper
around the method Configuration.buildDocument(javax.xml.transform.Source)
, which should be called in preference.
source
- Any javax.xml.transform.Source object representing the document against
which queries will be executed. Note that a Saxon DocumentInfo
(indeed any NodeInfo
)
can be used as a Source. To use a third-party DOM Document as a source, create an instance of
DOMSource
to wrap it.
For additional control over the way in which the source document is processed,
supply an AugmentedSource
object and set appropriate
options on the object.
XPathException
public XQueryExpression compileQuery(String query) throws XPathException
Note that this interface makes caller responsible for decoding the query and presenting it as a string of characters. This means it is likely that any encoding specified in the query prolog will be ignored.
query
- The XQuery query to be evaluated, supplied as a string.
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.public XQueryExpression compileQuery(Reader source) throws XPathException, IOException
Note that this interface makes the Reader responsible for decoding the query and presenting it as a stream of characters. This means it is likely that any encoding specified in the query prolog will be ignored. Also, some implementations of Reader cannot handle a byte order mark.
source
- A Reader giving access to the text of the XQuery query to be compiled.
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.
IOException
- if a failure occurs reading the supplied input.public XQueryExpression compileQuery(InputStream source, String encoding) throws XPathException, IOException
source
- An InputStream giving access to the text of the XQuery query to be compiled, as a stream
of octetsencoding
- 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
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.
IOException
- if a failure occurs reading the supplied input.public Executable getExecutable()
public void setExecutable(Executable executable)
executable
- the Executablepublic LocationMap getLocationMap()
getLocationMap
in interface StaticContext
public void declarePassiveNamespace(String prefix, String uri, boolean explicit) throws StaticError
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.
StaticError
public void declareActiveNamespace(String prefix, String uri)
undeclareNamespace()
.
This method is intended for internal use only.
public void undeclareNamespace()
declareActiveNamespace(String, String)
public void clearPassiveNamespaces()
public void setExternalNamespaceResolver(NamespaceResolver resolver)
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.getURIForPrefix(String, boolean)
. Other
methods may throw an UnsupportedOperationException.
public NamespaceResolver getExternalNamespaceResolver()
public String getURIForPrefix(String prefix) throws XPathException
getURIForPrefix
in interface StaticContext
prefix
- The prefix
XPathException
- if the prefix has not been declaredpublic String checkURIForPrefix(String prefix)
prefix
- The prefix. Supply "" to obtain the default namespace.
public int[] getActiveNamespaceCodes()
public NamespaceResolver getNamespaceResolver()
getNamespaceResolver
in interface StaticContext
public String getDefaultFunctionNamespace()
getDefaultFunctionNamespace
in interface StaticContext
public void setDefaultFunctionNamespace(String defaultFunctionNamespace)
defaultFunctionNamespace
- The namespace to be used for unprefixed function callspublic void setDefaultElementNamespace(String uri) throws StaticError
StaticError
public String getDefaultElementNamespace()
getDefaultElementNamespace
in interface StaticContext
public void setModuleNamespace(String uri)
public String getModuleNamespace()
public short getModuleNamespaceCode()
public void setLocationURI(String uri)
public String getLocationURI()
public void setModuleURIResolver(ModuleURIResolver resolver)
public ModuleURIResolver getModuleURIResolver()
public void setInheritNamespaces(boolean inherit)
inherit
- true if namespaces are inherited, false if notpublic boolean isInheritNamespaces()
public void setPreserveNamespaces(boolean inherit)
inherit
- true if namespaces are preserved, false if notpublic boolean isPreserveNamespaces()
public void declareCollation(String name, Comparator comparator)
name
- The name of the collation (technically, a URI)comparator
- The Java Comparator used to implement the collating sequencepublic void declareCollation(String name, StringCollator comparator)
name
- The name of the collation (technically, a URI)comparator
- The Java Comparator used to implement the collating sequencepublic void declareDefaultCollation(String name)
name
- The collation name, as specified in the query prolog. The name
is not validated until it is used.public StringCollator getCollation(String name)
getCollation
in interface StaticContext
name
- the name of the collation, as an absolute URI
public String getDefaultCollationName()
getDefaultCollationName
in interface StaticContext
public CollationMap getAllCollations()
public void setRequiredContextItemType(ItemType type)
type
- the required context item typepublic ItemType getRequiredContextItemType()
public SlotManager getGlobalStackFrameMap()
public void declareVariable(VariableDeclaration var) throws StaticError
Note that the same VariableDeclation object cannot be used with more than one query. This is because the VariableDeclaration is modified internally to hold a list of references to all the places where the variable is used.
StaticError
public List fixupGlobalVariables(SlotManager globalVariableMap) throws StaticError
StaticError
public void lookForModuleCycles(Stack referees, int lineNumber) throws XPathException
[Definition: A module M1 directly depends on another module M2 (different from M1) if a variable or function declared in M1 depends on a variable or function declared in M2.] It is a static error [err:XQST0093] to import a module M1 if there exists a sequence of modules M1 ... Mi ... M1 such that each module directly depends on the next module in the sequence (informally, if M1 depends on itself through some chain of module dependencies.)
XPathException
public Iterator getModuleVariables()
public void typeCheckGlobalVariables(List compiledVars) throws StaticError
StaticError
public void explainGlobalVariables(PrintStream out)
public SlotManager getStackFrameMap()
public NamePool getNamePool()
getNamePool
in interface StaticContext
public void issueWarning(String s, SourceLocator locator)
issueWarning
in interface StaticContext
public void setBaseURI(String baseURI)
public String getSystemId()
getSystemId
in interface StaticContext
public String getBaseURI()
getBaseURI
in interface StaticContext
public int getLineNumber()
getLineNumber
in interface StaticContext
public VariableReference bindVariable(int fingerprint) throws StaticError
bindVariable
in interface StaticContext
fingerprint
- the name of the variable
StaticError
public void setFunctionLibraryList(FunctionLibraryList functionLibrary)
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 getFunctionLibrary()
method.FunctionLibraryList
public FunctionLibrary getFunctionLibrary()
getFunctionLibrary
in interface StaticContext
FunctionLibraryList
public XQueryFunctionLibrary getLocalFunctionLibrary()
public void declareFunction(XQueryFunction function) throws StaticError
StaticError
public void bindUnboundFunctionCalls() throws XPathException
StaticError
- if a function call refers to a function that has
not been declared
XPathException
public void fixupGlobalFunctions() throws XPathException
XPathException
public void explainGlobalFunctions(PrintStream out) throws XPathException
XPathException
public UserFunction getUserDefinedFunction(String uri, String localName, int arity)
uri
- the uri of the function namelocalName
- the local part of the function namearity
- the number of arguments.public void bindUnboundVariables() throws XPathException
XPathException
public boolean isInBackwardsCompatibleMode()
isInBackwardsCompatibleMode
in interface StaticContext
public void addImportedSchema(String targetNamespace)
targetNamespace
- The target namespace of the schema to be addedpublic boolean isImportedSchema(String namespace)
isImportedSchema
in interface StaticContext
namespace
- The namespace of the required schema. Supply "" for
a no-namespace schema.
public Set getImportedSchemaNamespaces()
getImportedSchemaNamespaces
in interface StaticContext
public boolean isAllowedBuiltInType(AtomicType type)
isAllowedBuiltInType
in interface StaticContext
type
- the supposedly built-in type. This will always be a type in the
XS or XDT namespace.
public void setConstructionMode(int mode)
mode
- one of Validation.STRIP
, Validation.PRESERVE
public int getConstructionMode()
Validation.STRIP
, Validation.PRESERVE
public static StaticQueryContext makeStaticQueryContext(String baseURI, Executable executable, StaticQueryContext importer, String query, String namespaceURI, boolean allowCycles) throws StaticError
baseURI
- The base URI and location URI of the moduleexecutable
- The Executableimporter
- 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 endingsnamespaceURI
- namespace of the query module to be loaded
StaticError
public void setErrorListener(ErrorListener listener)
public ErrorListener getErrorListener()
public void reportFatalError(XPathException err)
public void checkImportedType(SequenceType importedType, Declaration declaration) throws StaticError
StaticError
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |