00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef XQQUERY_HPP
00023 #define XQQUERY_HPP
00024
00025 #include <xqilla/framework/XQillaExport.hpp>
00026 #include <vector>
00027 #include <string>
00028 #include <xercesc/util/XMemory.hpp>
00029 #include <xercesc/sax/InputSource.hpp>
00030 #include <xqilla/runtime/ResultImpl.hpp>
00031 #include <xqilla/runtime/LazySequenceResult.hpp>
00032 #include <xqilla/context/StaticContext.hpp>
00033
00034 class DynamicContext;
00035 class XQUserFunction;
00036 class XQGlobalVariable;
00037 class XQUserFunctionInstance;
00038 class XQQuery;
00039
00040 typedef std::vector<XQGlobalVariable*, XQillaAllocator<XQGlobalVariable*> > GlobalVariables;
00041 typedef std::vector<XQQuery*, XQillaAllocator<XQQuery*> > ImportedModules;
00042
00057 class XQILLA_API XQQuery : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
00058 {
00059 public:
00061 ~XQQuery();
00062
00064
00065
00074 DynamicContext *createDynamicContext(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
00075 XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager) const;
00076
00090 Result execute(DynamicContext* context) const;
00091
00106 Result execute(const Item::Ptr &contextItem, DynamicContext *context) const;
00107
00123 Result execute(const XMLCh *templateQName, DynamicContext *context) const;
00124
00135 void execute(EventHandler *events, DynamicContext* context) const;
00136
00148 void execute(EventHandler *events, const Item::Ptr &contextItem, DynamicContext *context) const;
00149
00162 void execute(EventHandler *events, const XMLCh *templateQName, DynamicContext *context) const;
00163
00183 void staticResolution();
00184
00197 void staticTyping(StaticTyper *styper = 0);
00198
00200
00202
00203
00205 const XMLCh* getQueryText() const;
00206
00208 std::string getQueryPlan() const;
00209
00211
00213
00214
00216 ASTNode* getQueryBody() const;
00218 void setQueryBody(ASTNode* query);
00219
00221 void addFunction(XQUserFunction* fnDef);
00223 const UserFunctions &getFunctions() const { return m_userDefFns; }
00224
00226 void addVariable(XQGlobalVariable* varDef);
00228 const GlobalVariables &getVariables() const { return m_userDefVars; }
00229
00231 const ImportedModules &getImportedModules() const { return m_importedModules; }
00232
00234 const XMLCh* getFile() const;
00236 void setFile(const XMLCh* file);
00237
00238 const DynamicContext *getStaticContext() const { return m_context; }
00239
00241
00243
00244
00246 void setIsLibraryModule(bool bIsModule=true);
00248 bool getIsLibraryModule() const;
00250 void setModuleTargetNamespace(const XMLCh* uri);
00252 const XMLCh* getModuleTargetNamespace() const;
00254 void importModule(const XMLCh* szUri, VectorOfStrings* locations, StaticContext* context, const LocationInfo *location);
00255
00257
00258 private:
00260 class QueryResult : public ResultImpl
00261 {
00262 public:
00263 QueryResult(const XQQuery *query);
00264
00265 Item::Ptr nextOrTail(Result &tail, DynamicContext *context);
00266
00267 private:
00268 const XQQuery *_query;
00269 };
00270
00271 private:
00273 XQQuery(const XMLCh* queryText, DynamicContext *context, bool contextOwned = false,
00274 XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
00275 XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager);
00276
00277 XQQuery(const XQQuery &);
00278 XQQuery &operator=(const XQQuery &);
00279
00280 void executeProlog(DynamicContext *context) const;
00281
00282 private:
00284 XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* m_memMgr;
00285
00287 DynamicContext *m_context;
00288 bool m_contextOwned;
00289
00290 ASTNode* m_query;
00291
00292 bool m_bIsLibraryModule;
00293 const XMLCh* m_szTargetNamespace;
00294 const XMLCh* m_szQueryText;
00295 const XMLCh* m_szCurrentFile;
00296
00297 UserFunctions m_userDefFns;
00298 GlobalVariables m_userDefVars;
00299 ImportedModules m_importedModules;
00300
00301 friend class QueryResult;
00302 friend class XQilla;
00303 };
00304
00305 #endif