org.exist.xquery
Class XQueryContext

java.lang.Object
  extended by org.exist.xquery.XQueryContext
Direct Known Subclasses:
ModuleContext

public class XQueryContext
extends Object

The current XQuery execution context. Contains the static as well as the dynamic XQuery context components.

Author:
Wolfgang Meier (wolfgang@exist-db.org)

Field Summary
static String BUILT_IN_MODULE_CLASS_ATTRIBUTE
           
static String BUILT_IN_MODULE_SOURCE_ATTRIBUTE
           
static String BUILT_IN_MODULE_URI_ATTRIBUTE
           
static String CONFIGURATION_ELEMENT_NAME
           
static String CONFIGURATION_MODULE_ELEMENT_NAME
           
static String CONFIGURATION_MODULES_ELEMENT_NAME
           
static String ENABLE_QUERY_REWRITING_ATTRIBUTE
           
static String HTTP_SESSIONVAR_XMLDB_USER
           
static String PROPERTY_BUILT_IN_MODULES
           
static String PROPERTY_ENABLE_QUERY_REWRITING
           
static String PROPERTY_STATIC_MODULE_MAP
           
static String PROPERTY_XQUERY_BACKWARD_COMPATIBLE
           
static String PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL
           
static String XQUERY_BACKWARD_COMPATIBLE_ATTRIBUTE
           
static String XQUERY_CONTEXTVAR_XQUERY_UPDATE_ERROR
           
static String XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL_ATTRIBUTE
           
static boolean XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL_DEFAULT
           
 
Constructor Summary
XQueryContext(DBBroker broker, AccessContext accessCtx)
           
