public class QueryModule extends Object implements StaticContext
Constructor and Description |
---|
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
|
Modifier and Type | Method and Description |
---|---|
void |
addImportedNamespace(String uri)
Register that this module imports a particular module namespace
|
void |
addImportedSchema(String targetNamespace,
String baseURI,
List<String> locationURIs)
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)
|
Expression |
bindVariable(StructuredQName qName)
Bind a variable used in a query to the expression in which it is declared.
|
void |
checkForCircularities(List<GlobalVariable> 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(GlobalVariable 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<GlobalVariable> |
fixupGlobalVariables(SlotManager globalVariableMap,
GlobalVariable contextItemVar)
Fixup all references to global variables.
|
NamespaceBinding[] |
getActiveNamespaceCodes()
Get an array containing the namespace codes of all active namespaces.
|
Map<String,HashSet<String>> |
getAllImportedSchemata()
For the top-level module only, get all the schema modules imported anywhere in the query.
|
String |
getBaseURI()
Get the base URI for a module
|
CodeInjector |
getCodeInjector()
Get the CodeInjector if one is in use
|
StringCollator |
getCollation(String name)
Get a named collation.
|
Configuration |
getConfiguration()
Get the Saxon Configuration
|
int |
getConstructionMode()
Get the current construction mode
|
DecimalFormatManager |
getDecimalFormatManager()
Get a DecimalFormatManager to resolve the names of decimal formats used in calls
to the format-number() function.
|
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.
|
Set<LanguageFeature> |
getFeaturesProhibited() |
Set<LanguageFeature> |
getFeaturesRequired() |
Map<LanguageFeature,SourceLocator> |
getFeaturesUsed() |
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.
|
Iterator<GlobalVariable> |
getGlobalVariables()
Get all global variables declared in or imported into this module
|
ImportedFunctionLibrary |
getImportedFunctionLibrary()
Get the function library object that holds details of imported functions
|
Set<String> |
getImportedSchemaNamespaces()
Get the set of imported schemas
|
DecimalValue |
getLanguageVersion()
Get the language version supported
|
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.
|
Iterator<GlobalVariable> |
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.
|
int |
getRevalidationMode()
Get the revalidation mode.
|
String |
getSystemId()
Get the System ID for a module
|
QueryModule |
getTopLevelModule()
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
|
DecimalValue |
getXPathLanguageLevel()
Get the XPath language level supported
|
boolean |
importsNamespace(String uri)
Ask whether this module directly imports a particular namespace
|
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
|
boolean |
isSchemaAware()
Ask whether expressions compiled under this static context are schema-aware.
|
void |
issueWarning(String s,
SourceLocator locator)
Issue a compile-time warning.
|
boolean |
isTopLevelModule()
Test whether this is a "top-level" module.
|
boolean |
isUpdating()
Ask whether the query is allowed to be updating
|
void |
lookForModuleCycles(Stack<QueryModule> 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 |
setInheritNamespaces(boolean inherit)
Set the namespace inheritance mode
|
void |
setIsMainModule(boolean main)
Set whether this is a "Main" module, in the sense of the XQuery language specification
|
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 |
setRevalidationMode(int mode)
Set the revalidation mode.
|
void |
setUpdating(boolean updating)
Set whether the query is allowed to be updating
|
void |
typeCheckGlobalVariables(List<GlobalVariable> compiledVars)
Perform type checking on global variables.
|
void |
undeclareNamespace()
Undeclare the most recently-declared active namespace.
|
void |
useFeature(LanguageFeature feature,
String construct,
SourceLocator locator) |
public QueryModule(StaticQueryContext sqc) throws XPathException
sqc
- the StaticQueryContext object from which this module is initializedXPathException
- if information supplied is invalidpublic 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 stylesheetpublic 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 permittedXPathException
- if an error occurspublic Configuration getConfiguration()
getConfiguration
in interface StaticContext
public NamePool getNamePool()
getNamePool
in interface StaticContext
public boolean isTopLevelModule()
public void setIsMainModule(boolean main)
main
- true if this is a main module, false if it is a library modulepublic boolean isMainModule()
public boolean mayImportModule(String namespace)
namespace
- the namespace to be testedpublic boolean isSchemaAware()
isSchemaAware
in interface StaticContext
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 QueryModule getTopLevelModule()
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 module. Null is allowed only
for a main module, not for a library module.public String getModuleNamespace()
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(GlobalVariable 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 declaredXPathException
- if a static error is detectedpublic Iterator<GlobalVariable> getGlobalVariables()
public List<GlobalVariable> fixupGlobalVariables(SlotManager globalVariableMap, GlobalVariable contextItemVar) throws XPathException
globalVariableMap
- a SlotManager that holds details of the assignment of slots to global variables.contextItemVar
- the variable holding the context itemXPathException
- if compiling a global variable definition failspublic void lookForModuleCycles(Stack<QueryModule> 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 diagnosticsXPathException
- if cycles are foundpublic Iterator<GlobalVariable> getModuleVariables()
public void checkForCircularities(List<GlobalVariable> compiledVars, XQueryFunctionLibrary globalFunctionLibrary) throws XPathException
This method is intended for internal use
compiledVars
- a list of GlobalVariable
objects to be checkedglobalFunctionLibrary
- the library of global functionsXPathException
- if a circularity is foundpublic void typeCheckGlobalVariables(List<GlobalVariable> compiledVars) throws XPathException
This method is intended for internal use
compiledVars
- a list of GlobalVariable
objects to be checkedXPathException
- if a type error occurspublic Expression bindVariable(StructuredQName qName) throws XPathException
bindVariable
in interface StaticContext
qName
- the name of the variable to be boundXPathException
public FunctionLibrary getFunctionLibrary()
getFunctionLibrary
in interface StaticContext
FunctionLibraryList
public XQueryFunctionLibrary getLocalFunctionLibrary()
public void declareFunction(XQueryFunction function) throws XPathException
function
- the function being declaredXPathException
- if an error occurs, for example
a duplicate function namepublic void bindUnboundFunctionCalls() throws XPathException
XPathException
- if a function call refers to a function that has
not been declaredpublic void fixupGlobalFunctions() throws XPathException
XPathException
- if an error occurspublic void optimizeGlobalFunctions() throws XPathException
XPathException
- if an error occurs during optimizationpublic 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
- if an error occurs, for example if the
variable reference cannot be resolved or if the variable is privatepublic void addImportedSchema(String targetNamespace, String baseURI, List<String> locationURIs)
targetNamespace
- The target namespace of the schema to be addedbaseURI
- The base URI against which the locationURIs are to be absolutizedlocationURIs
- a list of strings containing the absolutized URIs of the "location hints" supplied
for this schemapublic Map<String,HashSet<String>> getAllImportedSchemata()
public boolean isImportedSchema(String namespace)
isImportedSchema
in interface StaticContext
namespace
- The namespace of the required schema. Supply "" for
a no-namespace schema.public Set<String> 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 functionXPathException
- 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 definitionXPathException
- 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 collationNullPointerException
- if the supplied collation name is nullpublic Map<LanguageFeature,SourceLocator> getFeaturesUsed()
public Set<LanguageFeature> getFeaturesProhibited()
public Set<LanguageFeature> getFeaturesRequired()
public void useFeature(LanguageFeature feature, String construct, SourceLocator locator) throws XPathException
XPathException
public 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
- if the declaration is invalidpublic void declareActiveNamespace(String prefix, String uri)
undeclareNamespace()
.
This method is intended for internal use only.prefix
- the namespace prefixuri
- the namespace URIpublic void undeclareNamespace()
public String getURIForPrefix(String prefix) throws XPathException
getURIForPrefix
in interface StaticContext
prefix
- The prefixXPathException
- (with error code XPST0081)
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
NamespaceConstant.NULL
for the non-namespacepublic 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 void setRevalidationMode(int mode)
mode
- the revalidation mode. This must be one of Validation.STRICT
,
Validation.LAX
, or Validation.SKIP
public int getRevalidationMode()
Validation.STRICT
,
Validation.LAX
, or Validation.SKIP
public NamespaceBinding[] getActiveNamespaceCodes()
public NamespaceResolver getNamespaceResolver()
getNamespaceResolver
in interface StaticContext
public ItemType getRequiredContextItemType()
getRequiredContextItemType
in interface StaticContext
public DecimalFormatManager getDecimalFormatManager()
getDecimalFormatManager
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.public void setUpdating(boolean updating)
updating
- true if the query may use the XQuery Update facility (requires Saxon-EE)public boolean isUpdating()
public DecimalValue getLanguageVersion()
public DecimalValue getXPathLanguageLevel()
getXPathLanguageLevel
in interface StaticContext
public CodeInjector getCodeInjector()
Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.