1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 #ifndef ZORBA_GLOBALENV_H
18 #define ZORBA_GLOBALENV_H
19 
20 #include <memory>
21 #include <zorba/config.h>
22 #include "common/common.h"
23 #include "common/shared_types.h"
24 
25 namespace zorba {
26 
27 class RootTypeManager;
28 class root_static_context;
29 class XQueryXConvertor;
30 class DynamicLoader;
31 
32 namespace internal {
33 class HTTPURLResolver;
34 class FileURLResolver;
35 class AutoFSURIMapper;
36 #ifndef ZORBA_NO_FULL_TEXT
37 class ThesaurusURLResolver;
38 #endif /* ZORBA_NO_FULL_TEXT */
39 }
40 
41 namespace store {
42 class Store;
43 }
44 
45 
46 // exported for unit testing only
47 class ZORBA_DLL_PUBLIC GlobalEnvironment
48 {
49 private:
50 
51   static GlobalEnvironment        * m_globalEnv;
52 
53 private:
54   store::Store                    * m_store;
55 
56   RootTypeManager                 * theRootTypeManager;
57 
58   root_static_context             * theRootStaticContext;
59 
60   XQueryCompilerSubsystem         * m_compilerSubSys;
61 
62 #ifdef ZORBA_XQUERYX
63   XQueryXConvertor                * xqueryx_convertor;
64 #endif
65 
66   internal::HTTPURLResolver       * m_http_resolver;
67   internal::FileURLResolver       * m_file_resolver;
68   internal::AutoFSURIMapper       * m_autofs_mapper;
69 #ifndef ZORBA_NO_FULL_TEXT
70   internal::ThesaurusURLResolver  * m_thesaurus_resolver;
71 #endif /* ZORBA_NO_FULL_TEXT */
72 
73   mutable DynamicLoader           * m_dynamic_loader;
74 
75 public:
76 
77   static void init(store::Store* store);
78 
79   static void destroy();
80 
81   static void destroyStatics();
82 
getInstance()83   static GlobalEnvironment& getInstance()
84   {
85     assert(m_globalEnv);
86     return *m_globalEnv;
87   }
88 
89 public:
90   ~GlobalEnvironment();
91 
92   RootTypeManager& getRootTypeManager() const;
93 
94   static_context& getRootStaticContext() const;
95 
96   bool isRootStaticContextInitialized() const;
97 
98   XQueryCompilerSubsystem& getCompilerSubsystem();
99 
100   store::Store& getStore();
101 
102   store::ItemFactory* getItemFactory();
103 
104   store::IteratorFactory* getIteratorFactory();
105 
getHTTPURLResolver()106   internal::HTTPURLResolver* getHTTPURLResolver() const { return m_http_resolver; }
107 
getFileURLResolver()108   internal::FileURLResolver* getFileURLResolver() const { return m_file_resolver; }
109 
getAutoFSURIMapper()110   internal::AutoFSURIMapper* getAutoFSURIMapper() const { return m_autofs_mapper; }
111 
112 #ifndef ZORBA_NO_FULL_TEXT
getThesaurusURLResolver()113   internal::ThesaurusURLResolver* getThesaurusURLResolver() const { return m_thesaurus_resolver; }
114 #endif /* ZORBA_NO_FULL_TEXT */
115 
116   DynamicLoader* getDynamicLoader() const;
117 
118 #ifdef ZORBA_XQUERYX
119   XQueryXConvertor* getXQueryXConvertor();
120 #endif
121 
122 private:
123   GlobalEnvironment();
124 
125   void init_icu();
126 
127   void cleanup_icu();
128 };
129 
130 
131 #define GENV GlobalEnvironment::getInstance()
132 
133 #define GENV_TYPESYSTEM GlobalEnvironment::getInstance().getRootTypeManager()
134 
135 #define GENV_COMPILERSUBSYS GlobalEnvironment::getInstance().getCompilerSubsystem()
136 
137 #define GENV_STORE GlobalEnvironment::getInstance().getStore()
138 
139 #define GENV_ITEMFACTORY GlobalEnvironment::getInstance().getItemFactory()
140 
141 #define GENV_ITERATOR_FACTORY GlobalEnvironment::getInstance().getIteratorFactory()
142 
143 #define GENV_ROOT_STATIC_CONTEXT GlobalEnvironment::getInstance().getRootStaticContext()
144 
145 #define GENV_DYNAMIC_LOADER GlobalEnvironment::getInstance().getDynamicLoader()
146 
147 }
148 
149 #endif /* ZORBA_GLOBALENV_H */
150 
151 /*
152  * Local variables:
153  * mode: c++
154  * End:
155  */
156 /* vim:set et sw=2 ts=2: */
157