XQueryContext(XQueryContext copyFrom)
           
 
Method Summary
 void addDynamicOption(String qnameString, String contents)
          for dynamic run-time options i.e.
 void addForwardReference(FunctionCall call)
          Add a forward reference to an undeclared function.
 void addLockedDocument(DocumentImpl doc)
           
 void addModifiedDoc(DocumentImpl document)
           
 void addOption(String qnameString, String contents)
          for static compile-time options i.e.
 void analyzeAndOptimizeIfModulesChanged(PathExpr expr)
           
 boolean checkModulesValid()
          For compiled expressions: check if the source of any module imported by the current query has changed since compilation.
 void checkOptions(Properties properties)
          Check if the XQuery contains pragmas that define serialization settings.
 XQueryContext copyContext()
           
 void declareFunction(UserDefinedFunction function)
          Declare a user-defined function.
 Variable declareGlobalVariable(Variable var)
          Declare a global variable as by "declare variable".
 void declareInScopeNamespace(String prefix, String uri)
          Declare an in-scope namespace.
 void declareNamespace(String prefix, String uri)
          Declare a user-defined static prefix/namespace mapping.
 void declareNamespaces(Map namespaceMap)
           
 Variable declareVariable(QName qn, Object value)
           
 Variable declareVariable(String qname, Object value)
          Declare a user-defined variable.
 LocalVariable declareVariableBinding(LocalVariable var)
          Declare a local variable.
 void expressionEnd(Expression expr)
           
 void expressionStart(Expression expr)
           
 void finishBatchTransaction()
          Completes a batch transaction, by committing the transaction and calling finish on any triggers set by setBatchTransactionTrigger()
 void functionEnd()
          Report the end of the currently executed function.
 void functionStart(FunctionSignature signature)
          Report the start of a function execution.
 AccessContext getAccessContext()
           
 Iterator getAllModules()
           
 Object getAttribute(String attribute)
           
 AnyURIValue getBaseURI()
          Get the base URI of the evaluation context.
 Txn getBatchTransaction()
          Get the Transaction for the batch
 DBBroker getBroker()
          Get the DBBroker instance used for the current query.
 XMLGregorianCalendar getCalendar()
           
 Collator getCollator(String uri)
           
 XQueryContext getContext()
           
 int getContextPosition()
          Get the current context position, i.e.
 int getCurrentStackSize()
          Returns the current size of the stack.
 DebuggeeJoint getDebuggeeJoint()
           
 String getDefaultCollation()
           
 Collator getDefaultCollator()
           
 String getDefaultElementNamespace()
          Returns the current default element namespace.
 String getDefaultElementNamespaceSchema()
          Returns the current default element namespace.
 String getDefaultFunctionNamespace()
          Returns the current default function namespace.
 MemTreeBuilder getDocumentBuilder()
          Get the document builder currently used for creating temporary document fragments.
 MemTreeBuilder getDocumentBuilder(boolean explicitCreation)
           
 int getExpressionCount()
          Returns the number of expression objects in the internal representation of the query.
 TimeZone getImplicitTimeZone()
           
 String getInheritedNamespace(String prefix)
           
 String getInheritedPrefix(String uri)
           
 String getInScopeNamespace(String prefix)
           
 String getInScopePrefix(String uri)
           
 Module getModule(String namespaceURI)
          Get the built-in module registered for the given namespace URI.
 String getModuleLoadPath()
           
 Iterator getModules()
           
 Option getOption(QName qname)
           
 ExistPDP getPDP()
          Convenience method that returns the XACML Policy Decision Point for this database instance.
 Pragma getPragma(String name, String contents)
           
 String getPrefixForURI(String uri)
           
 Profiler getProfiler()
          Returns the Profiler instance of this context if profiling is enabled.
 LockedDocumentMap getProtectedDocs()
           
 XQueryContext getRootContext()
           
 Expression getRootExpression()
          Returns the root expression of the XQuery associated with this context.
 Module getRootModule(String namespaceURI)
           
 Iterator getRootModules()
           
 NamePool getSharedNamePool()
          Returns the shared name pool used by all in-memory documents which are created within this query context.
 Iterator getSignaturesForFunction(QName name)
           
 XACMLSource getSource()
           
 String getSourceKey()
          Returns the Source Key of the XQuery associated with this context.
 String getSourceType()
          Returns the Source Type of the XQuery associated with this context.
 DocumentSet getStaticallyKnownDocuments()
           
 String getURIForPrefix(String prefix)
          Return the namespace URI mapped to the registered prefix or null if the prefix is not registered.
 User getUser()
          Get the user which executes the current query.
 Map<QName,Variable> getVariables()
           
 XQueryWatchDog getWatchDog()
           
 Object getXQueryContextVar(String name)
          Get an XQuery Context variable.
 boolean hasBatchTransaction()
          Determines if a batch transaction should be performed
 boolean hasParent()
          Returns true if this context has a parent context (means it is a module context).
 void importModule(String namespaceURI, String prefix, String location)
          Import a module and make it available in this context.
 boolean inheritNamespaces()
          Returns true if namespaces for constructed element and document nodes should be inherited on copy by default.
 boolean inProtectedMode()
           
 boolean isBackwardsCompatible()
          XPath 1.0 backwards compatibility turned on? In XPath 1.0 compatible mode, additional conversions will be applied to values if a numeric value is expected.
 boolean isBaseURIDeclared()
          The method isBaseURIDeclared
 boolean isDebugMode()
           
 boolean isProfilingEnabled()
           
 boolean isProfilingEnabled(int verbosity)
           
 boolean isRaiseErrorOnFailedRetrieval()
           
 boolean isShared()
           
 boolean isVarDeclared(QName qname)
           
 Module loadBuiltInModule(String namespaceURI, String moduleClass)
          Load a built-in module from the given class name and assign it to the namespace URI.
