org.exist.xquery
Class ModuleContext

java.lang.Object
  extended by org.exist.xquery.XQueryContext
      extended by org.exist.xquery.ModuleContext
All Implemented Interfaces:
Context, BinaryValueManager

public class ModuleContext
extends XQueryContext

Subclass of XQueryContext for imported modules.


Field Summary
 
Fields inherited from class org.exist.xquery.XQueryContext
allModules, attributes, baseURI, baseURISetInProlog, BUILT_IN_MODULE_CLASS_ATTRIBUTE, BUILT_IN_MODULE_SOURCE_ATTRIBUTE, BUILT_IN_MODULE_URI_ATTRIBUTE, callStack, contextStack, db, declaredFunctions, defaultElementNamespace, defaultElementNamespaceSchema, defaultFunctionNamespace, dynamicOptions, ENABLE_QUERY_REWRITING_ATTRIBUTE, forwardReferences, globalVariables, HTTP_SESSIONVAR_XMLDB_USER, inheritedInScopeNamespaces, inheritedInScopePrefixes, inScopeNamespaces, inScopePrefixes, lastVar, LOG, mappedModules, modifiedDocuments, modules, namespaceStack, profiler, PROPERTY_BUILT_IN_MODULES, PROPERTY_ENABLE_QUERY_REWRITING, PROPERTY_MODULE_PARAMETERS, PROPERTY_STATIC_MODULE_MAP, PROPERTY_XQUERY_BACKWARD_COMPATIBLE, PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, savedState, staticCollections, staticDocumentPaths, staticDocuments, staticNamespaces, staticOptions, staticPrefixes, variableStackSize, watchdog, XQUERY_BACKWARD_COMPATIBLE_ATTRIBUTE, XQUERY_CONTEXTVAR_XQUERY_UPDATE_ERROR, XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL_ATTRIBUTE, XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL_DEFAULT
 
Constructor Summary
ModuleContext(XQueryContext parentContext, java.lang.String modulePrefix, java.lang.String moduleNamespace, java.lang.String location)
           
 
Method Summary
 void addDynamicOption(java.lang.String qnameString, java.lang.String contents)
          for dynamic run-time options i.e.
protected  void clearUpdateListeners()
           
 XQueryContext copyContext()
           
 void declareInScopeNamespace(java.lang.String prefix, java.lang.String uri)
          Declare an in-scope namespace.
 LocalVariable declareVariableBinding(LocalVariable var)
          Declare a local variable.
 void expressionEnd(Expression expr)
           
 void expressionStart(Expression expr)
           
 java.util.Iterator<Module> getAllModules()
           
 AnyURIValue getBaseURI()
          Get the base URI of the evaluation context.
 javax.xml.datatype.XMLGregorianCalendar getCalendar()
           
 int getCurrentStackSize()
          Returns the current size of the stack.
 DebuggeeJoint getDebuggeeJoint()
           
 MemTreeBuilder getDocumentBuilder()
          Get the document builder currently used for creating temporary document fragments.
 MemTreeBuilder getDocumentBuilder(boolean explicitCreation)
           
 java.util.Map<QName,Variable> getGlobalVariables()
           
 java.lang.String getInheritedNamespace(java.lang.String prefix)
           
 java.lang.String getInheritedPrefix(java.lang.String uri)
           
 java.lang.String getInScopeNamespace(java.lang.String prefix)
           
 java.lang.String getInScopePrefix(java.lang.String uri)
           
 java.util.Map<QName,Variable> getLocalVariables()
           
 Module getModule(java.lang.String namespaceURI)
          Get the built-in module registered for the given namespace URI.
 java.lang.String getPrefixForURI(java.lang.String uri)
          First checks the parent context for in-scope namespaces, then the module's static context.
 Profiler getProfiler()
          Returns the Profiler instance of this context if profiling is enabled.
 XQueryContext getRootContext()
           
 Module getRootModule(java.lang.String namespaceURI)
           
 java.util.Iterator<Module> getRootModules()
          Get root modules
 DocumentSet getStaticallyKnownDocuments()
          Get statically known documents
 java.lang.String getURIForPrefix(java.lang.String prefix)
          First checks the parent context for in-scope namespaces, then the module's static context.
 java.util.Map<QName,Variable> getVariables()
           
 XQueryWatchDog getWatchDog()
           
 java.lang.Object getXQueryContextVar(java.lang.String name)
          Delegate to parent context
 boolean hasParent()
          Returns true if this context has a parent context (means it is a module context).
 boolean isDebugMode()
           
 Module loadBuiltInModule(java.lang.String namespaceURI, java.lang.String moduleClass)
          Overwritten method: the module will be loaded by the parent context, but we need to declare its namespace in the module context.
 LocalVariable markLocalVariables(boolean newContext)
          Returns the last variable on the local variable stack.
 void popDocumentContext()
           
 void popInScopeNamespaces()
           
 void popLocalVariables(LocalVariable var)
          Restore the local variable stack to the position marked by variable var.
 void pushDocumentContext()
          Push any document fragment created within the current execution context on the stack.
 void pushInScopeNamespaces()
           
 void pushInScopeNamespaces(boolean inherit)
          Push all in-scope namespace declarations onto the stack.
 void registerUpdateListener(UpdateListener listener)
           
