> 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_ZORBA_API_H 00017 #define XQP_ZORBA_API_H 00018 00019 #include <istream> 00020 00021 #include <zorba/config.h> 00022 #include <zorba/api_shared_types.h> 00023 00024 #include <zorba/version.h> 00025 #include <zorba/exception.h> 00026 #include <zorba/xquery.h> 00027 #include <zorba/static_context.h> 00028 #include <zorba/dynamic_context.h> 00029 #include <zorba/result_iterator.h> 00030 #include <zorba/item.h> 00031 #include <zorba/item_factory.h> 00032 #include <zorba/zorbastring.h> 00033 #include <zorba/exception.h> 00034 #include <zorba/error_handler.h> 00035 #include <zorba/xmldatamanager.h> 00036 #include <zorba/default_error_handler.h> 00037 #include <zorba/collection.h> 00038 #include <zorba/options.h> 00039 00040 namespace zorba { 00041 00042 /** 00043 * The Zorba class is the single point of access to the %Zorba engine. 00044 * There exists one instance of the Zorba class per process. 00045 * It can be used to (1) create and compile queries, (2) create static contexts, 00046 * (3) provides access to the XmlDataManager, and (4) provides access to the ItemFactory. 00047 */ 00048 class ZORBA_EXTERN_DECL Zorba 00049 { 00050 public: 00051 00052 /** \brief Gets the singleton instance of the Zorba object. 00053 * 00054 * The Zorba object provides factory methods for creating and/or compiling 00055 * XQuery objects, creating StaticContext objects, and accessing components 00056 * as, for example, the ItemFactory or the XmlDataManager. 00057 * 00058 * The first time this function is called, the %Zorba Engine is initialized. 00059 * Thereby, it initializes all the libraries that are used in the system, i.e. 00060 * ICU, libxml2, xerces, and libcurl. 00061 * 00062 * @return Zorba the singleton Zorba object 00063 * 00064 */ 00065 static Zorba* 00066 getInstance(void* store); 00067 00068 /** \brief Releases all resources aquired by the Zorba %XQuery Engine. 00069 * 00070 * Also releases resources aquired by the libraries used (i.e. icu, 00071 * libxml2, xerces, libcurl). 00072 * 00073 * Before calling shutdown, all xquery objects, items, contexts, ... have 00074 * to be closed or gone out of scope; otherwise this call may fail. 00075 * 00076 * After shutdown has been called, any calls to zorba are invalid. 00077 * 00078 * getInstance may used to reinitialize the engine. 00079 * 00080 */ 00081 virtual void 00082 shutdown() = 0; 00083 00084 /** \brief Destructor. 00085 * 00086 * The destructor is called during static deinitialization if getInstance 00087 * has been called at least once before. 00088 */ 00089 virtual ~Zorba(); 00090 00091 /** \brief Creates an XQuery object. 00092 * 00093 * This methods creates an XQuery object without implicitliy assigning it 00094 * a query. An object returned by this method can be compiled (see compileQuery). 00095 * 00096 * Optionally, this method takes an ErrorHandler as parameter. In the case 00097 * an ErrorHandler is passed as parameter, each error that occurs during 00098 * compiling or executing the query, is reported to the passed error handler. 00099 * If no ErrorHandler is given, exceptions are thrown for each of these errors. 00100 * 00101 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00102 * @return XQuery the newly created XQuery object. 00103 */ 00104 virtual XQuery_t 00105 createQuery(ErrorHandler* aErrorHandler = 0) = 0; 00106 00107 00108 /** \brief Creates and compiles an XQuery object. 00109 * 00110 * This methods creates an XQuery object and compiles the query string 00111 * passed to this method. 00112 * 00113 * Optionally, this method takes an ErrorHandler as parameter. In the case 00114 * an ErrorHandler is passed as parameter, each error that occurs during 00115 * compiling or executing the query, is reported to the passed error handler. 00116 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00117 * 00118 * @param aQuery the query string for the new XQuery object. 00119 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00120 * @return XQuery the newly created and compiled XQuery object. 00121 */ 00122 virtual XQuery_t 00123 compileQuery(const String& aQuery, ErrorHandler* aErrorHandler = 0) = 0; 00124 00125 /** \brief Creates and compiles an XQuery object using a StaticContext. 00126 * 00127 * This methods creates an XQuery object and compiles the query string 00128 * passed to this method. Compilation is done using the information 00129 * contained in the StaticContext that is passed as parameter. 00130 * 00131 * Optionally, this method takes an ErrorHandler as parameter. In the case 00132 * an ErrorHandler is passed as parameter, each error that occurs during 00133 * compiling or executing the query, is reported to the passed error handler. 00134 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00135 * 00136 * @param aQuery the query string for the new XQuery object. 00137 * @param aContext the StaticContext that contains information used for compiling the query. 00138 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00139 * @return XQuery the newly created and compiled XQuery object. 00140 */ 00141 virtual XQuery_t 00142 compileQuery(const String& aQuery, const StaticContext_t& aContext, 00143 ErrorHandler* aErrorHandler = 0) = 0; 00144 00145 /** \brief Creates and compiles an XQuery object using the given CompilerHints. 00146 * 00147 * This methods creates an XQuery object and compiles the query string 00148 * passed to this method. Compilation and optimization is done with respect 00149 * to the given CompilerHints. 00150 * 00151 * Optionally, this method takes an ErrorHandler as parameter. In the case 00152 * an ErrorHandler is passed as parameter, each error that occurs during 00153 * compiling or executing the query, is reported to the passed error handler. 00154 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00155 * 00156 * @param aQuery the query string for the new XQuery object. 00157 * @param aCompilerHints the CompilerHints used to compile the query. 00158 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00159 * @return XQuery the newly created and compiled XQuery object. 00160 */ 00161 virtual XQuery_t 00162 compileQuery(const String& aQuery, const Zorba_CompilerHints_t& aCompilerHints, 00163 ErrorHandler* aErrorHandler = 0) = 0; 00164 00165 /** \brief Creates and compiles an XQuery object using the given 00166 * CompilerHints and StaticContext. 00167 * 00168 * This methods creates an XQuery object and compiles the query string 00169 * passed to this method. Compilation and optimization is done with respect 00170 * to the given CompilerHints. Moreover, compilation is done using the 00171 * information contained in the StaticContext. 00172 * 00173 * Optionally, this method takes an ErrorHandler as parameter. In the case 00174 * an ErrorHandler is passed as parameter, each error that occurs during 00175 * compiling or executing the query, is reported to the passed error handler. 00176 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00177 * 00178 * @param aQuery the query string for the new XQuery object. 00179 * @param aContext the StaticContext that contains information used for compiling the query. 00180 * @param aCompilerHints the CompilerHints used to compile the query. 00181 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00182 * @return XQuery the newly created and compiled XQuery object. 00183 */ 00184 virtual XQuery_t 00185 compileQuery(const String& aQuery, const StaticContext_t& aContext, 00186 const Zorba_CompilerHints_t& aCompilerHints, 00187 ErrorHandler* aErrorHandler = 0) = 0; 00188 00189 /** \brief Creates and compiles an XQuery object. 00190 * 00191 * This methods creates an XQuery object and compiles the query that is 00192 * passed to this method as an input stream. 00193 * 00194 * Optionally, this method takes an ErrorHandler as parameter. In the case 00195 * an ErrorHandler is passed as parameter, each error that occurs during 00196 * compiling or executing the query, is reported to the passed error handler. 00197 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00198 * 00199 * @param aQuery the input stream providing the query. 00200 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00201 * @return XQuery the newly created and compiled XQuery object. 00202 */ 00203 virtual XQuery_t 00204 compileQuery(std::istream& aQuery, ErrorHandler* aErrorHandler = 0) = 0; 00205 00206 /** \brief Creates and compiles an XQuery object using a StaticContext. 00207 * 00208 * This methods creates an XQuery object and compiles the query that is 00209 * passed to this method as an input stream. Compilation is done using 00210 * the information contained in the StaticContext that is passed as 00211 * parameter. 00212 * 00213 * Optionally, this method takes an ErrorHandler as parameter. In the case 00214 * an ErrorHandler is passed as parameter, each error that occurs during 00215 * compiling or executing the query, is reported to the passed error handler. 00216 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00217 * 00218 * @param aQuery the input stream providing the query. 00219 * @param aContext the StaticContext that contains information used for compiling the query. 00220 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00221 * @return XQuery the newly created and compiled XQuery object. 00222 */ 00223 virtual XQuery_t 00224 compileQuery(std::istream& aQuery, const StaticContext_t& aContext, 00225 ErrorHandler* aErrorHandler = 0) = 0; 00226 00227 /** \brief Creates and compiles an XQuery object using the given CompilerHints. 00228 * 00229 * This methods creates an XQuery object and compiles the query that is 00230 * passed to this method as an input stream. Compilation and optimization 00231 * is done with respect to the given CompilerHints. 00232 * 00233 * Optionally, this method takes an ErrorHandler as parameter. In the case 00234 * an ErrorHandler is passed as parameter, each error that occurs during 00235 * compiling or executing the query, is reported to the passed error handler. 00236 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00237 * 00238 * @param aQuery the input stream providing the query. 00239 * @param aCompilerHints the CompilerHints used to compile the query. 00240 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00241 * @return XQuery the newly created and compiled XQuery object. 00242 */ 00243 virtual XQuery_t 00244 compileQuery(std::istream& aQuery, const Zorba_CompilerHints_t& aCompilerHints, 00245 ErrorHandler* aErrorHandler = 0) = 0; 00246 00247 /** \brief Creates and compiles an XQuery object using the given 00248 * CompilerHints and StaticContext. 00249 * 00250 * This methods creates an XQuery object and compiles the query that is 00251 * passed to this method as an input stream. Compilation and optimization 00252 * is done with respect to the given CompilerHints. Moreover, compilation 00253 * is done using the information contained in the StaticContext. 00254 * 00255 * Optionally, this method takes an ErrorHandler as parameter. In the case 00256 * an ErrorHandler is passed as parameter, each error that occurs during 00257 * compiling or executing the query, is reported to the passed error handler. 00258 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00259 * 00260 * @param aQuery the input stream providing the query. 00261 * @param aContext the StaticContext that contains information used for compiling the query. 00262 * @param aCompilerHints the CompilerHints used to compile the query. 00263 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00264 * @return XQuery the newly created and compiled XQuery object. 00265 */ 00266 virtual XQuery_t 00267 compileQuery(std::istream& aQuery, const StaticContext_t& aContext, 00268 const Zorba_CompilerHints_t& aCompilerHints, 00269 ErrorHandler* aErrorHandler = 0) = 0; 00270 00271 /** \brief Creates a new StaticContext. 00272 * 00273 * The method returns a StaticContext object that can be used 00274 * for compiling a query. Instances of the StaticContext class are 00275 * returned as a smart pointer. 00276 * That is, objects of type StaticContext_t are reference counted object 00277 * to an dynamically allocated StaticContext object. Hence, each object can h 00278 * have multiple owners. The object is deleted if nobody holds on to an StaticContext_t 00279 * object anymore. 00280 * 00281 * Optionally, this method takes an ErrorHandler as parameter. In the case 00282 * an ErrorHandler is passed as parameter, each error that occurs during 00283 * setting or getting information out of the StaticContext, is reported to the passed 00284 * ErrorHandler. 00285 * If not ErrorHandler is given, exceptions are thrown for each of these errors. 00286 * 00287 * @param aErrorHandler the ErrorHandler to which errors should be reported. 00288 * @return StaticContext_t a new StaticContext object. 00289 */ 00290 virtual StaticContext_t 00291 createStaticContext(ErrorHandler* aErrorHandler = 0) = 0; 00292 00293 /** \brief Gets the singelton instance of the ItemFactory. 00294 * 00295 * @return ItemFactory the singleton instance of the ItemFactory. 00296 */ 00297 virtual ItemFactory* 00298 getItemFactory() = 0; 00299 00300 /** \brief Gets the singleton instance of the XmlDataManager object. 00301 * 00302 * @return XmlDataManager the singelton instance of the XmlDataManager. 00303 */ 00304 virtual XmlDataManager* 00305 getXmlDataManager() = 0; 00306 00307 /** \brief Get information about the used version of %Zorba. 00308 * 00309 * @return Version informatino about the used %Zorba version. 00310 */ 00311 static const Version& 00312 version(); 00313 00314 }; /* class Zorba */ 00315 00316 } /* namespace zorba */ 00317 00318 /** 00319 * \example simple.cpp 00320 * This is a simple example that demonstrate how to create, compile, and execute queries. 00321 * 00322 * \example datamanager.cpp 00323 * This file contains some examples that demonstrate how the XmlDataManager can be used 00324 * to load files, create collection, etc. 00325 * 00326 * \example context.cpp 00327 * This file demonstrates how the ItemFactory can be used to create new Items and 00328 * bind the Items to external variables in the dynamic context of a query. 00329 * 00330 * \example errors.cpp 00331 * This file demonstrates how error management and handling is done in Zorba. 00332 * 00333 * \example serialization.cpp 00334 * This file shows examples of how to serialize query results, for example as XML. 00335 * 00336 * \example sax2.cpp 00337 * An example showing XML serialization that is performed using SAX2. 00338 * 00339 * \example external_functions.cpp 00340 * This file shows some simple examples of external functions. 00341 * 00342 */ 00343 #endif /* XQP_ZORBA_API_H */