static void loadModuleClasses(Element xquery, Map classMap, Map externalMap)
          Read list of built-in modules from the configuration.
 Iterator localFunctions()
           
 boolean lockDocumentsOnLoad()
          Should loaded documents be locked? see #setLockDocumentsOnLoad(boolean)
 void mapModule(String namespace, XmldbURI uri)
           
 LocalVariable markLocalVariables(boolean newContext)
          Returns the last variable on the local variable stack.
 boolean optimizationsEnabled()
           
 boolean orderEmptyGreatest()
          Returns true if order empty is set to gretest, otherwise false for order empty is least.
 void popDocumentContext()
           
 void popInScopeNamespaces()
           
 void popLocalVariables(LocalVariable var)
          Restore the local variable stack to the position marked by variable var.
 void popNamespaceContext()
           
 void prepare()
          Prepares the current context before xquery execution
 boolean preserveNamespaces()
          Returns true if namespaces for constructed element and document nodes should be preserved on copy by default.
 void proceed()
           
 void proceed(Expression expr)
           
 void proceed(Expression expr, MemTreeBuilder builder)
           
 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 pushNamespaceContext()
           
 void registerUpdateListener(UpdateListener listener)
           
 void removeNamespace(String uri)
          Removes the namespace URI from the prefix/namespace mappings table.
 void reset()
           
 void reset(boolean keepGlobals)
          Prepare this XQueryContext to be reused.
 void resolveForwardReferences()
          Resolve all forward references to previously undeclared functions.
 UserDefinedFunction resolveFunction(QName name, int argCount)
          Resolve a user-defined function.
 Variable resolveVariable(QName qname)
          Try to resolve a variable.
 Variable resolveVariable(String name)
          Try to resolve a variable.
 void setAttribute(String attribute, Object value)
           
 void setBackwardsCompatibility(boolean backwardsCompatible)
          Turn on/off XPath 1.0 backwards compatibility.
 void setBaseURI(AnyURIValue uri)
          Set the base URI for the evaluation context.
 void setBaseURI(AnyURIValue uri, boolean setInProlog)
          Set the base URI for the evaluation context.
 void setBatchTransactionTrigger(DocumentImpl doc)
          Set's that a trigger should be executed for the provided document as part of the batch transaction
 void setBroker(DBBroker broker)
           
 void setCalendar(XMLGregorianCalendar newCalendar)
           
 void setContextPosition(int pos)
          Set the current context position, i.e.
 void setDebuggeeJoint(DebuggeeJoint joint)
           
 void setDebugMode(boolean isDebugMode)
           
 void setDefaultCollation(String uri)
          Set the default collation to be used by all operators and functions on strings.
 void setDefaultElementNamespace(String uri, String schema)
          Set the default element namespace.
 void setDefaultElementNamespaceSchema(String uri)
          Set the default element namespace.
 void setDefaultFunctionNamespace(String uri)
          Set the default function namespace.
 void setInheritNamespaces(boolean inherit)
          The method setInheritNamespaces
 void setModule(String namespaceURI, Module module)
           
 void setModuleLoadPath(String path)
          Set the path to a base directory where modules should be loaded from.
 void setOrderEmptyGreatest(boolean order)
          The method setOrderEmptyGreatest
 void setPreserveNamespaces(boolean preserve)
          The method setPreserveNamespaces
 void setProtectedDocs(LockedDocumentMap map)
           
 void setRootExpression(Expression expr)
          Called from the XQuery compiler to set the root expression for this context.
 void setShared(boolean shared)
           
 void setSource(XACMLSource source)
           
 void setStaticallyKnownDocuments(DocumentSet set)
           
 void setStaticallyKnownDocuments(XmldbURI[] docs)
          Set the set of statically known documents for the current execution context.
 void setStripWhitespace(boolean strip)
           
 void setTimeZone(TimeZone newTimeZone)
           
 void setXQueryContextVar(String name, Object XQvar)
          Set an XQuery Context variable.
 void stackEnter(Expression expr)
           
 void stackLeave(Expression expr)
           
 void startBatchTransaction()
          Starts a batch Transaction
 DocumentImpl storeTemporaryDoc(DocumentImpl doc)
          Store the supplied data to a temporary document fragment.
 boolean stripWhitespace()
          Returns true if whitespace between constructed element nodes should be stripped by default.
 boolean tailRecursiveCall(FunctionSignature signature)
          Check if the specified function signature is found in the current function called stack.
 void updateContext(XQueryContext from)
          Update the current dynamic context using the properties of another context.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGURATION_ELEMENT_NAME

public static final String CONFIGURATION_ELEMENT_NAME
See Also:
Constant Field Values

CONFIGURATION_MODULES_ELEMENT_NAME

public static final String CONFIGURATION_MODULES_ELEMENT_NAME
See Also:
Constant Field Values

ENABLE_QUERY_REWRITING_ATTRIBUTE

public static final String ENABLE_QUERY_REWRITING_ATTRIBUTE
See Also:
Constant Field Values

XQUERY_BACKWARD_COMPATIBLE_ATTRIBUTE

public static final String XQUERY_BACKWARD_COMPATIBLE_ATTRIBUTE
See Also:
Constant Field Values

XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL_ATTRIBUTE

public static final String XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL_ATTRIBUTE
See Also:
Constant Field Values

CONFIGURATION_MODULE_ELEMENT_NAME

public static final String CONFIGURATION_MODULE_ELEMENT_NAME
See Also:
Constant Field Values