protected  Variable resolveLocalVariable(QName qname)
           
 Variable resolveVariable(QName qname)
          Try to resolve a variable.
 void saveState()
          Before a dynamic import, make sure relevant parts of the current context a saved to the stack.
 void setBaseURI(AnyURIValue uri)
          Set the base URI for the evaluation context.
 void setModule(java.lang.String namespaceURI, Module module)
           
 void setParentContext(XQueryContext parentContext)
           
protected  void setRootModule(java.lang.String namespaceURI, Module module)
           
 void setXQueryContextVar(java.lang.String name, java.lang.Object XQvar)
          Delegate to parent context
 void stackEnter(Expression expr)
           
 void stackLeave(Expression expr)
           
 void updateContext(XQueryContext from)
          Update the current dynamic context using the properties of another context.
 void updateModuleRefs(XQueryContext rootContext)
           
 
Methods inherited from class org.exist.xquery.XQueryContext
addForwardReference, addLockedDocument, addModifiedDoc, addOption, analyzeAndOptimizeIfModulesChanged, checkModulesValid, checkOptions, cleanupBinaryValueInstances, copyFields, declareFunction, declareGlobalVariable, declareNamespace, declareNamespaces, declareVariable, declareVariable, finishBatchTransaction, functionEnd, functionStart, getAccessContext, getAttribute, getBatchTransaction, getBroker, getCollator, getContext, getContextPosition, getContextSequence, getDatabase, getDefaultCollation, getDefaultCollator, getDefaultElementNamespace, getDefaultElementNamespaceSchema, getDefaultFunctionNamespace, getExpressionCount, getImplicitTimeZone, getMappedModuleURIs, getModuleLoadPath, getModuleLocation, getModules, getOption, getPDP, getPragma, getProtectedDocs, getRepository, getRootExpression, getSharedNamePool, getSignaturesForFunction, getSource, getSourceKey, getSourceType, getSubject, getUser, getUserFromHttpSession, getXMLStreamReader, getXQueryVersion, hasBatchTransaction, importModule, inheritNamespaces, initBuiltInModule, inProtectedMode, instantiateModule, isBackwardsCompatible, isBaseURIDeclared, isProfilingEnabled, isProfilingEnabled, isRaiseErrorOnFailedRetrieval, isShared, isVarDeclared, loadDefaultNS, loadDefaults, localFunctions, lockDocumentsOnLoad, mapModule, nextExpressionId, optimizationsEnabled, orderEmptyGreatest, popNamespaceContext, prepareForExecution, preserveNamespaces, proceed, proceed, proceed, prologEnter, pushNamespaceContext, registerBinaryValueInstance, removeNamespace, requireDebugMode, reset, reset, resolveForwardReferences, resolveFunction, resolveVariable, setAttribute, setBackwardsCompatibility, setBaseURI, setBatchTransactionTrigger, setCalendar, setContextSequencePosition, setDebuggeeJoint, setDefaultCollation, setDefaultElementNamespace, setDefaultElementNamespaceSchema, setDefaultFunctionNamespace, setInheritNamespaces, setModuleLoadPath, setOrderEmptyGreatest, setPreserveNamespaces, setProtectedDocs, setRootExpression, setShared, setSource, setStaticallyKnownDocuments, setStaticallyKnownDocuments, setStripWhitespace, setTimeZone, setWatchDog, setXQueryVersion, startBatchTransaction, storeTemporaryDoc, stripWhitespace, tailRecursiveCall, undeclareGlobalVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModuleContext

