|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.saxon.query.QueryModule
public class QueryModule
This class represents a query module, and includes information about the static context of the query module. The class is intended for internal Saxon use. User settings that affect the static context are made in the StaticQueryContext object, and those settings are copied to each QueryModule when the query module is compiled.
Constructor Summary | |
---|---|
QueryModule(Configuration config,
QueryModule importer)
Create a QueryModule for a library module. |
|
QueryModule(StaticQueryContext sqc)
Create a QueryModule for a main module, copying the data that has been set up in a StaticQueryContext object |
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(StructuredQName qName)
Bind a variable used in a query to the expression in which it is declared. |
void |
checkForCircularities(List compiledVars,
XQueryFunctionLibrary globalFunctionLibrary)
Check for circular definitions of global variables. |
void |
checkImportedFunctionSignature(XQueryFunction fd)
Check that all the types used in the signature of an imported function are available in the module of the caller of the function |
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 |
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 |
declareFunction(XQueryFunction function)
Register a user-defined XQuery function. |
void |
declarePrologNamespace(String prefix,
String uri)
Register a namespace that is explicitly declared in the prolog of the query module. |
void |
declareVariable(VariableDeclaration var)
Declare a global variable. |
void |
explainGlobalFunctions(ExpressionPresenter out)
Output "explain" information about each declared function. |
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. |
String |
getBaseURI()
Get the base URI for a module |
StringCollator |
getCollation(String name)
Get a named collation. |
Configuration |
getConfiguration()
Get the Saxon Configuration |
int |
getConstructionMode()
Get the current construction 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 |
Executable |
getExecutable()
Get the Executable, an object representing the compiled query and its environment. |
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()
Get the function library object that holds details of global functions |
SlotManager |
getGlobalStackFrameMap()
Get the stack frame map for global variables. |
ImportedFunctionLibrary |
getImportedFunctionLibrary()
Get the function library object that holds details of imported functions |
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. |
URI |
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. |
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. |
String |
getSystemId()
Get the System ID for a module |
QueryModule |
getTopLevelModule(QueryModule start)
Get the QueryModule 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. |
StaticQueryContext |
getUserQueryContext()
Get the StaticQueryContext object containing options set up by the user |
boolean |
importsNamespace(String uri)
Ask 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(BuiltInAtomicType type)
Determine whether a built-in type is available in this context. |
boolean |
isEmptyLeast()
Ask what is the option for where an empty sequence appears in the collation order, if not otherwise specified in the "order by" clause |
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()
Ask whether this is a "main" module, in the sense of the XQuery language specification |
boolean |
isPreserveBoundarySpace()
Ask whether the policy for boundary space is "preserve" or "strip" |
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 QueryModule |
makeQueryModule(String baseURI,
Executable executable,
QueryModule importer,
String query,
String namespaceURI,
boolean allowCycles)
Supporting method to load an imported library module. |
boolean |
mayImportModule(String namespace)
Check whether this module is allowed to import a module with namespace N. |
void |
optimizeGlobalFunctions()
Optimize the body of all global functions. |
void |
reportFatalError(XPathException err)
Report a fatal error in the query (via the registered ErrorListener) |
void |
setBaseURI(String uri)
Set the base URI for a module |
void |
setConstructionMode(int mode)
Set the construction mode for this module |
void |
setDefaultCollationName(String collation)
Set the name of the default collation |
void |
setDefaultElementNamespace(String uri)
Set the default element namespace as declared in the query prolog |
void |
setDefaultFunctionNamespace(String uri)
Set the default function namespace |
void |
setEmptyLeast(boolean least)
Set the option for where an empty sequence appears in the collation order, if not otherwise specified in the "order by" clause |
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(URI uri)
Set the location URI for a module |
void |
setModuleNamespace(String uri)
Set the namespace for a library module. |
void |
setPreserveBoundarySpace(boolean preserve)
Set the policy for preserving boundary space |
void |
setPreserveNamespaces(boolean inherit)
Set the namespace copy mode |
void |
typeCheckGlobalVariables(List compiledVars)
Perform type checking on global 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 QueryModule(StaticQueryContext sqc) throws XPathException
sqc
- the StaticQueryContext object from which this module is initialized
XPathException
public QueryModule(Configuration config, QueryModule importer)
config
- the Saxon configurationimporter
- the module that imported this module. This may be null, in the case where
the library module is being imported into an XSLT stylesheetMethod Detail |
---|
public static QueryModule makeQueryModule(String baseURI, Executable executable, QueryModule importer, String query, String namespaceURI, boolean allowCycles) throws XPathException
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 loadedallowCycles
- True if cycles of module imports (disallowed by the spec) are to be permitted
XPathException
public Configuration getConfiguration()
getConfiguration
in interface StaticContext
public NamePool getNamePool()
getNamePool
in interface StaticContext
public boolean isTopLevelModule()
public boolean isMainModule()
public boolean mayImportModule(String namespace)
namespace
- the namespace to be tested
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 setConstructionMode(int mode)
mode
- one of Validation.STRIP
, Validation.PRESERVE
public int getConstructionMode()
Validation.STRIP
, Validation.PRESERVE
public void setPreserveBoundarySpace(boolean preserve)
preserve
- true if boundary space is to be preserved, false if it is to be strippedpublic boolean isPreserveBoundarySpace()
public void setEmptyLeast(boolean least)
least
- true if the empty sequence is considered less than any other value (the default),
false if it is considered greater than any other valuepublic boolean isEmptyLeast()
public XQueryFunctionLibrary getGlobalFunctionLibrary()
public ImportedFunctionLibrary getImportedFunctionLibrary()
public void addImportedNamespace(String uri)
This method is intended for internal use.
uri
- the URI of the imported namespace.public boolean importsNamespace(String uri)
This method is intended for internal use.
uri
- the URI of the possibly-imported namespace.
public boolean importsNamespaceIndirectly(String uri)
This method is intended for internal use.
uri
- the URI of the possibly-imported namespace.
public Iterator iterateImportedNamespaces()
public QueryModule getTopLevelModule(QueryModule start)
start
- the StaticQueryContext where the search started
public Executable getExecutable()
public void setExecutable(Executable executable)
executable
- the Executablepublic StaticQueryContext getUserQueryContext()
public LocationMap getLocationMap()
getLocationMap
in interface StaticContext
public void setModuleNamespace(String uri)
uri
- the module namespace URI of the library modulepublic String getModuleNamespace()
public short getModuleNamespaceCode()
public void setLocationURI(URI uri)
uri
- the location URIpublic URI getLocationURI()
public String getSystemId()
getSystemId
in interface StaticContext
public void setBaseURI(String uri)
uri
- the base URIpublic String getBaseURI()
getBaseURI
in interface StaticContext
public SlotManager getGlobalStackFrameMap()
public void declareVariable(VariableDeclaration var) throws XPathException
Note that the same VariableDeclaration 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.
var
- the Variable declaration being declared
XPathException
public List fixupGlobalVariables(SlotManager globalVariableMap) throws XPathException
globalVariableMap
- a SlotManager that holds details of the assignment of slots to global variables.
XPathException
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.)
referees
- a Stack containing the chain of module import references leading to this
modulelineNumber
- used for diagnostics
XPathException
public Iterator getModuleVariables()
public void checkForCircularities(List compiledVars, XQueryFunctionLibrary globalFunctionLibrary) throws XPathException
This method is intended for internal use
compiledVars
- a list of GlobalVariableDefinition
objects to be checked
XPathException
public void typeCheckGlobalVariables(List compiledVars) throws XPathException
This method is intended for internal use
compiledVars
- a list of GlobalVariableDefinition
objects to be checked
XPathException
public VariableReference bindVariable(StructuredQName qName) throws XPathException
bindVariable
in interface StaticContext
qName
- the name of the variable to be bound
XPathException
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 XPathException
function
- the function being declared
XPathException
public void bindUnboundFunctionCalls() throws XPathException
XPathException
- if a function call refers to a function that has
not been declaredpublic void fixupGlobalFunctions() throws XPathException
XPathException
public void optimizeGlobalFunctions() throws XPathException
XPathException
public void explainGlobalFunctions(ExpressionPresenter out)
out
- the expression presenter used to display the outputpublic 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 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 void reportFatalError(XPathException err)
err
- the error to be signalledpublic void checkImportedFunctionSignature(XQueryFunction fd) throws XPathException
fd
- the declaration of the imported function
XPathException
- if an error is foundpublic void checkImportedType(SequenceType importedType, Declaration declaration) throws XPathException
importedType
- the type that is to be checkeddeclaration
- the containing query or function definition
XPathException
- if an error is fonnd.public XPathContext makeEarlyEvaluationContext()
makeEarlyEvaluationContext
in interface StaticContext
public StringCollator getCollation(String name)
getCollation
in interface StaticContext
name
- The name of the required collation. Supply null to get the default collation.
public String getDefaultCollationName()
getDefaultCollationName
in interface StaticContext
public void setDefaultCollationName(String collation)
collation
- the URI of the default collationpublic void declarePrologNamespace(String prefix, String uri) throws XPathException
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.
XPathException
public void declareActiveNamespace(String prefix, String uri)
undeclareNamespace()
.
This method is intended for internal use only.
prefix
- the namespace prefixuri
- the namespace URIpublic void undeclareNamespace()
declareActiveNamespace(String, String)
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 for elements and types.
public String getDefaultElementNamespace()
getDefaultElementNamespace
in interface StaticContext
public void setDefaultElementNamespace(String uri)
uri
- the default namespace for elements and typespublic String getDefaultFunctionNamespace()
getDefaultFunctionNamespace
in interface StaticContext
public void setDefaultFunctionNamespace(String uri)
uri
- the default namespace for functionspublic int[] getActiveNamespaceCodes()
public NamespaceResolver getNamespaceResolver()
getNamespaceResolver
in interface StaticContext
public void issueWarning(String s, SourceLocator locator)
issueWarning
in interface StaticContext
s
- The warning message. This should not contain any prefix such as "Warning".locator
- the location of the construct in question. May be null.public int getLineNumber()
getLineNumber
in interface StaticContext
public boolean isInBackwardsCompatibleMode()
isInBackwardsCompatibleMode
in interface StaticContext
public boolean isAllowedBuiltInType(BuiltInAtomicType type)
isAllowedBuiltInType
in interface StaticContext
type
- the supposedly built-in type. This will always be a type in the
XS or XDT namespace.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |