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 XQQuery;
00038
00039 typedef std::vector<XQUserFunction*, XQillaAllocator<XQUserFunction*> > UserFunctions;
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
00102 void execute(EventHandler *events, DynamicContext* context) const;
00103
00123 void staticResolution(StaticContext *context = 0);
00124
00137 void staticTyping(StaticContext *context = 0);
00138
00140
00142
00143
00145 const XMLCh* getQueryText() const;
00146
00148 std::string getQueryPlan() const;
00149
00151
00153
00154
00156 ASTNode* getQueryBody() const;
00158 void setQueryBody(ASTNode* query);
00159
00161 void addFunction(XQUserFunction* fnDef);
00163 const UserFunctions &getFunctions() const { return m_userDefFns; }
00164
00166 void addVariable(XQGlobalVariable* varDef);
00168 const GlobalVariables &getVariables() const { return m_userDefVars; }
00169
00171 const ImportedModules &getImportedModules() const { return m_importedModules; }
00172
00174 const XMLCh* getFile() const;
00176 void setFile(const XMLCh* file);
00177
00178 const DynamicContext *getStaticContext() const { return m_context; }
00179
00181
00183
00184
00186 void setIsLibraryModule(bool bIsModule=true);
00188 bool getIsLibraryModule() const;
00190 void setModuleTargetNamespace(const XMLCh* uri);
00192 const XMLCh* getModuleTargetNamespace() const;
00194 void importModule(const XMLCh* szUri, VectorOfStrings* locations, StaticContext* context, const LocationInfo *location);
00195
00197
00198 private:
00200 class QueryResult : public ResultImpl
00201 {
00202 public:
00203 QueryResult(const XQQuery *query);
00204
00205 Item::Ptr next(DynamicContext *context);
00206 std::string asString(DynamicContext *context, int indent) const;
00207
00208 private:
00209 const XQQuery *_query;
00210 Result _parent;
00211 bool _toDo;
00212 };
00213
00214 private:
00216 XQQuery(const XMLCh* queryText, DynamicContext *context, bool contextOwned = false,
00217 XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
00218 XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager);
00219
00220 XQQuery(const XQQuery &);
00221 XQQuery &operator=(const XQQuery &);
00222
00223 void executeProlog(DynamicContext *context) const;
00224
00225 private:
00227 XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* m_memMgr;
00228
00230 DynamicContext *m_context;
00231 bool m_contextOwned;
00232
00233 ASTNode* m_query;
00234
00235 bool m_bIsLibraryModule;
00236 const XMLCh* m_szTargetNamespace;
00237 const XMLCh* m_szQueryText;
00238 const XMLCh* m_szCurrentFile;
00239
00240 UserFunctions m_userDefFns;
00241 GlobalVariables m_userDefVars;
00242 ImportedModules m_importedModules;
00243
00244 friend class QueryResult;
00245 friend class XQilla;
00246 };
00247
00248 #endif