public ModuleContext(XQueryContext parentContext,
                     java.lang.String modulePrefix,
                     java.lang.String moduleNamespace,
                     java.lang.String location)
Parameters:
parentContext -
Method Detail

setParentContext

public void setParentContext(XQueryContext parentContext)

setModule

public void setModule(java.lang.String namespaceURI,
                      Module module)
Specified by:
setModule in interface Context
Overrides:
setModule in class XQueryContext

hasParent

public boolean hasParent()
Description copied from class: XQueryContext
Returns true if this context has a parent context (means it is a module context).

Specified by:
hasParent in interface Context
Overrides:
hasParent in class XQueryContext
Returns:
False.

getRootContext

public XQueryContext getRootContext()
Specified by:
getRootContext in interface Context
Overrides:
getRootContext in class XQueryContext

updateContext

public void updateContext(XQueryContext from)
Description copied from class: XQueryContext
Update the current dynamic context using the properties of another context. This is needed by Eval.

Specified by:
updateContext in interface Context
Overrides:
updateContext in class XQueryContext

copyContext

public XQueryContext copyContext()
Specified by:
copyContext in interface Context
Overrides:
copyContext in class XQueryContext

addDynamicOption

public void addDynamicOption(java.lang.String qnameString,
                             java.lang.String contents)
                      throws XPathException
Description copied from class: XQueryContext
for dynamic run-time options i.e. util:declare-option

Specified by:
addDynamicOption in interface Context
Overrides:
addDynamicOption in class XQueryContext
Throws:
XPathException

getStaticallyKnownDocuments

public DocumentSet getStaticallyKnownDocuments()
                                        throws XPathException
Description copied from class: XQueryContext
Get statically known documents

Specified by:
getStaticallyKnownDocuments in interface Context
Overrides:
getStaticallyKnownDocuments in class XQueryContext
Returns:
set of statically known documents.
Throws:
XPathException

getModule

public Module getModule(java.lang.String namespaceURI)
Description copied from class: XQueryContext
Get the built-in module registered for the given namespace URI.

Specified by:
getModule in interface Context
Overrides:
getModule in class XQueryContext
Returns:
built-in module

setRootModule

protected void setRootModule(java.lang.String namespaceURI,
                             Module module)
Overrides:
setRootModule in class XQueryContext

getRootModules

public java.util.Iterator<Module> getRootModules()
Description copied from class: XQueryContext
Get root modules

Specified by:
getRootModules in interface Context
Overrides:
getRootModules in class XQueryContext
Returns:
iterator over all modules registered in the entire context tree

getAllModules

public java.util.Iterator<Module> getAllModules()
Specified by:
getAllModules in interface Context
Overrides:
getAllModules in class XQueryContext

getRootModule

public Module getRootModule(java.lang.String namespaceURI)
Specified by:
getRootModule in interface Context
Overrides:
getRootModule in class XQueryContext

loadBuiltInModule

public Module loadBuiltInModule(java.lang.String namespaceURI,
                                java.lang.String moduleClass)
Overwritten method: the module will be loaded by the parent context, but we need to declare its namespace in the module context.

Specified by:
loadBuiltInModule in interface Context
Overrides:
loadBuiltInModule in class XQueryContext
Returns:
Module

updateModuleRefs

public void updateModuleRefs(XQueryContext rootContext)

getWatchDog

public XQueryWatchDog getWatchDog()
Specified by:
getWatchDog in interface Context
Overrides:
getWatchDog in class XQueryContext

getProfiler

public Profiler getProfiler()
Description copied from class: XQueryContext
Returns the Profiler instance of this context if profiling is enabled.

Specified by:
getProfiler in interface Context
Overrides:
getProfiler in class XQueryContext
Returns:
the profiler instance.

getCalendar

public javax.xml.datatype.XMLGregorianCalendar getCalendar()
Specified by:
getCalendar in interface Context
Overrides:
getCalendar in class XQueryContext

getBaseURI

public AnyURIValue getBaseURI()
                       throws XPathException
Description copied from class: XQueryContext
Get the base URI of the evaluation context.

This is the URI returned by the fn:base-uri() function.

