> The XQuery Processor
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/config.h> 00020 #include <zorba/zorbastring.h> 00021 #include <zorba/typeident.h> 00022 #include <zorba/static_context_consts.h> 00023 #include <zorba/smart_ptr.h> 00024 00025 namespace zorba { 00026 00027 /** \brief Instances of the class StaticContext containt the information that is available 00028 * at the time the query is compiled. 00029 * 00030 * This class contains the information that is defined in the %XQuery specification 00031 * (see http://www.w3.org/TR/xquery/#static_context). 00032 * 00033 * A StaticContext can be created by calling Zorba::createStaticContext and then be passed 00034 * to the Zorba::compileQuery or XQuery::compile functions. 00035 * If no static context has been passed to any of these functions, a default static context 00036 * is used. It can be accessed by calling XQuery::getStaticContext on a compiled XQuery object. 00037 * 00038 * Note: This class is reference counted. When writing multi-threaded clients, 00039 * it is the responibility of the client code to synchronize assignments to the 00040 * SmartPtr holding this object. 00041 */ 00042 class ZORBA_EXTERN_DECL StaticContext : public SmartObject 00043 { 00044 public: 00045 /** \brief Destructor 00046 */ 00047 virtual ~StaticContext() {} 00048 00049 /** \brief Create a child static context, i.e. a context with the same information, 00050 * of the given static context. 00051 * 00052 * A child static context carries the same context as it's parent but 00053 * can override any information. 00054 */ 00055 virtual StaticContext_t 00056 createChildContext() const = 0; 00057 00058 /** \brief Add a pair (prefix, URI) to the statically known namespaces that 00059 * are available during query compilation. 00060 * 00061 * See http://www.w3.org/TR/xquery/#static_context. 00062 * 00063 * @param aPrefix the prefix String. 00064 * @param aURI the URI String. 00065 * @return true if the pair was added to the set of statically known namespaces, 00066 * false otherwise. 00067 * @throw ZorbaException if an error occures. 00068 */ 00069 virtual bool 00070 addNamespace( const String& aPrefix, const String& aURI ) = 0; 00071 00072 /** \brief Get the namespace URI for a given prefix. 00073 * 00074 * @param aPrefix the prefix for which to retrieve the namespace URI. 00075 * @return String the URI for the given prefix or an empty String if no URI 00076 * could be found for the given prefix and an ErrorHandler has been 00077 * registered. 00078 * @throw ZorbaException if an error occured (e.g. no URI could be found for the given prefix). 00079 */ 00080 virtual String 00081 getNamespaceURIByPrefix( const String& aPrefix ) const = 0; 00082 00083 /** \brief Set the default element and type namespace 00084 * (see http://www.w3.org/TR/xquery/#static_context) 00085 * 00086 * @param aURI of the default element and type namespace URI. 00087 * @return true if the default element and type namespace URI has been set, false otherwise 00088 * if an ErrorHandler has been registered. 00089 * @throw ZorbaException if an error occured. 00090 */ 00091 virtual bool 00092 setDefaultElementAndTypeNamespace( const String& aURI ) = 0; 00093 00094 /** \brief Get the default element and type namespace URI. 00095 * 00096 * @return String the URI for the default element and type namespace. 00097 * @throw ZorbaException if an error occured. 00098 */ 00099 virtual String 00100 getDefaultElementAndTypeNamespace( ) const = 0; 00101 00102 /** \brief Set the default functionnamespace 00103 * (see http://www.w3.org/TR/xquery/#static_context) 00104 * 00105 * @param aURI of the default function namespace. 00106 * @return true if the default function namespace URI has been set, false otherwise 00107 * if an ErrorHandler has been registered. 00108 * @throw ZorbaException if an error occured. 00109 */ 00110 virtual bool 00111 setDefaultFunctionNamespace( const String& aURI ) = 0; 00112 00113 /** \brief Get the default function namespace. 00114 * 00115 * @return String the URI of the default function namespace. 00116 * ErrorHandler has been registered. 00117 * @throw ZorbaException if an error occured. 00118 */ 00119 virtual String 00120 getDefaultFunctionNamespace( ) const = 0; 00121 00122 /** \brief Adds a collation URI. 00123 * 00124 * The URI specifies the locale and collation strength of the collation that is added. 00125 * A valid collation URI must begin with http://www.flworfound.org/collations/. 00126 * This prefix is followed by a collation strength (i.e. PRIMARY, SECONDARY, TERTIARY, 00127 * QUATTERNARY, or IDENTICAL) followed by a '/'. 00128 * After the strength a lower-case two- or three-letter ISO-639 language code must follow. 00129 * The URI may end with an upper-case two-letter ISO-3166. 00130 * For example, http://www.flworfound.org/collations/PRIMARY/en/US 00131 * specifies an english language with US begin the country.. 00132 * 00133 * Internally, ICU is used for comparing strings. For detailed description see 00134 * http://www.icu-project.org/apiref/icu4c/classCollator.html 00135 * and http://www.icu-project.org/apiref/icu4c/classLocale.html 00136 * 00137 * @param aURI the URI of the collation. 00138 * @return true if the collation was added, false otherwise (e.g. the URI was not 00139 * a valid collation URI). 00140 * @throw ZorbaException if an error occured. 00141 */ 00142 virtual bool 00143 addCollation( const String& aURI ) = 0; 00144 00145 /** \brief Set the URI of the default collation. 00146 * (see http://www.w3.org/TR/xquery/#static_context) 00147 * 00148 * @param aURI URI of the default collation. 00149 * @return true if the default collation URI has been set, false otherwise. 00150 * @throw ZorbaException if an error occured. 00151 */ 00152 virtual bool 00153 setDefaultCollation( const String& aURI ) = 0; 00154 00155 /** \brief Get the URI of the default collation 00156 * 00157 * @return String the URI of the default collation. 00158 */ 00159 virtual String 00160 getDefaultCollation() const = 0; 00161 00162 /** \brief Set the XPath 1.0 compatibility mode. 00163 * (see http://www.w3.org/TR/xquery/#static_context) 00164 * 00165 * @param aMode the XPath 1.0 compatibility mode. 00166 * @return true if the mode was set, false otherwise. 00167 */ 00168 virtual bool 00169 setXPath1_0CompatibMode( xpath1_0compatib_mode_t aMode ) = 0; 00170 00171 /** \brief Get the XPath 1.0 compatibility mode. 00172 * (see http://www.w3.org/TR/xquery/#static_context) 00173 * 00174 * @return xpath1_0compatib_mode_t the XPath 1.0 compatibility mode. 00175 */ 00176 virtual xpath1_0compatib_mode_t 00177 getXPath1_0CompatibMode( ) const = 0; 00178 00179 /** \brief Set the construction mode. 00180 * (see http://www.w3.org/TR/xquery/#static_context) 00181 * 00182 * @param aMode the construction mode. 00183 * @return true if the mode was set, false otherwise. 00184 */ 00185 virtual bool 00186 setConstructionMode( construction_mode_t aMode ) = 0; 00187 00188 /** \brief Get the construction mode. 00189 * (see http://www.w3.org/TR/xquery/#static_context) 00190 * 00191 * @return construction_mode_t the construction mode. 00192 */ 00193 virtual construction_mode_t 00194 getConstructionMode( ) const = 0; 00195 00196 /** \brief Set the ordering mode. 00197 * (see http://www.w3.org/TR/xquery/#static_context) 00198 * 00199 * @param aMode the ordering mode. 00200 * @return true if the mode was set, false otherwise. 00201 */ 00202 virtual bool 00203 setOrderingMode( ordering_mode_t aMode ) = 0; 00204 00205 /** \brief Get the ordering mode. 00206 * (see http://www.w3.org/TR/xquery/#static_context) 00207 * 00208 * @return ordering_mode_t the ordering mode. 00209 */ 00210 virtual ordering_mode_t 00211 getOrderingMode( ) const = 0; 00212 00213 /** \brief Set the default order for the empty sequence. 00214 * (see http://www.w3.org/TR/xquery/#static_context) 00215 * 00216 * @param aMode the default order for the empty sequence. 00217 * @return true if the mode was set, false otherwise. 00218 */ 00219 virtual bool 00220 setDefaultOrderForEmptySequences( order_empty_mode_t aMode ) = 0; 00221 00222 /** \brief Get the default order for the empty sequence. 00223 * (see http://www.w3.org/TR/xquery/#static_context) 00224 * 00225 * @return order_empty_mode_t the ordering mode. 00226 */ 00227 virtual order_empty_mode_t 00228 getDefaultOrderForEmptySequences( ) const = 0; 00229 00230 /** \brief Set the boundary space policy. 00231 * (see http://www.w3.org/TR/xquery/#static_context) 00232 * 00233 * @param aMode the boundary space policy. 00234 * @return true if the mode was set, false otherwise. 00235 */ 00236 virtual bool 00237 setBoundarySpacePolicy( boundary_space_mode_t aMode) = 0; 00238 00239 /** \brief Get the boundary space policy. 00240 * (see http://www.w3.org/TR/xquery/#static_context) 00241 * 00242 * @return boundary_space_mode_t the boundary space policy. 00243 */ 00244 virtual boundary_space_mode_t 00245 getBoundarySpacePolicy( ) const = 0; 00246 00247 /** \brief Set the copy namespace mode. 00248 * (see http://www.w3.org/TR/xquery/#static_context) 00249 * 00250 * @param aPreserve the preserve mode. 00251 * @param aInherit the inherit mode. 00252 * @return true if the mode was set, false otherwise. 00253 */ 00254 virtual bool 00255 setCopyNamespacesMode( preserve_mode_t aPreserve, 00256 inherit_mode_t aInherit ) = 0; 00257 00258 /** \brief Get the copy namespace mode. 00259 * (see http://www.w3.org/TR/xquery/#static_context) 00260 * 00261 * @return aPreserve the preserve mode. 00262 * @return aInherit the inherit mode. 00263 */ 00264 virtual void 00265 getCopyNamespacesMode( preserve_mode_t& aPreserve, 00266 inherit_mode_t& aInherit ) const = 0; 00267 00268 /** \brief Set the base URI. 00269 * (see http://www.w3.org/TR/xquery/#static_context) 00270 * 00271 * @param aBaseURI the base URI as String. 00272 * @return true if the base URI has been set, false otherwise. 00273 */ 00274 virtual bool 00275 setBaseURI( const String& aBaseURI ) = 0; 00276 00277 /** \brief Get the base URI. 00278 * 00279 * @return String the base URI. 00280 */ 00281 virtual String 00282 getBaseURI( ) const = 0; 00283 00284 00285 /** \brief Register a stateless external function. 00286 * 00287 * Register an external function that can be called within a query. 00288 * The caller keeps the ownership of the StatelessExternalFunction object passed 00289 * to this function. 00290 * 00291 * @param aExternalFunction the stateless external function. 00292 * @return true if the function has been set, false otherwise. 00293 */ 00294 virtual bool 00295 registerStatelessExternalFunction(StatelessExternalFunction* aExternalFunction) = 0; 00296 00297 }; 00298 00299 } /* namespace zorba */ 00300 #endif