static_context.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef XQP_STATIC_CONTEXT_API_H
00017 #define XQP_STATIC_CONTEXT_API_H
00018 
00019 #include <zorba/zorbastring.h>
00020 #include <zorba/typeident.h> 
00021 
00022 namespace zorba {
00023 
00024   /** \brief Instances of the class StaticContext containt the information that is available
00025    *         at the time the query is compiled.
00026    *
00027    * This class contains the information that is defined in the %XQuery specification
00028    * (see http://www.w3.org/TR/xquery/#static_context).
00029    *
00030    * A StaticContext can be created by calling Zorba::createStaticContext and then be passed
00031    * to the Zorba::compileQuery or XQuery::compile functions.
00032    * If no static context has been passed to any of these functions, a default static context
00033    * is used. It can be accessed by calling XQuery::getStaticContext on a compiled XQuery object.
00034    */
00035   class StaticContext
00036   {
00037     public:
00038       /** \brief XPath 1.0 compatibility mode as defined in 
00039        *         http://www.w3.org/TR/xquery/#static_context 
00040        */
00041       enum xpath1_0compatib_mode_t { xpath2_0, xpath1_0          };
00042 
00043       /** \brief Ordering mode as defined in http://www.w3.org/TR/xquery/#static_context.
00044        */
00045       enum ordering_mode_t         { ordered, unordered          };
00046 
00047       /** \brief Default order for empty sequences as defined in 
00048        *         http://www.w3.org/TR/xquery/#static_context.
00049        */
00050       enum order_empty_mode_t      { empty_greatest, empty_least };
00051 
00052       /** \brief Inherit part of the Copy-namespace mode as defined in 
00053        *         http://www.w3.org/TR/xquery/#static_context.
00054        */
00055       enum inherit_mode_t          { inherit_ns, no_inherit_ns   };
00056 
00057       /** \brief Preserve part of the Copy-namespace mode as defined in 
00058        *         http://www.w3.org/TR/xquery/#static_context.
00059        */
00060       enum preserve_mode_t         { preserve_ns, no_preserve_ns };
00061 
00062       /** \brief Boundary-space policy as defined in http://www.w3.org/TR/xquery/#static_context.
00063        */
00064       enum boundary_space_mode_t   { preserve_space, strip_space };
00065 
00066       /** \brief Construction mode as defined in http://www.w3.org/TR/xquery/#static_context.
00067        */
00068       enum construction_mode_t     { preserve_cons, strip_cons   };
00069 
00070       /** \brief Destructor
00071        */
00072       virtual ~StaticContext() {}
00073 
00074       /** \brief Create a child static context, i.e. a context with the same information,
00075        *         of the given static context.
00076        *
00077        * A child static context carries the same context as it's parent but
00078        * can override any information. 
00079        */
00080       virtual StaticContext_t
00081       createChildContext() const = 0;
00082       
00083       /** \brief Add a pair (prefix, URI) to the statically known namespaces that
00084        *         are available during query compilation.
00085        *
00086        *  See http://www.w3.org/TR/xquery/#static_context.
00087        *
00088        *  @param aPrefix the prefix String.
00089        *  @param aURI the URI String.
00090        *  @return true if the pair was added to the set of statically known namespaces,
00091        *          false otherwise.
00092        *  @throw ZorbaException if an error occures.
00093        */
00094       virtual bool   
00095       addNamespace( const String& aPrefix, const String& aURI ) = 0;
00096       
00097       /** \brief Get the namespace URI for a given prefix.
00098        *
00099        * @param aPrefix the prefix for which to retrieve the namespace URI.
00100        * @return String the URI for the given prefix or an empty String if no URI
00101        *         could be found for the given prefix and an ErrorHandler has been
00102        *         registered.
00103        * @throw ZorbaException if an error occured (e.g. no URI could be found for the given prefix).
00104        */
00105       virtual String   
00106       getNamespaceURIByPrefix( const String& aPrefix ) const = 0;
00107 
00108       /** \brief Set the default element and type namespace 
00109        *         (see http://www.w3.org/TR/xquery/#static_context)
00110        *
00111        * @param aURI of the default element and type namespace URI.
00112        * @return true if the default element and type namespace URI has been set, false otherwise
00113        *         if an ErrorHandler has been registered.
00114        * @throw ZorbaException if an error occured.
00115        */
00116       virtual bool   
00117       setDefaultElementAndTypeNamespace( const String& aURI ) = 0;
00118       
00119       /** \brief Get the default element and type namespace URI.
00120        *
00121        * @return String the URI for the default element and type namespace.
00122        * @throw ZorbaException if an error occured.
00123        */
00124       virtual String   
00125       getDefaultElementAndTypeNamespace( ) const = 0;
00126 
00127       /** \brief Set the default functionnamespace 
00128        *         (see http://www.w3.org/TR/xquery/#static_context)
00129        *
00130        * @param aURI of the default function namespace.
00131        * @return true if the default function namespace URI has been set, false otherwise
00132        *         if an ErrorHandler has been registered.
00133        * @throw ZorbaException if an error occured.
00134        */
00135       virtual bool   
00136       setDefaultFunctionNamespace( const String& aURI ) = 0;
00137       
00138       /** \brief Get the default function namespace.
00139        *
00140        * @return String the URI of the default function namespace.
00141        *         ErrorHandler has been registered.
00142        * @throw ZorbaException if an error occured.
00143        */
00144       virtual String   
00145       getDefaultFunctionNamespace( ) const = 0;
00146 
00147       /** \brief Adds a collation URI.
00148        *
00149        * The URI specifies the locale and collation strength of the collation that is added.
00150        * A valid collation URI must begin with http://www.flworfound.org/collations/.
00151        * This prefix is followed by a collation strength (i.e. PRIMARY, SECONDARY, TERTIARY,
00152        * QUATTERNARY, or IDENTICAL) followed by a '/'.
00153        * After the strength a lower-case two- or three-letter ISO-639 language code must follow.
00154        * The URI may end with an upper-case two-letter ISO-3166.
00155        * For example, http://www.flworfound.org/collations/PRIMARY/en/US
00156        * specifies an english language with US begin the country..
00157        *
00158        * Internally, ICU is used for comparing strings. For detailed description see
00159        * http://www.icu-project.org/apiref/icu4c/classCollator.html
00160        * and http://www.icu-project.org/apiref/icu4c/classLocale.html
00161        * 
00162        * @param aURI the URI of the collation.
00163        * @return true if the collation was added, false otherwise (e.g. the URI was not
00164        *         a valid collation URI).
00165        * @throw ZorbaException if an error occured.
00166        */
00167       virtual bool   
00168       addCollation( const String& aURI ) = 0;
00169 
00170       /** \brief Set the URI of the default collation.
00171        *         (see http://www.w3.org/TR/xquery/#static_context)
00172        *
00173        * @param aURI URI of the default collation.
00174        * @return true if the default collation URI has been set, false otherwise.
00175        * @throw ZorbaException if an error occured.
00176        */
00177       virtual bool   
00178       setDefaultCollation( const String& aURI ) = 0;
00179 
00180       /** \brief Get the URI of the default collation
00181        *
00182        * @return String the URI of the default collation.
00183        */
00184       virtual String 
00185       getDefaultCollation() const = 0;
00186 
00187       /** \brief Set the XPath 1.0 compatibility mode.
00188        *         (see http://www.w3.org/TR/xquery/#static_context)
00189        *
00190        * @param aMode the XPath 1.0 compatibility mode.
00191        * @return true if the mode was set, false otherwise.
00192        */
00193       virtual bool   
00194       setXPath1_0CompatibMode( xpath1_0compatib_mode_t aMode ) = 0;
00195 
00196       /** \brief Get the XPath 1.0 compatibility mode.
00197        *         (see http://www.w3.org/TR/xquery/#static_context)
00198        *
00199        * @return xpath1_0compatib_mode_t the XPath 1.0 compatibility mode.
00200        */
00201       virtual xpath1_0compatib_mode_t  
00202       getXPath1_0CompatibMode( ) const = 0;
00203 
00204       /** \brief Set the construction mode.
00205        *         (see http://www.w3.org/TR/xquery/#static_context)
00206        *
00207        * @param aMode the construction mode.
00208        * @return true if the mode was set, false otherwise.
00209        */
00210       virtual bool   
00211       setConstructionMode( construction_mode_t aMode ) = 0;
00212 
00213       /** \brief Get the construction mode.
00214        *         (see http://www.w3.org/TR/xquery/#static_context)
00215        *
00216        * @return construction_mode_t the construction mode.
00217        */
00218       virtual construction_mode_t  
00219       getConstructionMode( ) const = 0;
00220 
00221       /** \brief Set the ordering mode.
00222        *         (see http://www.w3.org/TR/xquery/#static_context)
00223        *
00224        * @param aMode the ordering mode.
00225        * @return true if the mode was set, false otherwise.
00226        */
00227       virtual bool   
00228       setOrderingMode( ordering_mode_t aMode ) = 0;
00229 
00230       /** \brief Get the ordering mode.
00231        *         (see http://www.w3.org/TR/xquery/#static_context)
00232        *
00233        * @return ordering_mode_t the ordering mode.
00234        */
00235       virtual ordering_mode_t  
00236       getOrderingMode( ) const = 0;
00237 
00238       /** \brief Set the default order for the empty sequence.
00239        *         (see http://www.w3.org/TR/xquery/#static_context)
00240        *
00241        * @param aMode the default order for the empty sequence.
00242        * @return true if the mode was set, false otherwise.
00243        */
00244       virtual bool   
00245       setDefaultOrderForEmptySequences( order_empty_mode_t aMode ) = 0;
00246 
00247       /** \brief Get the default order for the empty sequence.
00248        *         (see http://www.w3.org/TR/xquery/#static_context)
00249        *
00250        * @return order_empty_mode_t the ordering mode.
00251        */
00252       virtual order_empty_mode_t   
00253       getDefaultOrderForEmptySequences( ) const = 0;
00254 
00255       /** \brief Set the boundary space policy.
00256        *         (see http://www.w3.org/TR/xquery/#static_context)
00257        *
00258        * @param aMode the boundary space policy.
00259        * @return true if the mode was set, false otherwise.
00260        */
00261       virtual bool   
00262       setBoundarySpacePolicy( boundary_space_mode_t aMode) = 0;
00263 
00264       /** \brief Get the boundary space policy.
00265        *         (see http://www.w3.org/TR/xquery/#static_context)
00266        *
00267        * @return boundary_space_mode_t the boundary space policy.
00268        */
00269       virtual boundary_space_mode_t  
00270       getBoundarySpacePolicy( ) const = 0;
00271 
00272       /** \brief Set the copy namespace mode.
00273        *         (see http://www.w3.org/TR/xquery/#static_context)
00274        *
00275        * @param aPreserve the preserve mode.
00276        * @param aInherit the inherit mode.
00277        * @return true if the mode was set, false otherwise.
00278        */
00279       virtual bool   
00280       setCopyNamespacesMode( preserve_mode_t aPreserve, 
00281                              inherit_mode_t aInherit ) = 0;
00282 
00283       /** \brief Get the copy namespace mode.
00284        *         (see http://www.w3.org/TR/xquery/#static_context)
00285        *
00286        * @return aPreserve the preserve mode.
00287        * @return aInherit the inherit mode.
00288        */
00289       virtual void   
00290       getCopyNamespacesMode( preserve_mode_t& aPreserve, 
00291                              inherit_mode_t& aInherit ) const = 0;
00292 
00293       /** \brief Set the base URI.
00294        *         (see http://www.w3.org/TR/xquery/#static_context)
00295        *
00296        * @param aBaseURI the base URI as String.
00297        * @return true if the base URI has been set, false otherwise.
00298        */
00299       virtual bool   
00300       setBaseURI( const String& aBaseURI ) = 0;
00301 
00302       /** \brief Get the base URI.
00303        *
00304        * @return String the base URI.
00305        */
00306       virtual String   
00307       getBaseURI( ) const = 0;
00308 
00309 
00310       /** \brief Register a stateless external function.
00311        *
00312        * Register an external function that can be called within a query.
00313        * The caller keeps the ownership of the StatelessExternalFunction object passed
00314        * to this function.
00315        *
00316        * @param aExternalFunction the stateless external function.
00317        * @return true if the function has been set, false otherwise.
00318        */
00319       virtual bool 
00320       registerStatelessExternalFunction(StatelessExternalFunction* aExternalFunction) = 0;
00321 
00322   };
00323 
00324 } /* namespace zorba */
00325 #endif