Specified by:
getBaseURI in interface Context
Overrides:
getBaseURI in class XQueryContext
Returns:
base URI of the evaluation context
Throws:
XPathException - if an error occurs

setBaseURI

public void setBaseURI(AnyURIValue uri)
Description copied from class: XQueryContext
Set the base URI for the evaluation context.

This is the URI returned by the fn:base-uri() function.

Specified by:
setBaseURI in interface Context
Overrides:
setBaseURI in class XQueryContext

setXQueryContextVar

public void setXQueryContextVar(java.lang.String name,
                                java.lang.Object XQvar)
Delegate to parent context

Specified by:
setXQueryContextVar in interface Context
Overrides:
setXQueryContextVar in class XQueryContext
Parameters:
name - The variable name
XQvar - The variable value, may be of any xs: type
See Also:
XQueryContext.setXQueryContextVar(String, Object)

getXQueryContextVar

public java.lang.Object getXQueryContextVar(java.lang.String name)
Delegate to parent context

Specified by:
getXQueryContextVar in interface Context
Overrides:
getXQueryContextVar in class XQueryContext
Parameters:
name - The variable name
Returns:
The variable value indicated by name.
See Also:
XQueryContext.getXQueryContextVar(String)

getDocumentBuilder

public MemTreeBuilder getDocumentBuilder()
Description copied from class: XQueryContext
Get the document builder currently used for creating temporary document fragments. A new document builder will be created on demand.

Specified by:
getDocumentBuilder in interface Context
Overrides:
getDocumentBuilder in class XQueryContext
Returns:
document builder

getDocumentBuilder

public MemTreeBuilder getDocumentBuilder(boolean explicitCreation)
Specified by:
getDocumentBuilder in interface Context
Overrides:
getDocumentBuilder in class XQueryContext

pushDocumentContext

public void pushDocumentContext()
Description copied from class: XQueryContext
Push any document fragment created within the current execution context on the stack.

Specified by:
pushDocumentContext in interface Context
Overrides:
pushDocumentContext in class XQueryContext

markLocalVariables

public LocalVariable markLocalVariables(boolean newContext)
Description copied from class: XQueryContext
Returns the last variable on the local variable stack. The current variable context can be restored by passing the return value to XQueryContext.popLocalVariables(LocalVariable).

Specified by:
markLocalVariables in interface Context
Overrides:
markLocalVariables in class XQueryContext
Returns:
last variable on the local variable stack

popLocalVariables

public void popLocalVariables(LocalVariable var)
Description copied from class: XQueryContext
Restore the local variable stack to the position marked by variable var.

Specified by:
popLocalVariables in interface Context
Overrides:
popLocalVariables in class XQueryContext

declareVariableBinding

public LocalVariable declareVariableBinding(LocalVariable var)
                                     throws XPathException
Description copied from class: XQueryContext
Declare a local variable. This is called by variable binding expressions like "let" and "for".

Specified by:
declareVariableBinding in interface Context
Overrides:
declareVariableBinding in class XQueryContext
Returns:
LocalVariable
Throws:
XPathException

resolveLocalVariable

protected Variable resolveLocalVariable(QName qname)
                                 throws XPathException
Overrides:
resolveLocalVariable in class XQueryContext
Throws:
XPathException

resolveVariable

public Variable resolveVariable(QName qname)
                         throws XPathException
Try to resolve a variable.

Specified by:
resolveVariable in interface Context
Overrides:
resolveVariable in class XQueryContext
Parameters:
qname - the qualified name of the variable
Returns:
the declared Variable object
Throws:
XPathException - if the variable is unknown

getVariables

public java.util.Map<QName,Variable> getVariables()
Specified by:
getVariables in interface Context
Overrides:
getVariables in class XQueryContext

getLocalVariables

public java.util.Map<QName,Variable> getLocalVariables()
Specified by:
getLocalVariables in interface Context
Overrides:
getLocalVariables in class XQueryContext

getGlobalVariables

public java.util.Map<QName,Variable> getGlobalVariables()
Specified by:
getGlobalVariables in interface Context
Overrides:
getGlobalVariables in class XQueryContext

getCurrentStackSize

public int getCurrentStackSize()
Description copied from class: XQueryContext
Returns the current size of the stack. This is used to determine where a variable has been declared.

Specified by:
getCurrentStackSize in interface Context
Overrides:
getCurrentStackSize in class XQueryContext
Returns:
current size of the stack

