public class QueryModule extends java.lang.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(java.lang.String uri)
Register that this module imports a particular module namespace
|
void |
addImportedSchema(java.lang.String targetNamespace,
java.lang.String baseURI,
java.util.List<java.lang.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(java.util.List<GlobalVariable> compiledVars,
XQueryFunctionLibrary globalFunctionLibrary)
Check for circular definitions of global variables.
|
java.lang.String |
checkURIForPrefix(java.lang.String prefix)
Get the URI for a prefix if there is one, return null if not.
|
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 |
declareFunction(XQueryFunction function)
Register a user-defined XQuery function.
|
void |
declarePrologNamespace(java.lang.String prefix,
java.lang.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.
|
java.util.List<GlobalVariable> |
fixupGlobalVariables(SlotManager globalVariableMap)
Fixup all references to global variables.
|
NamespaceBinding[] |
getActiveNamespaceCodes()
Get an array containing the namespace codes of all active namespaces.
|
BuiltInFunctionSet |
getBuiltInFunctionSet() |
CodeInjector |
getCodeInjector()
Get the CodeInjector if one is in use
|
Configuration |
getConfiguration()
Get the Saxon Configuration
|
int |
getConstructionMode()
Get the current construction mode
|
Location |
getContainingLocation()
Get the LocationMap, an data structure used to identify the location of compiled expressions within
the query source text.
|
DecimalFormatManager |
getDecimalFormatManager()
Get a DecimalFormatManager to resolve the names of decimal formats used in calls
to the format-number() function.
|
java.lang.String |
getDefaultCollationName()
Get the name of the default collation.
|
java.lang.String |
getDefaultElementNamespace()
Get the default XPath namespace for elements and types.
|
java.lang.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.
|
java.lang.Iterable<GlobalVariable> |
getGlobalVariables()
Get all global variables imported into this module
|
ImportedFunctionLibrary |
getImportedFunctionLibrary()
Get the function library object that holds details of imported functions
|
java.util.Set<java.lang.String> |
getImportedSchemaNamespaces()
Get the set of imported schemas
|
KeyManager |
getKeyManager()
Get the KeyManager, containing definitions of keys available for use.
|
NamespaceResolver |
getLiveNamespaceResolver()
Return a NamespaceResolver which is "live" in the sense that, as the parse proceeeds,
it always uses the namespaces declarations in scope at the relevant time
|
XQueryFunctionLibrary |
getLocalFunctionLibrary()
Get the functions declared locally within this module
|
java.net.URI |
getLocationURI()
Get the location URI for a module
|
java.lang.String |
getModuleNamespace()
Get the namespace of the current library module.
|
java.util.Iterator<GlobalVariable> |
getModuleVariables()
Get global variables declared in this module
|
NamespaceResolver |
getNamespaceResolver()
Get a copy of the Namespace Context.
|
OptimizerOptions |
getOptimizerOptions()
Get the optimization options in use.
|
PackageData |
getPackageData()
Get package data.
|
ItemType |
getRequiredContextItemType()
Get the required type of the context item.
|
int |
getRevalidationMode()
Get the revalidation mode.
|
java.lang.String |
getStaticBaseURI()
Get the base URI for a module
|
java.lang.String |
getSystemId()
Get the System ID for a module
|
QueryModule |
getTopLevelModule()
Get the QueryModule for the top-level module.
|
UserFunction |
getUserDefinedFunction(java.lang.String uri,
java.lang.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
|
int |
getXPathVersion()
Get the XPath language level supported, as an integer (being the actual version
number times ten).
|
boolean |
importsNamespace(java.lang.String uri)
Ask whether this module directly imports a particular namespace
|
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(java.lang.String namespace)
Ask whether a given schema target namespace 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(java.lang.String s,
Location locator)
Issue a compile-time warning.
|
boolean |
isTopLevelModule()
Test whether this is a "top-level" module.
|
boolean |
isUpdating()
Ask whether the query module is allowed to be updating
|
void |
lookForModuleCycles(java.util.Stack<QueryModule> referees,
int lineNumber)
Look for module cycles.
|
XPathContext |
makeEarlyEvaluationContext()
Construct a dynamic context for early evaluation of constant subexpressions
|
static QueryModule |
makeQueryModule(java.lang.String baseURI,
Executable executable,
QueryModule importer,
java.lang.String query,
java.lang.String namespaceURI)
Supporting method to load an imported library module.
|
RetainedStaticContext |
makeRetainedStaticContext()
Construct a RetainedStaticContext, which extracts information from this StaticContext
to provide the subset of static context information that is potentially needed
during expression evaluation
|
boolean |
mayImportModule(java.lang.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 |
reportStaticError(XPathException err)
Report a static error in the query (via the registered ErrorListener)
|
ItemType |
resolveTypeAlias(StructuredQName typeName)
Get type alias.
|
void |
setBaseURI(java.lang.String uri)
Set the base URI for a module
|
void |
setConstructionMode(int mode)
Set the construction mode for this module
|
void |
setDefaultCollationName(java.lang.String collation)
Set the name of the default collation
|
void |
setDefaultElementNamespace(java.lang.String uri)
Set the default element namespace as declared in the query prolog
|
void |
setDefaultFunctionNamespace(java.lang.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(java.net.URI uri)
Set the location URI for a module
|
void |
setModuleNamespace(java.lang.String uri)
Set the namespace for a library module.
|
void |
setPackageData(PackageData packageData)
Set the package data.
|
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 |
typeCheckGlobalVariables(java.util.List<GlobalVariable> compiledVars)
Perform type checking on global variables.
|
void |
undeclareNamespace()
Undeclare the most recently-declared active namespace.
|
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(java.lang.String baseURI, Executable executable, QueryModule importer, java.lang.String query, java.lang.String namespaceURI) throws XPathException
This method is intended for internal use only.
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 loadedXPathException
- if an error occurspublic BuiltInFunctionSet getBuiltInFunctionSet()
public Configuration getConfiguration()
getConfiguration
in interface StaticContext
public PackageData getPackageData()
getPackageData
in interface StaticContext
public void setPackageData(PackageData packageData)
packageData
- the package informationpublic 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(java.lang.String namespace)
namespace
- the namespace to be testedpublic boolean isSchemaAware()
public OptimizerOptions getOptimizerOptions()
Configuration
getOptimizerOptions
in interface StaticContext
public RetainedStaticContext makeRetainedStaticContext()
makeRetainedStaticContext
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(java.lang.String uri)
This method is intended for internal use.
uri
- the URI of the imported namespace.public boolean importsNamespace(java.lang.String uri)
This method is intended for internal use.
uri
- the URI of the possibly-imported namespace.public QueryModule getTopLevelModule()
public Executable getExecutable()
This method is intended for internal use only.
public void setExecutable(Executable executable)
This method is intended for internal use only.
executable
- the Executablepublic StaticQueryContext getUserQueryContext()
public Location getContainingLocation()
This method is intended for internal use only.
getContainingLocation
in interface StaticContext
public void setModuleNamespace(java.lang.String uri)
This method is for internal use only.
uri
- the module namespace URI of the library module. Null is allowed only
for a main module, not for a library module.public java.lang.String getModuleNamespace()
This method is intended primarily for internal use.
public void setLocationURI(java.net.URI uri)
uri
- the location URIpublic java.net.URI getLocationURI()
public java.lang.String getSystemId()
getSystemId
in interface StaticContext
public void setBaseURI(java.lang.String uri)
uri
- the base URIpublic java.lang.String getStaticBaseURI()
getStaticBaseURI
in interface StaticContext
public SlotManager getGlobalStackFrameMap()
This method is intended for internal use.
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 java.lang.Iterable<GlobalVariable> getGlobalVariables()
public java.util.List<GlobalVariable> fixupGlobalVariables(SlotManager globalVariableMap) throws XPathException
This method is for internal use by the Query Parser only.
globalVariableMap
- a SlotManager that holds details of the assignment of slots to global variables.XPathException
- if compiling a global variable definition failspublic void lookForModuleCycles(java.util.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 java.util.Iterator<GlobalVariable> getModuleVariables()
public void checkForCircularities(java.util.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(java.util.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
This method is provided for use by the XQuery parser, and it should not be called by the user of the API, or overridden, unless variables are to be declared using a mechanism other than the declareVariable method of this class.
bindVariable
in interface StaticContext
qName
- the name of the variable to be boundXPathException
- if the variable cannot be bound (has not been declared)public FunctionLibrary getFunctionLibrary()
This method is provided for use by advanced applications. The details of the interface are subject to change.
getFunctionLibrary
in interface StaticContext
FunctionLibraryList
public XQueryFunctionLibrary getLocalFunctionLibrary()
public void declareFunction(XQueryFunction function) throws XPathException
This method is intended for internal use only.
function
- the function being declaredXPathException
- if an error occurs, for example
a duplicate function namepublic void bindUnboundFunctionCalls() throws XPathException
This method is for internal use only.
XPathException
- if a function call refers to a function that has
not been declaredpublic void fixupGlobalFunctions() throws XPathException
This method is for internal use only. It is called only on the StaticQueryContext for the main query body (not for library modules).
XPathException
- if an error occurspublic void optimizeGlobalFunctions() throws XPathException
This method is for internal use only. It is called only on the StaticQueryContext for the main query body (not for library modules).
XPathException
- if an error occurs during optimizationpublic void explainGlobalFunctions(ExpressionPresenter out) throws XPathException
This method is intended primarily for internal use.
out
- the expression presenter used to display the outputXPathException
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 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(java.lang.String targetNamespace, java.lang.String baseURI, java.util.List<java.lang.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 boolean isImportedSchema(java.lang.String namespace)
isImportedSchema
in interface StaticContext
namespace
- The namespace of the required schema. Supply "" for
a no-namespace schema.public java.util.Set<java.lang.String> getImportedSchemaNamespaces()
getImportedSchemaNamespaces
in interface StaticContext
public void reportStaticError(XPathException err)
err
- the error to be signalledpublic XPathContext makeEarlyEvaluationContext()
makeEarlyEvaluationContext
in interface StaticContext
public java.lang.String getDefaultCollationName()
getDefaultCollationName
in interface StaticContext
public void setDefaultCollationName(java.lang.String collation)
collation
- the URI of the default collationpublic void declarePrologNamespace(java.lang.String prefix, java.lang.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(java.lang.String prefix, java.lang.String uri)
undeclareNamespace()
.
This method is intended for internal use only.
prefix
- the namespace prefixuri
- the namespace URIpublic void undeclareNamespace()
This method is intended for internal use only.
declareActiveNamespace(String, String)
public NamespaceResolver getLiveNamespaceResolver()
public java.lang.String checkURIForPrefix(java.lang.String prefix)
This method is intended primarily for internal use.
prefix
- The prefix. Supply "" to obtain the default namespace for elements and types.public java.lang.String getDefaultElementNamespace()
getDefaultElementNamespace
in interface StaticContext
NamespaceConstant.NULL
for the non-namespacepublic void setDefaultElementNamespace(java.lang.String uri)
uri
- the default namespace for elements and typespublic java.lang.String getDefaultFunctionNamespace()
getDefaultFunctionNamespace
in interface StaticContext
public void setDefaultFunctionNamespace(java.lang.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()
This method is for internal use only.
public NamespaceResolver getNamespaceResolver()
This method is for internal use only.
getNamespaceResolver
in interface StaticContext
public ItemType getRequiredContextItemType()
getRequiredContextItemType
in interface StaticContext
public DecimalFormatManager getDecimalFormatManager()
getDecimalFormatManager
in interface StaticContext
public void issueWarning(java.lang.String s, Location locator)
This method is intended for internal use only.
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 boolean isInBackwardsCompatibleMode()
isInBackwardsCompatibleMode
in interface StaticContext
public boolean isUpdating()
public int getXPathVersion()
getXPathVersion
in interface StaticContext
public CodeInjector getCodeInjector()
public KeyManager getKeyManager()
getKeyManager
in interface StaticContext
public ItemType resolveTypeAlias(StructuredQName typeName)
resolveTypeAlias
in interface StaticContext
typeName
- the name of the type aliasCopyright (c) 2004-2020 Saxonica Limited. All rights reserved.