zorba::StaticContext
Instances of the class StaticContext contain the information that is available at the time the query is compiled.
This class contains the information that is defined in the XQuery specification (see http://www.w3.org/TR/xquery/#static_context).
A StaticContext can be created by calling Zorba::createStaticContext and then be passed to the Zorba::compileQuery or XQuery::compile functions. If no static context has been passed to any of these functions, a default static context is used. It can be accessed by calling XQuery::getStaticContext on a compiled XQuery object.
Note: This class is reference counted. When writing multi-threaded clients, it is the responibility of the client code to synchronize assignments to the SmartPtr holding this object.
#include <zorba/static_context.h>
Inherited by: zorba::SmartObject
Public Functions
| virtual void | addCollation( const String & aURI ) Adds a collation URI. |
| virtual bool | addNamespace( const String & aPrefix, const String & aURI ) Add a pair (prefix, URI) to the statically known namespaces that are available during query compilation. |
| const inline void | addReference() |
| const virtual bool | containsFunction( const String & aFnNameUri, const String & aFnNameLocal, int arity ) Check if a function with the given name and arity are registered in the context. |
| const virtual StaticContext_t | createChildContext() Create a child static context, i.e. |
| virtual void | declareOption( const Item & aQName, const String & aOptionValue ) Declare an option (same as using declare option in XQuery) |
| virtual void | disableFunction( const Function_t & aFunction ) |
| virtual void | disableFunction( const Item & aQName, int arity ) |
| const virtual void | findFunctions( const Item & aQName, std::vector< Function_t > & aFunctions ) |
| virtual void | free() |
| const virtual audit::Event * | getAuditEvent() gets the audit event that is populated during execution |
| const virtual String | getBaseURI() Get the base URI. |
| const virtual boundary_space_mode_t | getBoundarySpacePolicy() Get the boundary space policy. |
| const virtual TypeIdentifier_t | getCollectionType( const String & aCollectionUri ) Get the type of a statically known collection. |
| const virtual construction_mode_t | getConstructionMode() Get the construction mode. |
| const virtual TypeIdentifier_t | getContextItemStaticType() Fetch the type of the context item. |
| const virtual void | getCopyNamespacesMode( preserve_mode_t & aPreserve, inherit_mode_t & aInherit ) Get the copy namespace mode. |
| const virtual String | getDefaultCollation() Get the URI of the default collation. |
| const virtual String | getDefaultElementAndTypeNamespace() Get the default element and type namespace URI. |
| const virtual String | getDefaultFunctionNamespace() Get the default function namespace. |
| const virtual order_empty_mode_t | getDefaultOrderForEmptySequences() Get the default order for the empty sequence. |
| const virtual TypeIdentifier_t | getDocumentType( const String & aDocUri ) Get the type of a statically known document. |
| const virtual void | getExternalVariables( Iterator_t & aVarsIter ) Returns the QName of all external variables within the static context. |
| const virtual void | getFullLibPath( std::vector< String > & aLibPath ) Return the URI lookup path (list of filesystem directories) for this static context and all its parents. |
| const virtual void | getFullModulePaths( std::vector< String > & aFullModulePaths ) Return the union of the URI and library lookup paths (lists of filesystem directories) for this static context and all its parents. |
| const virtual void | getFullURIPath( std::vector< String > & aURIPath ) Return the URI lookup path (list of filesystem directories) for this static context and all its parents. |
| const virtual void | getFunctionAnnotations( const Item & aQName, int arity, std::vector< Annotation_t > & aAnnotations ) |
| const virtual void | getFunctions( std::vector< Function_t > & aFunctions ) Get all functions declared in the given static context. |
| const virtual void | getFunctions( const String & aFnNameUri, uint32_t arity, std::vector< Function_t > & aFunctions ) Get all functions with a specified namespace and airty\ declared in the given static context. |
| const virtual void | getLibPath( std::vector< String > & aLibPath ) Return the URI lookup path (list of filesystem directories) for this static context. |
| const virtual void | getModulePaths( std::vector< String > & aModulePaths ) Return the union of the URI and library lookup paths (lists of filesystem directories) for this static context. |
| const virtual void | getNamespaceBindings( NsBindings & aBindings ) Get the list of all namespace bindings (prefix, uri) declared in this and its parent static contexts. |
| const virtual String | getNamespaceURIByPrefix( const String & aPrefix ) Get the namespace URI for a given prefix. |
| const virtual bool | getOption( const Item & aQName, String & aOptionValue ) Get an option that was declared using the declare option syntax. |
| const virtual ordering_mode_t | getOrderingMode() Get the ordering mode. |
| const inline long | getRefCount() |
| const virtual validation_mode_t | getRevalidationMode() Get the revalidation mode. |
| const virtual StaticCollectionManager * | getStaticCollectionManager() Returns a CollectionManager responsible for all collections which are statically declared in this static context. |
| const virtual void | getURIPath( std::vector< String > & aURIPath ) Return the URI lookup path (list of filesystem directories) for this static context. |
| const virtual xpath1_0compatib_mode_t | getXPath1_0CompatibMode() Get the XPath 1.0 compatibility mode. |
| const virtual xquery_version_t | getXQueryVersion() Get the XQuery processing mode (version 1.0 or 3.0). |
| const virtual ItemSequence_t | invoke( const Item & aQName, const std::vector< ItemSequence_t > & aArgs ) Invokes the XQuery function with the given name and the given parameters. |
| virtual void | loadProlog( const String & , const Zorba_CompilerHints_t & hints ) Loads the declarations and definitions of a given XQuery prolog into this static context. |
| virtual bool | registerModule( ExternalModule * aModule ) Register a module providing access to external functions. |
| virtual void | registerURIMapper( URIMapper * aMapper ) Register a URI Mapper which will transform a given URI into several alternate potential URIs. |
| virtual void | registerURLResolver( URLResolver * aResolver ) Register a URL Resolver which will transform a given URL into a Resource. |
| inline void | removeReference() |
| virtual void | resetTraceStream() Resets the output stream that is used by the fn:trace function to std::cerr. |
| const virtual String | resolve( const String & aRelativeUri ) Resolves the given URI against the value of the base-uri property from the static context. |
| const virtual String | resolve( const String & aRelativeUri, const String & aBaseUri ) Resolves the given relative URI against the absolute base URI. |
| virtual void | setAuditEvent( audit::Event * anEvent ) sets the audit event that will be populated during execution |
| virtual bool | setBaseURI( const String & aBaseURI ) Set the base URI. |
| virtual bool | setBoundarySpacePolicy( boundary_space_mode_t aMode ) Set the boundary space policy. |
| virtual void | setCollectionType( const String & aCollectionUri, TypeIdentifier_t type ) Set the type of a statically known collection. |
| virtual bool | setConstructionMode( construction_mode_t aMode ) Set the construction mode. |
| virtual void | setContextItemStaticType( TypeIdentifier_t type ) Set the type of the context item. |
| virtual bool | setCopyNamespacesMode( preserve_mode_t aPreserve, inherit_mode_t aInherit ) Set the copy namespace mode. |
| virtual void | setDefaultCollation( const String & aURI ) Set the URI of the default collation. |
| virtual bool | setDefaultElementAndTypeNamespace( const String & aURI ) Set the default element and type namespace (see http://www.w3.org/TR/xquery/#static_context) |
| virtual bool | setDefaultFunctionNamespace( const String & aURI ) Set the default functionnamespace (see http://www.w3.org/TR/xquery/#static_context) |
| virtual bool | setDefaultOrderForEmptySequences( order_empty_mode_t aMode ) Set the default order for the empty sequence. |
| virtual void | setDocumentType( const String & aDocUri, TypeIdentifier_t type ) Set the type of a statically known document. |
| virtual void | setLibPath( const std::vector< String > & aLibPath ) Set the library lookup path (list of filesystem directories) for this static context. |
| virtual void | setModulePaths( const std::vector< String > & aModulePaths ) Set the URI and library lookup paths (lists of filesystem directories) for this static context. |
| virtual bool | setOrderingMode( ordering_mode_t aMode ) Set the ordering mode. |
| virtual void | setRevalidationMode( validation_mode_t aMode ) Set the revalidation mode. |
| virtual void | setTraceStream( std::ostream & ) Set the output stream that is used by the fn:trace function. |
| virtual void | setURIPath( const std::vector< String > & aURIPath ) Set the URI lookup path (list of filesystem directories) for this static context. |
| virtual bool | setXPath1_0CompatibMode( xpath1_0compatib_mode_t aMode ) Set the XPath 1.0 compatibility mode. |
| virtual bool | setXQueryVersion( xquery_version_t aMode ) Set the XQuery processing mode (version 1.0 or 3.0). |
| const virtual bool | validate( const Item & rootElement, Item & validatedResult, validation_mode_t validationMode=validate_strict ) Validates this Item. |
| const virtual bool | validate( const Item & rootElement, Item & validatedResult, const String & targetNamespace, validation_mode_t validationMode=validate_strict ) Validates this Item while loading the schema for targetNamespace Note: works only on document or element nodes, otherwise returns false. |
| const virtual bool | validateSimpleContent( const String & stringValue, const Item & typeQName, std::vector< Item > & resultList ) Validates stringValue as XML simple content, i.e. |
| inline virtual | ~StaticContext() Destructor. |
Protected Attibutes
| unsigned int | theRefCount |
Public Functions
addCollation
Adds a collation URI.
The URI specifies the locale and collation strength of the collation that is added. A valid collation URI must begin with http://www.zorba-xquery.com/collations/. This prefix is followed by a collation strength (i.e. PRIMARY, SECONDARY, TERTIARY, QUATTERNARY, or IDENTICAL) followed by a '/'. After the strength a lower-case two- or three-letter ISO-639 language code must follow. The URI may end with an upper-case two-letter ISO-3166. For example, http://www.zorba-xquery.com/collations/PRIMARY/en/US specifies an english language with US begin the country..
Internally, ICU is used for comparing strings. For detailed description see http://www.icu-project.org/apiref/icu4c/classCollator.html and http://www.icu-project.org/apiref/icu4c/classLocale.html
Parameters
| aURI |
the URI of the collation. |
Parameters
|
if an error occured (e.g. the URI was not a valid collation URI). |
addNamespace
Add a pair (prefix, URI) to the statically known namespaces that are available during query compilation.
See http://www.w3.org/TR/xquery/#static_context.
Returns
true if the pair was added to the set of statically known namespaces, false otherwise.
Parameters
|
if an error occures. |
addReference
containsFunction
const String & aFnNameUri,
const String & aFnNameLocal,
int arity
)
Check if a function with the given name and arity are registered in the context.
createChildContext
Create a child static context, i.e.
a context with the same information, of the given static context.
A child static context carries the same context as it's parent but can override any information.
declareOption
Declare an option (same as using declare option in XQuery)
Parameters
| aQName |
The QName of the option to declare. |
| aOptionValue |
The value of the option to declare. |
disableFunction
disableFunction
findFunctions
free
getAuditEvent
gets the audit event that is populated during execution
Returns
the audit event
getBoundarySpacePolicy
Get the boundary space policy.
(see http://www.w3.org/TR/xquery/#static_context)
Returns
boundary_space_mode_t the boundary space policy.
getCollectionType
Get the type of a statically known collection.
getConstructionMode
Get the construction mode.
(see http://www.w3.org/TR/xquery/#static_context)
Returns
construction_mode_t the construction mode.
getContextItemStaticType
Fetch the type of the context item.
getCopyNamespacesMode
Get the copy namespace mode.
(see http://www.w3.org/TR/xquery/#static_context)
Returns
aPreserve the preserve mode.
aInherit the inherit mode.
getDefaultCollation
Get the URI of the default collation.
Returns
String the URI of the default collation.
getDefaultElementAndTypeNamespace
Get the default element and type namespace URI.
Returns
String the URI for the default element and type namespace.
Parameters
|
if an error occured. |
getDefaultFunctionNamespace
Get the default function namespace.
Returns
String the URI of the default function namespace. DiagnosticHandler has been registered.
Parameters
|
if an error occured. |
getDefaultOrderForEmptySequences
Get the default order for the empty sequence.
(see http://www.w3.org/TR/xquery/#static_context)
Returns
order_empty_mode_t the ordering mode.
getDocumentType
Get the type of a statically known document.
getExternalVariables
Returns the QName of all external variables within the static context.
Parameters
| aVarsIter |
iterator to store the results. |
Parameters
|
if an error occured. |
getFullLibPath
Return the URI lookup path (list of filesystem directories) for this static context and all its parents.
getFullModulePaths
Return the union of the URI and library lookup paths (lists of filesystem directories) for this static context and all its parents.
getFullURIPath
Return the URI lookup path (list of filesystem directories) for this static context and all its parents.
getFunctionAnnotations
const Item & aQName,
int arity,
std::vector< Annotation_t > & aAnnotations
)
getFunctions
Get all functions declared in the given static context.
Returns
aFunctions all of the said functions
getFunctions
const String & aFnNameUri,
uint32_t arity,
std::vector< Function_t > & aFunctions
)
Get all functions with a specified namespace and airty\ declared in the given static context.
Parameters
| aFnNameUri |
the namespace for the functions to return |
| arity |
the arity for the functions to return |
| aFunctions |
all of the said functions |
getLibPath
Return the URI lookup path (list of filesystem directories) for this static context.
Returns any values set by StaticContext::setLibPath() on this static context. To return the full library lookup path for this static context and all its parents (usually most useful), call StaticContext::getFullLibPath().
getModulePaths
Return the union of the URI and library lookup paths (lists of filesystem directories) for this static context.
Returns any values set by StaticContext::setLibPath() and/or StaticContext::setURIPath() on this static context.
getNamespaceBindings
Get the list of all namespace bindings (prefix, uri) declared in this and its parent static contexts.
Parameters
| aBindings |
the bindings are added to this list |
getNamespaceURIByPrefix
Get the namespace URI for a given prefix.
Parameters
| aPrefix |
the prefix for which to retrieve the namespace URI. |
Returns
String the URI for the given prefix or an empty String if no URI could be found for the given prefix and an DiagnosticHandler has been registered.
Parameters
|
if an error occured (e.g. no URI could be found for the given prefix). |
getOption
Get an option that was declared using the declare option syntax.
Parameters
| aQName |
The QName of the option to get. |
| aOptionValue |
The value of the option if found. |
Returns
true if the option was found, false otherwise.
getOrderingMode
Get the ordering mode.
(see http://www.w3.org/TR/xquery/#static_context)
Returns
ordering_mode_t the ordering mode.
getRefCount
getRevalidationMode
Get the revalidation mode.
Returns
the revalidation mode.
getStaticCollectionManager
Returns a CollectionManager responsible for all collections which are statically declared in this static context.
The collection manager provides a set of functions for managing collections and their contents.
Returns
The collection manager responsible for managing collections of this context.
getURIPath
Return the URI lookup path (list of filesystem directories) for this static context.
Returns any values set by StaticContext::setURIPath() on this static context. To return the full URI lookup path for this static context and all its parents (usually most useful), call StaticContext::getFullURIPath().
getXPath1_0CompatibMode
Get the XPath 1.0 compatibility mode.
(see http://www.w3.org/TR/xquery/#static_context)
Returns
xpath1_0compatib_mode_t the XPath 1.0 compatibility mode.
getXQueryVersion
Get the XQuery processing mode (version 1.0 or 3.0).
Returns
xquery_version_t the XQuery version processing mode.
invoke
const Item & aQName,
const std::vector< ItemSequence_t > & aArgs
)
Invokes the XQuery function with the given name and the given parameters.
Note that the function to be invoked needs to be declared in this static context. In order to declare a function in the static context, the loadProlog method of this class can be used.
Also note that if the function to be invoked is an updating function, its resulting pending update list is implicitly applied by this function.
Parameters
| aQName |
the name of the function to be invoked |
| aArgs |
a vector of ItemSequences. One entry in the vector corresponds to one argument that is passed to the function. |
Returns
The result of the function that is invoked. If the function to be invoked is an updating function, the resulting item sequence is empty.
loadProlog
Loads the declarations and definitions of a given XQuery prolog into this static context.
This function compiles the prolog passed as first parameter and loads all declarations and definitions into this static context.
The static context extended by this prolog can then be used for creating a compiling a new query.
A StaticException is raised if the prolog could not be compiled or if the prolog does not contain valid declarations (e.g. duplicate declarations).
registerModule
Register a module providing access to external functions.
Register a module that provides access to external functions. The caller keeps the ownership of the Module and the StatelessExternalFunction objects passed to this function.
Parameters
| aModule |
the module object |
Returns
true if the module has been set, false otherwise.
registerURIMapper
Register a URI Mapper which will transform a given URI into several alternate potential URIs.
QQQ doc
registerURLResolver
Register a URL Resolver which will transform a given URL into a Resource.
QQQ doc
removeReference
resetTraceStream
Resets the output stream that is used by the fn:trace function to std::cerr.
resolve
Resolves the given URI against the value of the base-uri property from the static context.
Parameters
| aRelativeUri |
The relative URI to be resolved. |
resolve
Resolves the given relative URI against the absolute base URI.
Parameters
| aRelativeUri |
The relative URI to be resolved. |
| aBaseUri |
The absolute URI against which the resolving is performed. |
setAuditEvent
sets the audit event that will be populated during execution
Parameters
| anEvent |
the audit event |
setBaseURI
Set the base URI.
(see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aBaseURI |
the base URI as String. |
Returns
true if the base URI has been set, false otherwise.
setBoundarySpacePolicy
Set the boundary space policy.
(see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aMode |
the boundary space policy. |
Returns
true if the mode was set, false otherwise.
setCollectionType
Set the type of a statically known collection.
setConstructionMode
Set the construction mode.
(see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aMode |
the construction mode. |
Returns
true if the mode was set, false otherwise.
setContextItemStaticType
Set the type of the context item.
setCopyNamespacesMode
Set the copy namespace mode.
(see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aPreserve |
the preserve mode. |
| aInherit |
the inherit mode. |
Returns
true if the mode was set, false otherwise.
setDefaultCollation
Set the URI of the default collation.
(see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aURI |
URI of the default collation. |
Parameters
|
if an error occured (e.g., the URI does not identify a collation among the statically known collations. |
setDefaultElementAndTypeNamespace
Set the default element and type namespace (see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aURI |
of the default element and type namespace URI. |
Returns
true if the default element and type namespace URI has been set, false otherwise if an DiagnosticHandler has been registered.
Parameters
|
if an error occured. |
setDefaultFunctionNamespace
Set the default functionnamespace (see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aURI |
of the default function namespace. |
Returns
true if the default function namespace URI has been set, false otherwise if an DiagnosticHandler has been registered.
Parameters
|
if an error occured. |
setDefaultOrderForEmptySequences
Set the default order for the empty sequence.
(see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aMode |
the default order for the empty sequence. |
Returns
true if the mode was set, false otherwise.
setDocumentType
Set the type of a statically known document.
setLibPath
Set the library lookup path (list of filesystem directories) for this static context.
Queries which import modules that have external function implementations will look for the implementation of those functions (shared libraries) in these directories.
setModulePaths
Set the URI and library lookup paths (lists of filesystem directories) for this static context.
Note that calling this method will override any values previously passed to StaticContext::setURIPath() and StaticContext::setLibPath().
Convenience method which adds the listed directories to both the URI path and Library path for this static context.
setOrderingMode
Set the ordering mode.
(see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aMode |
the ordering mode. |
Returns
true if the mode was set, false otherwise.
setRevalidationMode
Set the revalidation mode.
Parameters
| aMode |
the revalidation mode. |
setTraceStream
std::ostream &
)
Set the output stream that is used by the fn:trace function.
Sets the output stream that is used by the fn:trace function to the given output stream. The default stream is std::cerr.
setURIPath
Set the URI lookup path (list of filesystem directories) for this static context.
Queries which resolve URIs (for instance, importing modules or schemas) will look in these directories.
setXPath1_0CompatibMode
Set the XPath 1.0 compatibility mode.
(see http://www.w3.org/TR/xquery/#static_context)
Parameters
| aMode |
the XPath 1.0 compatibility mode. |
Returns
true if the mode was set, false otherwise.
setXQueryVersion
Set the XQuery processing mode (version 1.0 or 3.0).
Parameters
| aMode |
the XQuery version. |
Returns
true if the version was set, false otherwise.
validate
const Item & rootElement,
Item & validatedResult,
validation_mode_t validationMode=validate_strict
)
Validates this Item.
Note: works only on document and element nodes, otherwise returns false.
Parameters
| rootElement |
the root of the tree beeing validated |
| validatedResult |
the result of the validation |
| validationMode |
Validation mode: default value is validate_strict |
Returns
true if validation is correct, false if validation is disabled, throws errors if validation fails
Parameters
|
if any validation error occured |
validate
const Item & rootElement,
Item & validatedResult,
const String & targetNamespace,
validation_mode_t validationMode=validate_strict
)
Validates this Item while loading the schema for targetNamespace Note: works only on document or element nodes, otherwise returns false.
Parameters
| rootElement |
the root of the tree beeing validated |
| validatedResult |
the result of the validation |
| targetNamespace |
the expected namespace of root of the tree beeing validated ??? |
| validationMode |
Validation mode: default value is validate_strict |
Returns
true if validation is correct, false if validation is disabled, throws errors if validation fails
Parameters
|
if any validation error occured |
validateSimpleContent
const String & stringValue,
const Item & typeQName,
std::vector< Item > & resultList
)
Validates stringValue as XML simple content, i.e.
the text value of attributes or text only element content.
Parameters
| stringValue |
the value to be validated |
| typeQName | |
| resultList |
the result of the validation, a vector of atomic Items |
Returns
true if validation is correct, false if validation is disabled, throws errors if validation fails
Parameters
|
if any validation error occured |
~StaticContext
Destructor.