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>
26 #include <xercesc/util/XMemory.hpp>
30 
31 #include <xercesc/util/RefHashTableOf.hpp>
32 
33 class DynamicContext;
34 class XQUserFunction;
35 class XQGlobalVariable;
36 class XQQuery;
37 class DelayedModule;
38 class DelayedFuncFactory;
39 class StaticTyper;
40 
41 typedef std::vector<XQGlobalVariable*, XQillaAllocator<XQGlobalVariable*> > GlobalVariables;
42 typedef std::vector<XQQuery*, XQillaAllocator<XQQuery*> > ImportedModules;
43 typedef std::vector<DelayedFuncFactory*, XQillaAllocator<DelayedFuncFactory*> > DelayedFunctions;
44 
45 typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XQQuery> ModuleMap;
46 
47 class XQILLA_API ModuleCache : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
48 {
49 public:
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 
75 class XQILLA_API XQQuery : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
76 {
77 public:
80 
82  // @{
83 
92  DynamicContext *createDynamicContext(XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager *memMgr =
93  XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager) const;
94 
108  Result execute(DynamicContext* context) const;
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 
303 private:
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 
314 private:
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
XQQuery
Encapsulates a query expression.
Definition: XQQuery.hpp:76
XQQuery::execute
Result execute(DynamicContext *context) const
Executes the query using the given DynamicContext, returning a lazy iterator over the results.
XQQuery::addFunction
void addFunction(XQUserFunction *fnDef)
Adds an XQUserFunction to the query (also adds it as a template if necessary)
XQQuery::getVersion3
bool getVersion3() const
Definition: XQQuery.hpp:273
InputSource.hpp
GlobalVariables
std::vector< XQGlobalVariable *, XQillaAllocator< XQGlobalVariable * > > GlobalVariables
Definition: XQQuery.hpp:39
XQQuery::execute
Result execute(const XMLCh *templateQName, DynamicContext *context) const
Executes the stylesheet starting at the named template using the given DynamicContext,...
ModuleCache::getByNamespace
XQQuery * getByNamespace(const XMLCh *ns) const
RefCountPointer< const Item >
XQQuery::getModuleCache
ModuleCache * getModuleCache() const
Definition: XQQuery.hpp:264
DynamicContext
The execution time dynamic context interface.
Definition: DynamicContext.hpp:39
XQQuery::setQueryText
void setQueryText(const XMLCh *v)
XQQuery::setIsLibraryModule
void setIsLibraryModule(bool bIsModule=true)
Sets whether this query is a module or not.
XQQuery::createDynamicContext
DynamicContext * createDynamicContext(xercesc::MemoryManager *memMgr=xercesc::XMLPlatformUtils::fgMemoryManager) const
Creates a DynamicContext based on the static context used to parse this query.
ModuleCache::put
void put(XQQuery *module)
XQQuery::importModule
void importModule(XQQuery *module)
XQQuery::isModuleCacheOwned
bool isModuleCacheOwned() const
Definition: XQQuery.hpp:265
XQQuery::setVersion3
void setVersion3(bool v)
Definition: XQQuery.hpp:274
ModuleCache::ModuleCache
ModuleCache(xercesc::MemoryManager *mm)
XQQuery::getNext
XQQuery * getNext() const
Definition: XQQuery.hpp:278
XQQuery::getModuleTargetNamespace
const XMLCh * getModuleTargetNamespace() const
Gets the module taget namespace for this query.
XQQuery::addDelayedFunction
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.
UserFunctions
std::vector< XQUserFunction *, XQillaAllocator< XQUserFunction * > > UserFunctions
Definition: StaticContext.hpp:48
ImportedModules
std::vector< XQQuery *, XQillaAllocator< XQQuery * > > ImportedModules
Definition: XQQuery.hpp:42
ModuleCache::byURI_
ModuleMap byURI_
Definition: XQQuery.hpp:56
XQQuery::getQueryBody
ASTNode * getQueryBody() const
Get the query body as an ASTNode.
XQQuery::staticTypingOnce
bool staticTypingOnce(StaticTyper *styper=0)
DelayedFunctions
std::vector< DelayedFuncFactory *, XQillaAllocator< DelayedFuncFactory * > > DelayedFunctions
Definition: XQQuery.hpp:43
XQQuery::addVariable
void addVariable(XQGlobalVariable *varDef)
Adds a XQGlobalVariable to the query.
XQQuery::staticTyping
void staticTyping(StaticTyper *styper=0)
Perform type calculation and related optimizations.
ModuleMap
xercesc::RefHashTableOf< XQQuery > ModuleMap
Definition: XQQuery.hpp:45
XQQuery::getQueryPlan
std::string getQueryPlan() const
Returns the query plan as XML. This is designed for debug and informative purposes only.
Result
A scoped pointer wrapper for the lazily evaluated query result.
Definition: Result.hpp:38
ModuleCache::getByURI
XQQuery * getByURI(const XMLCh *uri) const
StaticContext.hpp
XQQuery::getIsLibraryModule
bool getIsLibraryModule() const
Returns whether this query is a module or not.
LocationInfo
A class that gives records a location in the query.
Definition: LocationInfo.hpp:30
XQQuery::getFile
const XMLCh * getFile() const
Returns the name of the file that this query was parsed from.
Definition: XQQuery.hpp:268
XQQuery::setFile
void setFile(const XMLCh *file)
Sets the name of the file that this query was parsed from.
XQQuery::setNext
void setNext(XQQuery *n)
Definition: XQQuery.hpp:279
XQQuery::execute
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...
XQQuery::findModuleForVariable
XQQuery * findModuleForVariable(const XMLCh *uri, const XMLCh *name)
XQQuery::getStaticContext
const DynamicContext * getStaticContext() const
Definition: XQQuery.hpp:276
XQQuery::getImportedModules
const ImportedModules & getImportedModules() const
Returns a vector of all XQGlobalVariable objects from the query.
Definition: XQQuery.hpp:262
XQQuery::getFunctions
const UserFunctions & getFunctions() const
Returns a vector of all XQUserFunction objects from the query.
Definition: XQQuery.hpp:243
XQilla
Provides factory methods for creating XQQuery and DynamicContext objects.
Definition: XQilla.hpp:53
ModuleCache::ordered_
ImportedModules ordered_
Definition: XQQuery.hpp:58
ModuleCache::byNamespace_
ModuleMap byNamespace_
Definition: XQQuery.hpp:57
XQQuery::~XQQuery
~XQQuery()
Destructor.
XQQuery::findModuleForFunction
XQQuery * findModuleForFunction(const XMLCh *uri, const XMLCh *name, int numArgs)
XQQuery::execute
void execute(EventHandler *events, const XMLCh *templateQName, DynamicContext *context) const
Executes the stylesheet starting at the named template using the given DynamicContext,...
XQQuery::getDelayedFunctions
const DelayedFunctions & getDelayedFunctions() const
Returns a vector of all XQUserFunction objects from the query.
Definition: XQQuery.hpp:254
EventHandler
Definition: EventHandler.hpp:30
VectorOfStrings
std::vector< const XMLCh *, XQillaAllocator< const XMLCh * > > VectorOfStrings
Definition: DocumentCache.hpp:35
XQQuery::setModuleTargetNamespace
void setModuleTargetNamespace(const XMLCh *uri)
Sets the module target namespace for this query.
ModuleCache
Definition: XQQuery.hpp:48
XQQuery::setQueryBody
void setQueryBody(ASTNode *query)
Set the query body to an ASTNode.
XQQuery::staticResolution
void staticResolution()
Perform static resolution on the query.
ResultImpl.hpp
XQQuery::getQueryText
const XMLCh * getQueryText() const
Returns the expression that was parsed to create this XQQuery object.
Definition: XQQuery.hpp:224
XQQuery::addDelayedFunction
void addDelayedFunction(const XMLCh *uri, const XMLCh *name, size_t numArgs, const char *functionDeclaration, bool isPrivate=false, int line=1, int column=1)
XQQuery::execute
void execute(EventHandler *events, DynamicContext *context) const
Executes the query using the given DynamicContext, sending the output of the query to the given Event...
XQQuery::execute
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 ...
XQQuery::getVariables
const GlobalVariables & getVariables() const
Returns a vector of all XQGlobalVariable objects from the query.
Definition: XQQuery.hpp:259
XQQuery::importModule
void importModule(const XMLCh *szUri, VectorOfStrings *locations, const LocationInfo *location)
Performs a module import from the given target namespace and locations.
XMemory.hpp