Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef XQQUERY_HPP
00021 #define XQQUERY_HPP
00022
00023 #include <xqilla/framework/XQillaExport.hpp>
00024 #include <vector>
00025 #include <string>
00026 #include <xercesc/util/XMemory.hpp>
00027 #include <xercesc/sax/InputSource.hpp>
00028 #include <xqilla/runtime/ResultImpl.hpp>
00029 #include <xqilla/context/StaticContext.hpp>
00030
00031 #include <xercesc/util/RefHashTableOf.hpp>
00032
00033 class DynamicContext;
00034 class XQUserFunction;
00035 class XQGlobalVariable;
00036 class XQQuery;
00037 class DelayedModule;
00038 class DelayedFuncFactory;
00039 class StaticTyper;
00040
00041 typedef std::vector<XQGlobalVariable*, XQillaAllocator<XQGlobalVariable*> > GlobalVariables;
00042 typedef std::vector<XQQuery*, XQillaAllocator<XQQuery*> > ImportedModules;
00043 typedef std::vector<DelayedFuncFactory*, XQillaAllocator<DelayedFuncFactory*> > DelayedFunctions;
00044
00045 typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XQQuery> ModuleMap;
00046
00047 class XQILLA_API ModuleCache : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
00048 {
00049 public:
00050 ModuleCache(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *mm);
00051
00052 void put(XQQuery *module);
00053 XQQuery *getByURI(const XMLCh *uri) const;
00054 XQQuery *getByNamespace(const XMLCh *ns) const;
00055
00056 ModuleMap byURI_;
00057 ModuleMap byNamespace_;
00058 ImportedModules ordered_;
00059 };
00060
00075 class XQILLA_API XQQuery : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
00076 {
00077 public:
00079 ~XQQuery();
00080
00082
00083
00092 DynamicContext *createDynamicContext(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
00093 XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager) const;
00094
00108 Result execute(DynamicContext* context) const;
00109
00124 Result execute(const Item::Ptr &contextItem, DynamicContext *context) const;
00125
00141 Result execute(const XMLCh *templateQName, DynamicContext *context) const;
00142
00153 void execute(EventHandler *events, DynamicContext* context) const;
00154
00166 void execute(EventHandler *events, const Item::Ptr &contextItem, DynamicContext *context) const;
00167
00180 void execute(EventHandler *events, const XMLCh *templateQName, DynamicContext *context) const;
00181
00201 void staticResolution();
00202
00215 void staticTyping(StaticTyper *styper = 0);
00216 bool staticTypingOnce(StaticTyper *styper = 0);
00217
00219
00221
00222
00224 const XMLCh* getQueryText() const { return m_szQueryText; }
00225 void setQueryText(const XMLCh *v);
00226
00228 std::string getQueryPlan() const;
00229
00231
00233
00234
00236 ASTNode* getQueryBody() const;
00238 void setQueryBody(ASTNode* query);
00239
00241 void addFunction(XQUserFunction* fnDef);
00243 const UserFunctions &getFunctions() const { return m_userDefFns; }
00244
00247 void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs,
00248 const XMLCh *functionDeclaration, bool isPrivate = false,
00249 int line = 1, int column = 1);
00250 void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs,
00251 const char *functionDeclaration, bool isPrivate = false,
00252 int line = 1, int column = 1);
00254 const DelayedFunctions &getDelayedFunctions() const { return m_delayedFunctions; }
00255
00257 void addVariable(XQGlobalVariable* varDef);
00259 const GlobalVariables &getVariables() const { return m_userDefVars; }
00260
00262 const ImportedModules &getImportedModules() const { return m_importedModules; }
00263
00264 ModuleCache *getModuleCache() const { return m_moduleCache; }
00265 bool isModuleCacheOwned() const { return m_moduleCacheOwned; }
00266
00268 const XMLCh* getFile() const { return m_szCurrentFile; }
00269
00271 void setFile(const XMLCh* file);
00272
00273 bool getVersion3() const { return m_version3; }
00274 void setVersion3(bool v) { m_version3 = v; }
00275
00276 const DynamicContext *getStaticContext() const { return m_context; }
00277
00278 XQQuery *getNext() const { return m_next; }
00279 void setNext(XQQuery *n) { m_next = n; }
00280
00282
00284
00285
00287 void setIsLibraryModule(bool bIsModule=true);
00289 bool getIsLibraryModule() const;
00291 void setModuleTargetNamespace(const XMLCh* uri);
00293 const XMLCh* getModuleTargetNamespace() const;
00295 void importModule(const XMLCh* szUri, VectorOfStrings* locations, const LocationInfo *location);
00296 void importModule(XQQuery *module);
00297
00298 XQQuery *findModuleForVariable(const XMLCh *uri, const XMLCh *name);
00299 XQQuery *findModuleForFunction(const XMLCh *uri, const XMLCh *name, int numArgs);
00300
00302
00303 private:
00305 XQQuery(DynamicContext *context, bool contextOwned, ModuleCache *moduleCache,
00306 XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr);
00307
00308 XQQuery(const XQQuery &);
00309 XQQuery &operator=(const XQQuery &);
00310
00311 XQQuery *parseModule(const XMLCh *ns, const XMLCh *at, const LocationInfo *location) const;
00312 void executeProlog(DynamicContext *context) const;
00313
00314 private:
00316 XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* m_memMgr;
00317
00319 DynamicContext *m_context;
00320 bool m_contextOwned;
00321
00322 ASTNode* m_query;
00323
00324 bool m_bIsLibraryModule;
00325 const XMLCh* m_szTargetNamespace;
00326 const XMLCh* m_szQueryText;
00327 const XMLCh* m_szCurrentFile;
00328
00329 UserFunctions m_userDefFns;
00330 DelayedFunctions m_delayedFunctions;
00331 GlobalVariables m_userDefVars;
00332 ImportedModules m_importedModules;
00333
00334 ModuleCache *m_moduleCache;
00335 bool m_moduleCacheOwned;
00336
00337 bool m_version3;
00338
00339 enum { BEFORE, DURING, AFTER } m_staticTyped;
00340
00341
00342 XQQuery *m_next;
00343
00344 friend class QueryResult;
00345 friend class XQilla;
00346 friend class DelayedModule;
00347 };
00348
00349 #endif