BUILT_IN_MODULE_URI_ATTRIBUTE

public static final String BUILT_IN_MODULE_URI_ATTRIBUTE
See Also:
Constant Field Values

BUILT_IN_MODULE_CLASS_ATTRIBUTE

public static final String BUILT_IN_MODULE_CLASS_ATTRIBUTE
See Also:
Constant Field Values

BUILT_IN_MODULE_SOURCE_ATTRIBUTE

public static final String BUILT_IN_MODULE_SOURCE_ATTRIBUTE
See Also:
Constant Field Values

PROPERTY_XQUERY_BACKWARD_COMPATIBLE

public static final String PROPERTY_XQUERY_BACKWARD_COMPATIBLE
See Also:
Constant Field Values

PROPERTY_ENABLE_QUERY_REWRITING

public static final String PROPERTY_ENABLE_QUERY_REWRITING
See Also:
Constant Field Values

PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL

public static final String PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL
See Also:
Constant Field Values

XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL_DEFAULT

public static final boolean XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL_DEFAULT
See Also:
Constant Field Values

PROPERTY_BUILT_IN_MODULES

public static final String PROPERTY_BUILT_IN_MODULES
See Also:
Constant Field Values

PROPERTY_STATIC_MODULE_MAP

public static final String PROPERTY_STATIC_MODULE_MAP
See Also:
Constant Field Values

XQUERY_CONTEXTVAR_XQUERY_UPDATE_ERROR

public static final String XQUERY_CONTEXTVAR_XQUERY_UPDATE_ERROR
See Also:
Constant Field Values

HTTP_SESSIONVAR_XMLDB_USER

public static final String HTTP_SESSIONVAR_XMLDB_USER
See Also:
Constant Field Values
Constructor Detail

XQueryContext

public XQueryContext(DBBroker broker,
                     AccessContext accessCtx)

XQueryContext

public XQueryContext(XQueryContext copyFrom)
Method Detail

hasParent

public boolean hasParent()
Returns true if this context has a parent context (means it is a module context).

Returns:
False.

getRootContext

public XQueryContext getRootContext()

copyContext

public XQueryContext copyContext()

updateContext

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

Parameters:
from -

prepare

public void prepare()
Prepares the current context before xquery execution


getAccessContext

public AccessContext getAccessContext()

isProfilingEnabled

public boolean isProfilingEnabled()
Returns:
true if profiling is enabled for this context.

isProfilingEnabled

public boolean isProfilingEnabled(int verbosity)

getProfiler

public Profiler getProfiler()
Returns the Profiler instance of this context if profiling is enabled.

Returns:
the profiler instance.

setRootExpression

public void setRootExpression(Expression expr)
Called from the XQuery compiler to set the root expression for this context.

Parameters:
expr -

getRootExpression

public Expression getRootExpression()
Returns the root expression of the XQuery associated with this context.

Returns:
root expression

getExpressionCount

public int getExpressionCount()
Returns the number of expression objects in the internal representation of the query. Used to estimate the size of the query.

Returns:
number of expression objects

setSource

public void setSource(XACMLSource source)

getSource

public XACMLSource getSource()

getSourceKey

public String getSourceKey()
Returns the Source Key of the XQuery associated with this context.

Returns:
source key

getSourceType

public String getSourceType()
Returns the Source Type of the XQuery associated with this context.

Returns:
source type

declareNamespace

public void declareNamespace(String prefix,
                             String uri)
                      throws XPathException
Declare a user-defined static prefix/namespace mapping. eXist internally keeps a table containing all prefix/namespace mappings it found in documents, which have been previously stored into the database. These default mappings need not to be declared explicitely.

Parameters:
prefix -
uri -
Throws:
XPathException

declareNamespaces

public void declareNamespaces(Map namespaceMap)

removeNamespace

public void removeNamespace(String uri)
Removes the namespace URI from the prefix/namespace mappings table.

Parameters:
uri -

declareInScopeNamespace

public void declareInScopeNamespace(String prefix,
                                    String uri)
Declare an in-scope namespace. This is called during query execution.

Parameters:
prefix -
uri -

getInScopeNamespace

public String getInScopeNamespace(String prefix)

getInScopePrefix

public String getInScopePrefix(String uri)

getInheritedNamespace