popDocumentContext

public void popDocumentContext()
Specified by:
popDocumentContext in interface Context
Overrides:
popDocumentContext in class XQueryContext

getURIForPrefix

public java.lang.String getURIForPrefix(java.lang.String prefix)
First checks the parent context for in-scope namespaces, then the module's static context.

Specified by:
getURIForPrefix in interface Context
Overrides:
getURIForPrefix in class XQueryContext
Parameters:
prefix - the prefix to look up
Returns:
the namespace currently mapped to that prefix

getPrefixForURI

public java.lang.String getPrefixForURI(java.lang.String uri)
First checks the parent context for in-scope namespaces, then the module's static context.

Specified by:
getPrefixForURI in interface Context
Overrides:
getPrefixForURI in class XQueryContext
Parameters:
uri - the URI to look up
Returns:
a prefix for the URI

getInScopeNamespace

public java.lang.String getInScopeNamespace(java.lang.String prefix)
Specified by:
getInScopeNamespace in interface Context
Overrides:
getInScopeNamespace in class XQueryContext

getInScopePrefix

public java.lang.String getInScopePrefix(java.lang.String uri)
Specified by:
getInScopePrefix in interface Context
Overrides:
getInScopePrefix in class XQueryContext

getInheritedNamespace

public java.lang.String getInheritedNamespace(java.lang.String prefix)
Specified by:
getInheritedNamespace in interface Context
Overrides:
getInheritedNamespace in class XQueryContext

getInheritedPrefix

public java.lang.String getInheritedPrefix(java.lang.String uri)
Specified by:
getInheritedPrefix in interface Context
Overrides:
getInheritedPrefix in class XQueryContext

declareInScopeNamespace

public void declareInScopeNamespace(java.lang.String prefix,
                                    java.lang.String uri)
Description copied from class: XQueryContext
Declare an in-scope namespace. This is called during query execution.

Specified by:
declareInScopeNamespace in interface Context
Overrides:
declareInScopeNamespace in class XQueryContext

pushInScopeNamespaces

public void pushInScopeNamespaces(boolean inherit)
Description copied from class: XQueryContext
Push all in-scope namespace declarations onto the stack.

Specified by:
pushInScopeNamespaces in interface Context
Overrides:
pushInScopeNamespaces in class XQueryContext

pushInScopeNamespaces

public void pushInScopeNamespaces()
Specified by:
pushInScopeNamespaces in interface Context
Overrides:
pushInScopeNamespaces in class XQueryContext

popInScopeNamespaces

public void popInScopeNamespaces()
Specified by:
popInScopeNamespaces in interface Context
Overrides:
popInScopeNamespaces in class XQueryContext

registerUpdateListener

public void registerUpdateListener(UpdateListener listener)
Specified by:
registerUpdateListener in interface Context
Overrides:
registerUpdateListener in class XQueryContext

clearUpdateListeners

protected void clearUpdateListeners()
Overrides:
clearUpdateListeners in class XQueryContext

getDebuggeeJoint

public DebuggeeJoint getDebuggeeJoint()
Specified by:
getDebuggeeJoint in interface Context
Overrides:
getDebuggeeJoint in class XQueryContext

isDebugMode

public boolean isDebugMode()
Specified by:
isDebugMode in interface Context
Overrides:
isDebugMode in class XQueryContext

expressionStart

public void expressionStart(Expression expr)
                     throws TerminatedException
Specified by:
expressionStart in interface Context
Overrides:
expressionStart in class XQueryContext
Throws:
TerminatedException

expressionEnd

public void expressionEnd(Expression expr)
Specified by:
expressionEnd in interface Context
Overrides:
expressionEnd in class XQueryContext

stackEnter

public void stackEnter(Expression expr)
                throws TerminatedException
Specified by:
stackEnter in interface Context
Overrides:
stackEnter in class XQueryContext
Throws:
TerminatedException

stackLeave

public void stackLeave(Expression expr)
Specified by:
stackLeave in interface Context
Overrides:
stackLeave in class XQueryContext

saveState

public void saveState()
Description copied from class: XQueryContext
Before a dynamic import, make sure relevant parts of the current context a saved to the stack. This is important for util:import-module. The context will be restored during XQueryContext.reset().

Overrides:
saveState in class XQueryContext