dynamic_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 ZORBA_DYNAMIC_CONTEXT_API_H
00017 #define ZORBA_DYNAMIC_CONTEXT_API_H
00018 
00019 #include <time.h>
00020 #include <istream>
00021 
00022 #include <zorba/api_shared_types.h>
00023 
00024 namespace zorba {
00025 
00026   /** \brief Instances of the class DynamicContext contain the information that is available at the 
00027    *         time the query is executed.
00028    * 
00029    * The class contains the information that is defined in the %XQuery 
00030    * specification (see http://www.w3.org/TR/xquery/#eval_context).
00031    *
00032    * A dynamic context always belongs to a particular query and, hence, can be retrieved by
00033    * calling getDynamicContext on a compiled query (see XQuery::getDynamicContext()).
00034    *
00035    */
00036   class DynamicContext 
00037   {
00038     public:
00039       /** \brief Destructor
00040        *
00041        */
00042       virtual ~DynamicContext( ) {};
00043 
00044       /** \brief Defines the external variable identified by aQName and assigns it the value of
00045        *         aItem.
00046        *
00047        * @param aQName the QName that identifies the external variable.
00048        * @param aItem the Item that is used as value for the variable. 
00049        * @return true if the variable has been set, false otherwise.
00050        * @throw ZorbaException if an error occured (e.g. the given Item is not valid).
00051        */
00052       virtual bool
00053       setVariable( const String& aQName, const Item& aItem ) = 0;
00054 
00055       /** \brief Defines the external variable identifies by aQName and assigns it the sequence
00056        *         that is returned by evaluating aResultIterator.
00057        *
00058        * @param aQName the QName that identifies the external variable.
00059        * @param aResultIterator the ResultIterator producing the sequence that is assigned 
00060        *        to the variable.
00061        * @return true if the variable has been set successfully, false otherwise.
00062        * @throw ZorbaException if an error occured (e.g. the given ResultIterator is not valid).
00063        */
00064       virtual bool
00065       setVariable( const String& aQName, const ResultIterator_t& aResultIterator ) = 0;
00066 
00067       /** \brief Defines the external variable identifies by aQName and assigns it the 
00068        *         the document that results from reading and parsing the given istream.
00069        *
00070        * @param aQName the QName that identifies the external variable.
00071        * @param aDocURI the URI that is used to reference the document in the XmlDataManager.
00072        * @param aDocStream the istream used to read the document from.
00073        * @return true if the variable has been set successfully, false otherwise.
00074        * @throw ZorbaException if an error occured (e.g. the given ResultIterator is not valid).
00075        */
00076       virtual bool
00077       setVariableAsDocument ( const String& aQName, const String& aDocURI, 
00078                               std::istream& aDocStream) = 0;
00079 
00080       /** \brief Defines the context item.
00081        *
00082        * @param aItem the Item that is used as value for the context item.
00083        * @return true if the context item was set, false otherwise.
00084        * @throw ZorbaException if an error occured (e.g. the given Item is not valid).
00085        */
00086       virtual bool
00087       setContextItem ( const Item& aItem ) = 0;
00088 
00089       /** \brief Defines the context item and assigns it the document that results
00090        *         from parsing the given input stream.
00091        *
00092        * @param aDocURI the URI that is used to reference the document in the XmlDataManager.
00093        * @param aDocStream the istream used to read the document from.
00094        * @throw ZorbaException if an error occured (e.g. the input document could not be parsed).
00095        */
00096       virtual bool
00097       setContextItemAsDocument ( const String& aDocURI, std::istream& aDocStream ) = 0;
00098 
00099       /** \brief Defines the value of the current date time that can be accessed by the
00100        *         fn:current-dateTime() function at the time the query is executed.
00101        *
00102        * If the current date time has not been set explicitly the value of the date
00103        * and time is used at the time the query is created or cloned, respectively.
00104        *
00105        * @param aDateTimeItem the dateTime Item.
00106        * @return true if the variable has been set successfully, false otherwise.
00107        * @throw ZorbaException if an error occured (e.g. the given Item is invalid or not a Item of
00108        *        type dateTime
00109        */
00110       virtual bool
00111       setCurrentDateTime( const Item& aDateTimeItem ) = 0;
00112       
00113       /** \brief Retrieve the dateTime Item used at the time the query is executed 
00114        *         (see setCurrentDateTime()).
00115        *
00116        * @return Item the dateTime Item used at the time the query is executed.
00117        */
00118       virtual Item
00119       getCurrentDateTime( ) = 0;
00120 
00121       /** \brief Defines the variable of the implicit timezone to be used when a date, time, 
00122        *         or dateTime value that does not have a timezone is used in a comparison or 
00123        *         arithmetic operation.
00124        *
00125        * @param aTimezone the implicit timezone as int that should be used.
00126        * @return true if the implicit timezone has been set successfully, false otherwise.
00127        * @throw ZorbaException if an error occured.
00128        */
00129       virtual bool
00130       setImplicitTimezone( int aTimezone ) = 0;
00131 
00132       /** \brief Retrieve the implicit timezone used in comparisons or arithmetic operations
00133        *         of date, time, or dateTime values.
00134        *
00135        * @return int the implicit timezone. Note that 0 is returned if an error occured
00136        *         and an ErrorHandler is used.
00137        * @throw ZorbaException if an error occured.
00138        */
00139       virtual int
00140       getImplicitTimezone() = 0;
00141 
00142       /** \brief Defines the value of the default collection that is when calling the
00143        *         fn:collection function without a parameter.
00144        *
00145        * @param aCollectionUri the URI of the collection used by the fn:collection function.
00146        * @return true if the default collection has been set successfully, false otherwise.
00147        * @throw ZorbaException if an error occured.
00148        */
00149       virtual bool
00150       setDefaultCollection( const Item& aCollectionUri ) = 0;
00151 
00152   };
00153 
00154 } /* namespace zorba */
00155 
00156 #endif