public String getInheritedNamespace(String prefix)

getInheritedPrefix

public String getInheritedPrefix(String uri)

getURIForPrefix

public String getURIForPrefix(String prefix)
Return the namespace URI mapped to the registered prefix or null if the prefix is not registered.

Parameters:
prefix -
Returns:
namespace

getPrefixForURI

public String getPrefixForURI(String uri)
Parameters:
uri -
Returns:
the prefix mapped to the registered URI or null if the URI is not registered.

getDefaultFunctionNamespace

public String getDefaultFunctionNamespace()
Returns the current default function namespace.

Returns:
current default function namespace

setDefaultFunctionNamespace

public void setDefaultFunctionNamespace(String uri)
                                 throws XPathException
Set the default function namespace. By default, this points to the namespace for XPath built-in functions.

Parameters:
uri -
Throws:
XPathException

getDefaultElementNamespaceSchema

public String getDefaultElementNamespaceSchema()
                                        throws XPathException
Returns the current default element namespace.

Returns:
current default element namespace schema
Throws:
XPathException

setDefaultElementNamespaceSchema

public void setDefaultElementNamespaceSchema(String uri)
                                      throws XPathException
Set the default element namespace. By default, this points to the empty uri.

Parameters:
uri -
Throws:
XPathException

getDefaultElementNamespace

public String getDefaultElementNamespace()
                                  throws XPathException
Returns the current default element namespace.

Returns:
current default element namespace
Throws:
XPathException

setDefaultElementNamespace

public void setDefaultElementNamespace(String uri,
                                       String schema)
                                throws XPathException
Set the default element namespace. By default, this points to the empty uri.

Parameters:
uri - a String value
schema - a String value
Throws:
XPathException - if an error occurs

setDefaultCollation

public void setDefaultCollation(String uri)
                         throws XPathException
Set the default collation to be used by all operators and functions on strings. Throws an exception if the collation is unknown or cannot be instantiated.

Parameters:
uri -
Throws:
XPathException

getDefaultCollation

public String getDefaultCollation()

getCollator

public Collator getCollator(String uri)
                     throws XPathException
Throws:
XPathException

getDefaultCollator

public Collator getDefaultCollator()

setStaticallyKnownDocuments

public void setStaticallyKnownDocuments(XmldbURI[] docs)
Set the set of statically known documents for the current execution context. These documents will be processed if no explicit document set has been set for the current expression with fn:doc() or fn:collection().

Parameters:
docs -

setStaticallyKnownDocuments

public void setStaticallyKnownDocuments(DocumentSet set)

setCalendar

public void setCalendar(XMLGregorianCalendar newCalendar)

setTimeZone

public void setTimeZone(TimeZone newTimeZone)

getCalendar

public XMLGregorianCalendar getCalendar()

getImplicitTimeZone

public TimeZone getImplicitTimeZone()

getStaticallyKnownDocuments

public DocumentSet getStaticallyKnownDocuments()
                                        throws XPathException
Returns:
set of statically known documents.
Throws:
XPathException

setProtectedDocs

public void setProtectedDocs(LockedDocumentMap map)

getProtectedDocs

public LockedDocumentMap getProtectedDocs()

inProtectedMode

public boolean inProtectedMode()

lockDocumentsOnLoad

public boolean lockDocumentsOnLoad()
Should loaded documents be locked? see #setLockDocumentsOnLoad(boolean)


addLockedDocument

public void addLockedDocument(DocumentImpl doc)

setShared

public void setShared(boolean shared)

isShared

public boolean isShared()

addModifiedDoc

public void addModifiedDoc(DocumentImpl document)

reset

public void reset()

reset

public void reset(boolean keepGlobals)
Prepare this XQueryContext to be reused. This should be called when adding an XQuery to the cache.


stripWhitespace

public boolean stripWhitespace()
Returns true if whitespace between constructed element nodes should be stripped by default.


setStripWhitespace

public void setStripWhitespace(boolean strip)

preserveNamespaces

public boolean preserveNamespaces()
Returns true if namespaces for constructed element and document nodes should be preserved on copy by default.


setPreserveNamespaces

public void setPreserveNamespaces(boolean preserve)
The method setPreserveNamespaces

Parameters:
preserve - a boolean value

inheritNamespaces

public boolean inheritNamespaces()
Returns true if namespaces for constructed element and document nodes should be inherited on copy by default.


