|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.saxon.query.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 |
Method Summary | |
void |
addImportedNamespace(java.lang.String uri)
Register that this module imports a particular module namespace |
void |
addImportedSchema(java.lang.String targetNamespace)
Add an imported schema to this static context. |
void |
bindUnboundFunctionCalls()
Bind function calls that could not be bound when first encountered. |
VariableDeclaration |
bindVariable(int fingerprint)
Bind a variable used in a query to the expression in which it is declared. |
DocumentInfo |
buildDocument(javax.xml.transform.Source source)
Convenience method for building Saxon's internal representation of a source XML document. |
java.lang.String |
checkURIForPrefix(java.lang.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(java.io.InputStream source,
java.lang.String encoding)
Prepare an XQuery query for subsequent evaluation. |
XQueryExpression |
compileQuery(java.io.Reader source)
Prepare an XQuery query for subsequent evaluation. |
XQueryExpression |
compileQuery(java.lang.String query)
Prepare an XQuery query for subsequent evaluation. |
StaticQueryContext |
copy()
Make a copy of this StaticQueryContext. |
void |
declareActiveNamespace(java.lang.String prefix,
java.lang.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(java.lang.String name,
java.util.Comparator comparator)
Declare a named collation. |
void |
declareDefaultCollation(java.lang.String name)
Set the default collation. |
void |
declareFunction(XQueryFunction function)
Register a user-defined XQuery function. |
void |
declarePassiveNamespace(java.lang.String prefix,
java.lang.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. |
java.util.List |
fixupGlobalVariables(SlotManager globalVariableMap)
Fixup all references to global variables. |
int[] |
getActiveNamespaceCodes()
Get an array containing the namespace codes of all active namespaces. |
java.util.HashMap |
getAllCollations()
Get a HashMap that maps all registered collations to Comparators. |
java.lang.String |
getBaseURI()
Get the Base URI of the query, for resolving any relative URI's used in the expression. |
java.util.Comparator |
getCollation(java.lang.String name)
Get a named collation. |
Configuration |
getConfiguration()
Get the Configuration options |
int |
getConstructionMode()
Get the current validation mode |
java.lang.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 |
java.lang.String |
getDefaultFunctionNamespace()
Get the default function namespace |
Executable |
getExecutable()
Get the Executable, an object representing the compiled query and its environment. |
java.util.Iterator |
getFunctionDefinitions()
Get an iterator over the Functions defined in this module. |
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). |
SlotManager |
getGlobalStackFrameMap()
Get the stack frame map for global variables. |
StaticQueryContext |
getImporter()
Get the StaticQueryContext representing the module that imported this module. |
int |
getLineNumber()
Get the line number of the expression within that container. |
LocationMap |
getLocationMap()
Get the LocationMap, an data structure used to identify the location of compiled expressions within the query source text. |
java.lang.String |
getLocationURI()
Get the location URI for a module |
java.lang.String |
getModuleNamespace()
Get the namespace of the current library module. |
short |
getModuleNamespaceCode()
Get the namesapce code of the current library 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. |
java.lang.String |
getSystemId()
Get the system ID of the container of the expression. |
java.lang.String |
getURIForPrefix(java.lang.String prefix)
Get the URI for a prefix. |
UserFunction |
getUserDefinedFunction(java.lang.String uri,
java.lang.String localName,
int arity)
Get the function with a given name and arity. |
java.util.Iterator |
getVariableDeclarations()
Get an iterator over the variables defined in this module. |
boolean |
importsNamespace(java.lang.String uri)
Test whether this module imports a particular namespace |
boolean |
isAllowedBuiltInType(AtomicType type)
Determine whether a built-in type is available in this context. |
boolean |
isImportedSchema(java.lang.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 |
isPreserveNamespaces()
Get the namespace copy mode |
void |
issueWarning(java.lang.String s,
javax.xml.transform.SourceLocator locator)
Issue a compile-time warning. |
java.util.Iterator |
iterateImportedNamespaces()
Get an iterator over all the module namespaces that this module imports |
static StaticQueryContext |
makeStaticQueryContext(java.lang.String baseURI,
Executable executable,
StaticQueryContext importer,
java.lang.String query,
java.lang.String namespaceURI)
Supporting method to load a query module. |
void |
reset()
Reset the state of this StaticQueryContext to an uninitialized state |
void |
setBaseURI(java.lang.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(java.lang.String uri)
Set the default element namespace |
void |
setDefaultFunctionNamespace(java.lang.String defaultFunctionNamespace)
Set the default function namespace |
void |
setExecutable(Executable executable)
Set the executable. |
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(java.lang.String uri)
Set the location URI for a module |
void |
setModuleNamespace(java.lang.String uri)
Set the namespace for a library module. |
void |
setPreserveNamespaces(boolean inherit)
Set the namespace copy mode |
void |
typeCheckGlobalVariables(java.util.List compiledVars)
|
void |
undeclareNamespace()
Undeclare the most recently-declared active namespace. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StaticQueryContext(Configuration config)
Method Detail |
public void reset()
public StaticQueryContext getImporter()
public void addImportedNamespace(java.lang.String uri)
public boolean importsNamespace(java.lang.String uri)
public java.util.Iterator iterateImportedNamespaces()
public StaticQueryContext copy()
public void setConfiguration(Configuration config)
java.lang.IllegalArgumentException
- if the configuration supplied is different from the existing
configurationpublic Configuration getConfiguration()
getConfiguration
in interface StaticContext
public DocumentInfo buildDocument(javax.xml.transform.Source source) throws XPathException
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(java.lang.String query) throws XPathException
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(java.io.Reader source) throws XPathException, java.io.IOException
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.
java.io.IOException
- if a failure occurs reading the supplied input.public XQueryExpression compileQuery(java.io.InputStream source, java.lang.String encoding) throws XPathException, java.io.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.
java.io.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(java.lang.String prefix, java.lang.String uri, boolean explicit) throws StaticError
prefix
- The namespace prefix. Must not be null.uri
- The namespace URI. Must not be null.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(java.lang.String prefix, java.lang.String uri)
undeclareNamespace()
.
This method is intended for internal use only.
public void undeclareNamespace()
declareActiveNamespace(String, String)
public void clearPassiveNamespaces()
public java.lang.String getURIForPrefix(java.lang.String prefix) throws XPathException
getURIForPrefix
in interface StaticContext
prefix
- The prefix
XPathException
- if the prefix has not been declaredpublic java.lang.String checkURIForPrefix(java.lang.String prefix)
prefix
- The prefix. Supply "" to obtain the default namespace.
public int[] getActiveNamespaceCodes()
public NamespaceResolver getNamespaceResolver()
getNamespaceResolver
in interface StaticContext
public java.lang.String getDefaultFunctionNamespace()
getDefaultFunctionNamespace
in interface StaticContext
public void setDefaultFunctionNamespace(java.lang.String defaultFunctionNamespace)
defaultFunctionNamespace
- The namespace to be used for unprefixed function callspublic void setDefaultElementNamespace(java.lang.String uri) throws StaticError
StaticError
public short getDefaultElementNamespace()
getDefaultElementNamespace
in interface StaticContext
public void setModuleNamespace(java.lang.String uri)
public java.lang.String getModuleNamespace()
public short getModuleNamespaceCode()
public void setLocationURI(java.lang.String uri)
public java.lang.String getLocationURI()
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(java.lang.String name, java.util.Comparator comparator)
name
- The name of the collation (technically, a URI)comparator
- The Java Comparator used to implement the collating sequencepublic void declareDefaultCollation(java.lang.String name) throws XPathException
name
- The collation name
XPathException
- if the collation name has not been registeredpublic java.util.Comparator getCollation(java.lang.String name)
getCollation
in interface StaticContext
name
- The name of the required collation. Supply null to get the default collation.
public java.lang.String getDefaultCollationName()
getDefaultCollationName
in interface StaticContext
public java.util.HashMap getAllCollations()
public SlotManager getGlobalStackFrameMap()
public void declareVariable(VariableDeclaration var) throws StaticError
StaticError
public java.util.List fixupGlobalVariables(SlotManager globalVariableMap) throws StaticError
StaticError
public void typeCheckGlobalVariables(java.util.List compiledVars) throws StaticError
StaticError
public void explainGlobalVariables()
public java.util.Iterator getVariableDeclarations()
public SlotManager getStackFrameMap()
public NamePool getNamePool()
getNamePool
in interface StaticContext
public void issueWarning(java.lang.String s, javax.xml.transform.SourceLocator locator)
issueWarning
in interface StaticContext
public void setBaseURI(java.lang.String baseURI)
public java.lang.String getSystemId()
getSystemId
in interface StaticContext
public java.lang.String getBaseURI()
getBaseURI
in interface StaticContext
public int getLineNumber()
getLineNumber
in interface StaticContext
public VariableDeclaration bindVariable(int fingerprint) throws StaticError
bindVariable
in interface StaticContext
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 void declareFunction(XQueryFunction function) throws StaticError
StaticError
public void bindUnboundFunctionCalls() throws StaticError
StaticError
- if a function call refers to a function that has
not been declaredpublic java.util.Iterator getFunctionDefinitions()
XQueryFunction
objects. It returns
all function known to this module including those imported from elsewhere; they
can be distinguished by their namespace.public void fixupGlobalFunctions() throws XPathException
XPathException
public void explainGlobalFunctions() throws XPathException
XPathException
public UserFunction getUserDefinedFunction(java.lang.String uri, java.lang.String localName, int arity)
uri
- the uri of the function namelocalName
- the local part of the function namearity
- the number of arguments.public boolean isInBackwardsCompatibleMode()
isInBackwardsCompatibleMode
in interface StaticContext
public void addImportedSchema(java.lang.String targetNamespace)
targetNamespace
- The target namespace of the schema to be addedpublic boolean isImportedSchema(java.lang.String namespace)
isImportedSchema
in interface StaticContext
namespace
- The namespace of the required schema. Supply "" for
a no-namespace schema.
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(java.lang.String baseURI, Executable executable, StaticQueryContext importer, java.lang.String query, java.lang.String namespaceURI) 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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |