SourceForge.net Logo
XQQuery.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2001, 2008,
3 * DecisionSoft Limited. All rights reserved.
4 * Copyright (c) 2004, 2015 Oracle and/or its affiliates. All rights reserved.
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#ifndef XQQUERY_HPP
21#define XQQUERY_HPP
22
23#include <xqilla/framework/XQillaExport.hpp>
24#include <vector>
25#include <string>
30
31#include <xercesc/util/RefHashTableOf.hpp>
32
33class DynamicContext;
34class XQUserFunction;
35class XQGlobalVariable;
36class XQQuery;
37class DelayedModule;
38class DelayedFuncFactory;
39class StaticTyper;
40
41typedef std::vector<XQGlobalVariable*, XQillaAllocator<XQGlobalVariable*> > GlobalVariables;
42typedef std::vector<XQQuery*, XQillaAllocator<XQQuery*> > ImportedModules;
43typedef std::vector<DelayedFuncFactory*, XQillaAllocator<DelayedFuncFactory*> > DelayedFunctions;
44
45typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XQQuery> ModuleMap;
46
47class XQILLA_API ModuleCache : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
48{
49public:
50 ModuleCache(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *mm);
51
52 void put(XQQuery *module);
53 XQQuery *getByURI(const XMLCh *uri) const;
54 XQQuery *getByNamespace(const XMLCh *ns) const;
55
59};
60
75class XQILLA_API XQQuery : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
76{
77public:
80
82 // @{
83
92 DynamicContext *createDynamicContext(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
93 XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager) const;
94
109
124 Result execute(const Item::Ptr &contextItem, DynamicContext *context) const;
125
141 Result execute(const XMLCh *templateQName, DynamicContext *context) const;
142
153 void execute(EventHandler *events, DynamicContext* context) const;
154
166 void execute(EventHandler *events, const Item::Ptr &contextItem, DynamicContext *context) const;
167
180 void execute(EventHandler *events, const XMLCh *templateQName, DynamicContext *context) const;
181
202
215 void staticTyping(StaticTyper *styper = 0);
216 bool staticTypingOnce(StaticTyper *styper = 0);
217
219
221 // @{
222
224 const XMLCh* getQueryText() const { return m_szQueryText; }
225 void setQueryText(const XMLCh *v);
226
228 std::string getQueryPlan() const;
229
231
233 // @{
234
236 ASTNode* getQueryBody() const;
238 void setQueryBody(ASTNode* query);
239
241 void addFunction(XQUserFunction* fnDef);
243 const UserFunctions &getFunctions() const { return m_userDefFns; }
244
247 void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs,
248 const XMLCh *functionDeclaration, bool isPrivate = false,
249 int line = 1, int column = 1);
250 void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs,
251 const char *functionDeclaration, bool isPrivate = false,
252 int line = 1, int column = 1);
254 const DelayedFunctions &getDelayedFunctions() const { return m_delayedFunctions; }
255
257 void addVariable(XQGlobalVariable* varDef);
259 const GlobalVariables &getVariables() const { return m_userDefVars; }
260
262 const ImportedModules &getImportedModules() const { return m_importedModules; }
263
264 ModuleCache *getModuleCache() const { return m_moduleCache; }
265 bool isModuleCacheOwned() const { return m_moduleCacheOwned; }
266
268 const XMLCh* getFile() const { return m_szCurrentFile; }
269
271 void setFile(const XMLCh* file);
272
273 bool getVersion3() const { return m_version3; }
274 void setVersion3(bool v) { m_version3 = v; }
275
276 const DynamicContext *getStaticContext() const { return m_context; }
277
278 XQQuery *getNext() const { return m_next; }
279 void setNext(XQQuery *n) { m_next = n; }
280
282
284 // @{
285
287 void setIsLibraryModule(bool bIsModule=true);
289 bool getIsLibraryModule() const;
291 void setModuleTargetNamespace(const XMLCh* uri);
293 const XMLCh* getModuleTargetNamespace() const;
295 void importModule(const XMLCh* szUri, VectorOfStrings* locations, const LocationInfo *location);
296 void importModule(XQQuery *module);
297
298 XQQuery *findModuleForVariable(const XMLCh *uri, const XMLCh *name);
299 XQQuery *findModuleForFunction(const XMLCh *uri, const XMLCh *name, int numArgs);
300
302
303private:
305 XQQuery(DynamicContext *context, bool contextOwned, ModuleCache *moduleCache,
306 XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr);
307
308 XQQuery(const XQQuery &);
309 XQQuery &operator=(const XQQuery &);
310
311 XQQuery *parseModule(const XMLCh *ns, const XMLCh *at, const LocationInfo *location) const;
312 void executeProlog(DynamicContext *context) const;
313
314private:
316 XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* m_memMgr;
317
319 DynamicContext *m_context;
320 bool m_contextOwned;
321
322 ASTNode* m_query;
323
324 bool m_bIsLibraryModule;
325 const XMLCh* m_szTargetNamespace;
326 const XMLCh* m_szQueryText;
327 const XMLCh* m_szCurrentFile;
328
329 UserFunctions m_userDefFns;
330 DelayedFunctions m_delayedFunctions;
331 GlobalVariables m_userDefVars;
332 ImportedModules m_importedModules;
333
334 ModuleCache *m_moduleCache;
335 bool m_moduleCacheOwned;
336
337 bool m_version3;
338
339 enum { BEFORE, DURING, AFTER } m_staticTyped;
340
341 // The next module with the same target namespace
342 XQQuery *m_next;
343
344 friend class QueryResult;
345 friend class XQilla;
346 friend class DelayedModule;
347};
348
349#endif
std::vector< const XMLCh *, XQillaAllocator< const XMLCh * > > VectorOfStrings
Definition DocumentCache.hpp:37
std::vector< XQUserFunction *, XQillaAllocator< XQUserFunction * > > UserFunctions
Definition StaticContext.hpp:48
xercesc::RefHashTableOf< XQQuery > ModuleMap
Definition XQQuery.hpp:45
std::vector< DelayedFuncFactory *, XQillaAllocator< DelayedFuncFactory * > > DelayedFunctions
Definition XQQuery.hpp:43
std::vector< XQQuery *, XQillaAllocator< XQQuery * > > ImportedModules
Definition XQQuery.hpp:42
std::vector< XQGlobalVariable *, XQillaAllocator< XQGlobalVariable * > > GlobalVariables
Definition XQQuery.hpp:41
The execution time dynamic context interface.
Definition DynamicContext.hpp:39
Definition EventHandler.hpp:30
A class that gives records a location in the query.
Definition LocationInfo.hpp:30
Definition XQQuery.hpp:48
void put(XQQuery *module)
XQQuery * getByURI(const XMLCh *uri) const
ModuleMap byURI_
Definition XQQuery.hpp:56
XQQuery * getByNamespace(const XMLCh *ns) const
ModuleMap byNamespace_
Definition XQQuery.hpp:57
ModuleCache(xercesc::MemoryManager *mm)
ImportedModules ordered_
Definition XQQuery.hpp:58
A scoped pointer wrapper for the lazily evaluated query result.
Definition Result.hpp:38
Encapsulates a query expression.
Definition XQQuery.hpp:76
void execute(EventHandler *events, const Item::Ptr &contextItem, DynamicContext *context) const
Executes the query or stylesheet using the given context item and DynamicContext, sending the output ...
const XMLCh * getModuleTargetNamespace() const
Gets the module taget namespace for this query.
void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs, const XMLCh *functionDeclaration, bool isPrivate=false, int line=1, int column=1)
Adds a function defined in XQuery syntax.
const DynamicContext * getStaticContext() const
Definition XQQuery.hpp:276
std::string getQueryPlan() const
Returns the query plan as XML. This is designed for debug and informative purposes only.
void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs, const char *functionDeclaration, bool isPrivate=false, int line=1, int column=1)
void setQueryBody(ASTNode *query)
Set the query body to an ASTNode.
void setNext(XQQuery *n)
Definition XQQuery.hpp:279
XQQuery * getNext() const
Definition XQQuery.hpp:278
void setVersion3(bool v)
Definition XQQuery.hpp:274
bool getVersion3() const
Definition XQQuery.hpp:273
bool isModuleCacheOwned() const
Definition XQQuery.hpp:265
~XQQuery()
Destructor.
void staticTyping(StaticTyper *styper=0)
Perform type calculation and related optimizations.
bool getIsLibraryModule() const
Returns whether this query is a module or not.
Result execute(const XMLCh *templateQName, DynamicContext *context) const
Executes the stylesheet starting at the named template using the given DynamicContext,...
DynamicContext * createDynamicContext(xercesc::MemoryManager *memMgr=xercesc::XMLPlatformUtils::fgMemoryManager) const
Creates a DynamicContext based on the static context used to parse this query.
void setQueryText(const XMLCh *v)
void importModule(XQQuery *module)
ModuleCache * getModuleCache() const
Definition XQQuery.hpp:264
void execute(EventHandler *events, DynamicContext *context) const
Executes the query using the given DynamicContext, sending the output of the query to the given Event...
void setModuleTargetNamespace(const XMLCh *uri)
Sets the module target namespace for this query.
void setFile(const XMLCh *file)
Sets the name of the file that this query was parsed from.
const ImportedModules & getImportedModules() const
Returns a vector of all XQGlobalVariable objects from the query.
Definition XQQuery.hpp:262
const XMLCh * getFile() const
Returns the name of the file that this query was parsed from.
Definition XQQuery.hpp:268
void addVariable(XQGlobalVariable *varDef)
Adds a XQGlobalVariable to the query.
const UserFunctions & getFunctions() const
Returns a vector of all XQUserFunction objects from the query.
Definition XQQuery.hpp:243
void addFunction(XQUserFunction *fnDef)
Adds an XQUserFunction to the query (also adds it as a template if necessary)
const XMLCh * getQueryText() const
Returns the expression that was parsed to create this XQQuery object.
Definition XQQuery.hpp:224
void setIsLibraryModule(bool bIsModule=true)
Sets whether this query is a module or not.
void execute(EventHandler *events, const XMLCh *templateQName, DynamicContext *context) const
Executes the stylesheet starting at the named template using the given DynamicContext,...
ASTNode * getQueryBody() const
Get the query body as an ASTNode.
void importModule(const XMLCh *szUri, VectorOfStrings *locations, const LocationInfo *location)
Performs a module import from the given target namespace and locations.
bool staticTypingOnce(StaticTyper *styper=0)
XQQuery * findModuleForFunction(const XMLCh *uri, const XMLCh *name, int numArgs)
Result execute(const Item::Ptr &contextItem, DynamicContext *context) const
Executes the query or stylesheet using the given context item and DynamicContext, returning a lazy it...
void staticResolution()
Perform static resolution on the query.
XQQuery * findModuleForVariable(const XMLCh *uri, const XMLCh *name)
const DelayedFunctions & getDelayedFunctions() const
Returns a vector of all XQUserFunction objects from the query.
Definition XQQuery.hpp:254
const GlobalVariables & getVariables() const
Returns a vector of all XQGlobalVariable objects from the query.
Definition XQQuery.hpp:259
Result execute(DynamicContext *context) const
Executes the query using the given DynamicContext, returning a lazy iterator over the results.
Provides factory methods for creating XQQuery and DynamicContext objects.
Definition XQilla.hpp:53