setInheritNamespaces

public void setInheritNamespaces(boolean inherit)
The method setInheritNamespaces

Parameters:
inherit - a boolean value

orderEmptyGreatest

public boolean orderEmptyGreatest()
Returns true if order empty is set to gretest, otherwise false for order empty is least.


setOrderEmptyGreatest

public void setOrderEmptyGreatest(boolean order)
The method setOrderEmptyGreatest

Parameters:
order - a boolean value

getModules

public Iterator getModules()
Returns:
iterator over all modules imported into this context

getRootModules

public Iterator getRootModules()
Returns:
iterator over all modules registered in the entire context tree

getAllModules

public Iterator getAllModules()

getModule

public Module getModule(String namespaceURI)
Get the built-in module registered for the given namespace URI.

Parameters:
namespaceURI -
Returns:
built-in module

getRootModule

public Module getRootModule(String namespaceURI)

setModule

public void setModule(String namespaceURI,
                      Module module)

checkModulesValid

public boolean checkModulesValid()
For compiled expressions: check if the source of any module imported by the current query has changed since compilation.


analyzeAndOptimizeIfModulesChanged

public void analyzeAndOptimizeIfModulesChanged(PathExpr expr)
                                        throws XPathException
Throws:
XPathException

loadBuiltInModule

public Module loadBuiltInModule(String namespaceURI,
                                String moduleClass)
Load a built-in module from the given class name and assign it to the namespace URI. The specified class should be a subclass of Module. The method will try to instantiate the class. If the class is not found or an exception is thrown, the method will silently fail. The namespace URI has to be equal to the namespace URI declared by the module class. Otherwise, the module is not loaded.

Parameters:
namespaceURI -
moduleClass -

getPDP

public ExistPDP getPDP()
Convenience method that returns the XACML Policy Decision Point for this database instance. If XACML has not been enabled, this returns null.

Returns:
the PDP for this database instance, or null if XACML is disabled

declareFunction

public void declareFunction(UserDefinedFunction function)
                     throws XPathException
Declare a user-defined function. All user-defined functions are kept in a single hash map.

Parameters:
function -
Throws:
XPathException

resolveFunction

public UserDefinedFunction resolveFunction(QName name,
                                           int argCount)
                                    throws XPathException
Resolve a user-defined function.

Parameters:
name -
Returns:
user-defined function
Throws:
XPathException

getSignaturesForFunction

public Iterator getSignaturesForFunction(QName name)

localFunctions

public Iterator localFunctions()

declareVariableBinding

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

Parameters:
var -
Throws:
XPathException

declareGlobalVariable

public Variable declareGlobalVariable(Variable var)
                               throws XPathException
Declare a global variable as by "declare variable".

Parameters:
var -
Throws:
XPathException

declareVariable

public Variable declareVariable(String qname,
                                Object value)
                         throws XPathException
