> 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 ZORBA_DYNAMIC_CONTEXT_API_H 00017 #define ZORBA_DYNAMIC_CONTEXT_API_H 00018 00019 #include <time.h> 00020 #include <istream> 00021 #include <memory> 00022 00023 #include <zorba/config.h> 00024 #include <zorba/api_shared_types.h> 00025 00026 namespace zorba { 00027 00028 /** \brief Instances of the class DynamicContext contain the information that is available at the 00029 * time the query is executed. 00030 * 00031 * The class contains the information that is defined in the %XQuery 00032 * specification (see http://www.w3.org/TR/xquery/#eval_context). 00033 * 00034 * A dynamic context always belongs to a particular query and, hence, can be retrieved by 00035 * calling getDynamicContext on a compiled query (see XQuery::getDynamicContext()). 00036 * 00037 */ 00038 class ZORBA_EXTERN_DECL DynamicContext 00039 { 00040 public: 00041 /** \brief Defines the external variable identified by aQName and assigns it the value of 00042 * aItem. 00043 * 00044 * @param aQName the QName that identifies the external variable. 00045 * @param aItem the Item that is used as value for the variable. 00046 * @return true if the variable has been set, false otherwise. 00047 * @throw ZorbaException if an error occured (e.g. the given Item is not valid). 00048 */ 00049 virtual bool 00050 setVariable( const String& aQName, const Item& aItem ) = 0; 00051 00052 /** \brief Defines the external variable identifies by aQName and assigns it the sequence 00053 * that is returned by evaluating aResultIterator. 00054 * 00055 * @param aQName the QName that identifies the external variable. 00056 * @param aResultIterator the ResultIterator producing the sequence that is assigned 00057 * to the variable. 00058 * @return true if the variable has been set successfully, false otherwise. 00059 * @throw ZorbaException if an error occured (e.g. the given ResultIterator is not valid). 00060 */ 00061 virtual bool 00062 setVariable( const String& aQName, const ResultIterator_t& aResultIterator ) = 0; 00063 00064 /** \brief Defines the external variable identifies by aQName and assigns it the 00065 * the document that results from reading and parsing the given istream. 00066 * 00067 * @param aQName the QName that identifies the external variable. 00068 * @param aDocURI the URI that is used to reference the document in the XmlDataManager. 00069 * @param aDocStream the istream used to read the document from. 00070 * Ownership of the input stream is transfered to the processor using an auto_ptr. 00071 * @return true if the variable has been set successfully, false otherwise. 00072 * @throw ZorbaException if an error occured (e.g. the given ResultIterator is not valid). 00073 */ 00074 virtual bool 00075 setVariableAsDocument ( const String& aQName, const String& aDocURI, 00076 std::auto_ptr<std::istream> aDocStream) = 0; 00077 00078 /** \brief Defines the context item. 00079 * 00080 * @param aItem the Item that is used as value for the context item. 00081 * @return true if the context item was set, false otherwise. 00082 * @throw ZorbaException if an error occured (e.g. the given Item is not valid). 00083 */ 00084 virtual bool 00085 setContextItem ( const Item& aItem ) = 0; 00086 00087 /** \brief Defines the context item and assigns it the document that results 00088 * from parsing the given input stream. 00089 * 00090 * @param aDocURI the URI that is used to reference the document in the XmlDataManager. 00091 * @param aDocStream the istream used to read the document from. 00092 * Ownership of the input stream is transfered to the processor using an auto_ptr. 00093 * @throw ZorbaException if an error occured (e.g. the input document could not be parsed). 00094 */ 00095 virtual bool 00096 setContextItemAsDocument ( const String& aDocURI, 00097 std::auto_ptr<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 used 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 protected: 00153 /** \brief Destructor 00154 * 00155 */ 00156 virtual ~DynamicContext( ) {}; 00157 }; 00158 00159 } /* namespace zorba */ 00160 00161 #endif