Declare a user-defined variable. The value argument is converted into an XPath value (@see XPathUtil#javaObjectToXPath(Object)).

Parameters:
qname - the qualified name of the new variable. Any namespaces should have been declared before.
value - a Java object, representing the fixed value of the variable
Returns:
the created Variable object
Throws:
XPathException - if the value cannot be converted into a known XPath value or the variable QName references an unknown namespace-prefix.

declareVariable

public Variable declareVariable(QName qn,
                                Object value)
                         throws XPathException
Throws:
XPathException

resolveVariable

public Variable resolveVariable(String name)
                         throws XPathException
Try to resolve a variable.

Parameters:
name - the qualified name of the variable as string
Returns:
the declared Variable object
Throws:
XPathException - if the variable is unknown

resolveVariable

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

Parameters:
qname - the qualified name of the variable
Returns:
the declared Variable object
Throws:
XPathException - if the variable is unknown

isVarDeclared

public boolean isVarDeclared(QName qname)

getVariables

public Map<QName,Variable> getVariables()

setBackwardsCompatibility

public void setBackwardsCompatibility(boolean backwardsCompatible)
Turn on/off XPath 1.0 backwards compatibility. If turned on, comparison expressions will behave like in XPath 1.0, i.e. if any one of the operands is a number, the other operand will be cast to a double.

Parameters:
backwardsCompatible -

isBackwardsCompatible

public boolean isBackwardsCompatible()
XPath 1.0 backwards compatibility turned on? In XPath 1.0 compatible mode, additional conversions will be applied to values if a numeric value is expected.


isRaiseErrorOnFailedRetrieval

public boolean isRaiseErrorOnFailedRetrieval()

getBroker

public DBBroker getBroker()
Get the DBBroker instance used for the current query. The DBBroker is the main database access object, providing access to all internal database functions.

Returns:
DBBroker instance

setBroker

public void setBroker(DBBroker broker)

getUser

public User getUser()
Get the user which executes the current query.

Returns:
user

getDocumentBuilder

public MemTreeBuilder getDocumentBuilder()
Get the document builder currently used for creating temporary document fragments. A new document builder will be created on demand.

Returns:
document builder

getDocumentBuilder

public MemTreeBuilder getDocumentBuilder(boolean explicitCreation)

getSharedNamePool

public NamePool getSharedNamePool()
Returns the shared name pool used by all in-memory documents which are created within this query context. Create a name pool for every document would be a waste of memory, especially since it is likely that the documents contain elements or attributes with similar names.

Returns:
the shared name pool

getContext

public XQueryContext getContext()

expressionStart

public void expressionStart(Expression expr)
                     throws TerminatedException
Throws:
TerminatedException

expressionEnd

public void expressionEnd(Expression expr)

stackEnter

public void stackEnter(Expression expr)
                throws TerminatedException
Throws:
TerminatedException

stackLeave

public void stackLeave(Expression expr)

proceed

public void proceed()
             throws TerminatedException
Throws:
TerminatedException

proceed

public void proceed(Expression expr)
             throws TerminatedException
Throws:
TerminatedException

proceed

public void proceed(Expression expr,
                    MemTreeBuilder builder)
             throws TerminatedException
Throws:
TerminatedException

getWatchDog

public XQueryWatchDog getWatchDog()

pushDocumentContext

public void pushDocumentContext()
Push any document fragment created within the current execution context on the stack.


popDocumentContext

public void popDocumentContext()

setBaseURI

public void setBaseURI(AnyURIValue uri)
Set the base URI for the evaluation context. This is the URI returned by the fn:base-uri() function.

Parameters:
uri -

setBaseURI

public void setBaseURI(AnyURIValue uri,
                       boolean setInProlog)
Set the base URI for the evaluation context. A base URI specified via the base-uri directive in the XQuery prolog overwrites any other setting.

Parameters:
uri -
setInProlog -

setModuleLoadPath

public void setModuleLoadPath(String path)
Set the path to a base directory where modules should be loaded from. Relative module paths will be resolved against this directory. The property is usually set by the XQueryServlet or XQueryGenerator, but can also be specified manually.

Parameters:
path -

getModuleLoadPath

public String getModuleLoadPath()

isBaseURIDeclared

public boolean isBaseURIDeclared()
The method isBaseURIDeclared

Returns:
a boolean value

getBaseURI

public AnyURIValue getBaseURI()
                       throws XPathException
Get the base URI of the evaluation context. This is the URI returned by the fn:base-uri() function.

Returns:
base URI of the evaluation context
Throws:
XPathException - if an error occurs

setContextPosition

public void setContextPosition(int pos)
Set the current context position, i.e. the position of the currently processed item in the context sequence. This value is required by some expressions, e.g. fn:position().

Parameters:
pos -

getContextPosition

public int getContextPosition()
Get the current context position, i.e. the position of the currently processed item in the context sequence.

Returns:
current context position

pushInScopeNamespaces

public void pushInScopeNamespaces()

pushInScopeNamespaces

public void pushInScopeNamespaces(boolean inherit)
Push all in-scope namespace declarations onto the stack.


popInScopeNamespaces

public void popInScopeNamespaces()

pushNamespaceContext

public void pushNamespaceContext()

popNamespaceContext

public void popNamespaceContext()

markLocalVariables

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

Returns:
last variable on the local variable stack

popLocalVariables

public void popLocalVariables(LocalVariable var)
Restore the local variable stack to the position marked by variable var.

Parameters:
var -

getCurrentStackSize

public int getCurrentStackSize()
Returns the current size of the stack. This is used to determine where a variable has been declared.

Returns:
current size of the stack

functionStart

public void functionStart(FunctionSignature signature)
Report the start of a function execution. Adds the reported function signature to the function call stack.


functionEnd

public void functionEnd()
Report the end of the currently executed function. Pops the last function signature from the function call stack.


tailRecursiveCall

public boolean tailRecursiveCall(FunctionSignature signature)
Check if the specified function signature is found in the current function called stack. If yes, the function might be tail recursive and needs to be optimized.

Parameters:
signature -

mapModule

public void mapModule(String namespace,
                      XmldbURI uri)

importModule

public void importModule(String namespaceURI,
                         String prefix,
                         String location)
                  throws XPathException
Import a module and make it available in this context. The prefix and location parameters are optional. If prefix is null, the default prefix specified by the module is used. If location is null, the module will be read from the namespace URI.

Parameters:
namespaceURI -
prefix -
location -
Throws:
XPathException

addForwardReference

public void addForwardReference(FunctionCall call)
Add a forward reference to an undeclared function. Forward references will be resolved later.

Parameters:
call -

resolveForwardReferences

public void resolveForwardReferences()
                              throws XPathException
Resolve all forward references to previously undeclared functions.

Throws:
XPathException

optimizationsEnabled

public boolean optimizationsEnabled()

addOption

public void addOption(String qnameString,
                      String contents)
               throws XPathException
for static compile-time options i.e. declare option

Throws:
XPathException

addDynamicOption

public void addDynamicOption(String qnameString,
                             String contents)
                      throws XPathException
for dynamic run-time options i.e. util:declare-option

Throws:
XPathException

getOption

public Option getOption(QName qname)

getPragma

public Pragma getPragma(String name,
                        String contents)
                 throws XPathException
Throws:
XPathException

storeTemporaryDoc

public DocumentImpl storeTemporaryDoc(DocumentImpl doc)
                               throws XPathException
Store the supplied data to a temporary document fragment.

Parameters:
doc -
Throws:
XPathException

setAttribute

public void setAttribute(String attribute,
                         Object value)

getAttribute

public Object getAttribute(String attribute)

setXQueryContextVar

public void setXQueryContextVar(String name,
                                Object XQvar)
Set an XQuery Context variable. General variable storage in the xquery context

Parameters:
name - The variable name
XQvar - The variable value, may be of any xs: type

getXQueryContextVar

public Object getXQueryContextVar(String name)
Get an XQuery Context variable. General variable storage in the xquery context

Parameters:
name - The variable name
Returns:
The variable value indicated by name.

startBatchTransaction

public void startBatchTransaction()
                           throws TransactionException
Starts a batch Transaction

Throws:
TransactionException

hasBatchTransaction

public boolean hasBatchTransaction()
Determines if a batch transaction should be performed

Returns:
true if a batch update transaction should be performed

getBatchTransaction

public Txn getBatchTransaction()
Get the Transaction for the batch

Returns:
The Transaction

setBatchTransactionTrigger

public void setBatchTransactionTrigger(DocumentImpl doc)
Set's that a trigger should be executed for the provided document as part of the batch transaction

Parameters:
doc - The document to trigger for

finishBatchTransaction

public void finishBatchTransaction()
                            throws TransactionException
Completes a batch transaction, by committing the transaction and calling finish on any triggers set by setBatchTransactionTrigger()

Throws:
TransactionException

registerUpdateListener

public void registerUpdateListener(UpdateListener listener)

checkOptions

public void checkOptions(Properties properties)
                  throws XPathException
Check if the XQuery contains pragmas that define serialization settings. If yes, copy the corresponding settings to the current set of output properties.

Parameters:
properties - the properties object to which serialization parameters will be added.
Throws:
XPathException - if an error occurs while parsing the option

loadModuleClasses

public static void loadModuleClasses(Element xquery,
                                     Map classMap,
                                     Map externalMap)
                              throws DatabaseConfigurationException
Read list of built-in modules from the configuration. This method will only make sure that the specified module class exists and is a subclass of Module.

Parameters:
xquery - configuration root
Throws:
DatabaseConfigurationException

setDebuggeeJoint

public void setDebuggeeJoint(DebuggeeJoint joint)

getDebuggeeJoint

public DebuggeeJoint getDebuggeeJoint()

setDebugMode

public void setDebugMode(boolean isDebugMode)

isDebugMode

public boolean isDebugMode()


Copyright (C) Wolfgang Meier. All rights reserved.