1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.qedeq.kernel.context; |
19 |
| |
20 |
| import java.io.File; |
21 |
| import java.io.IOException; |
22 |
| |
23 |
| import org.qedeq.kernel.base.module.Specification; |
24 |
| import org.qedeq.kernel.bo.module.Kernel; |
25 |
| import org.qedeq.kernel.bo.module.KernelState; |
26 |
| import org.qedeq.kernel.bo.module.ModuleAddress; |
27 |
| import org.qedeq.kernel.bo.module.ModuleFactory; |
28 |
| import org.qedeq.kernel.bo.module.ModuleProperties; |
29 |
| import org.qedeq.kernel.bo.module.QedeqBo; |
30 |
| import org.qedeq.kernel.common.XmlFileExceptionList; |
31 |
| import org.qedeq.kernel.config.QedeqConfig; |
32 |
| import org.qedeq.kernel.log.QedeqLog; |
33 |
| import org.qedeq.kernel.trace.Trace; |
34 |
| import org.qedeq.kernel.utility.IoUtility; |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| public final class KernelContext implements Kernel { |
44 |
| |
45 |
| |
46 |
| private static final String KERNEL_VERSION = "0.03.04"; |
47 |
| |
48 |
| |
49 |
| private static final String KERNEL_VERSION_DIRECTORY = KERNEL_VERSION.replace('.', '_'); |
50 |
| |
51 |
| |
52 |
| private static final String DESCRIPTIVE_KERNEL_VERSION |
53 |
| = "Hilbert II - Version " + KERNEL_VERSION + " (mongaga)"; |
54 |
| |
55 |
| |
56 |
| private static final String MAXIMAL_RULE_VERSION = "1.00.00"; |
57 |
| |
58 |
| |
59 |
| private static final KernelContext INSTANCE = new KernelContext(); |
60 |
| |
61 |
| |
62 |
| private final KernelState initialState = new KernelState() { |
63 |
| |
64 |
3
| public void startup(final ModuleFactory moduleFactory) throws IOException {
|
65 |
3
| QedeqLog.getInstance().logMessage("This is "
|
66 |
| + KernelContext.getInstance().getDescriptiveKernelVersion()); |
67 |
3
| QedeqLog.getInstance().logMessage(" see \"http://www.qedeq.org\" for more "
|
68 |
| + "information"); |
69 |
3
| QedeqLog.getInstance().logMessage(" supports rules till version "
|
70 |
| + KernelContext.getInstance().getMaximalRuleVersion()); |
71 |
3
| config = new QedeqConfig(
|
72 |
| new File(IoUtility.getStartDirectory("qedeq"), "config"), |
73 |
| "org.qedeq.properties", |
74 |
| "This file is part of the project *Hilbert II* - http://www.qedeq.org"); |
75 |
3
| QedeqLog.getInstance().logMessage("QEDEQ kernel opened.");
|
76 |
3
| KernelContext.this.moduleFactory = moduleFactory;
|
77 |
3
| currentState = readyState;
|
78 |
3
| moduleFactory.init();
|
79 |
| } |
80 |
| |
81 |
0
| public boolean isReady() {
|
82 |
0
| return false;
|
83 |
| } |
84 |
| |
85 |
0
| public QedeqConfig getConfig() {
|
86 |
0
| throw new IllegalStateException("Kernel not initialized");
|
87 |
| } |
88 |
| |
89 |
0
| public void shutdown() {
|
90 |
| } |
91 |
| |
92 |
0
| public void init() {
|
93 |
0
| throw new IllegalStateException("Kernel not initialized");
|
94 |
| } |
95 |
| |
96 |
0
| public void removeAllModules() {
|
97 |
0
| throw new IllegalStateException("Kernel not initialized");
|
98 |
| } |
99 |
| |
100 |
0
| public void clearLocalBuffer() throws IOException {
|
101 |
0
| throw new IllegalStateException("Kernel not initialized");
|
102 |
| } |
103 |
| |
104 |
0
| public QedeqBo loadModule(final String address) throws XmlFileExceptionList {
|
105 |
0
| throw new IllegalStateException("Kernel not initialized");
|
106 |
| } |
107 |
| |
108 |
0
| public QedeqBo loadModule(final ModuleAddress moduleAddress) throws XmlFileExceptionList {
|
109 |
0
| throw new IllegalStateException("Kernel not initialized");
|
110 |
| } |
111 |
| |
112 |
0
| public QedeqBo loadModule(final QedeqBo module, final Specification spec)
|
113 |
| throws XmlFileExceptionList { |
114 |
0
| throw new IllegalStateException("Kernel not initialized");
|
115 |
| } |
116 |
| |
117 |
0
| public boolean loadAllModulesFromQedeq() {
|
118 |
0
| throw new IllegalStateException("Kernel not initialized");
|
119 |
| } |
120 |
| |
121 |
0
| public String[] getAllLoadedModules() {
|
122 |
0
| throw new IllegalStateException("Kernel not initialized");
|
123 |
| } |
124 |
| |
125 |
0
| public String getBufferDirectory() {
|
126 |
0
| throw new IllegalStateException("Kernel not initialized");
|
127 |
| } |
128 |
| |
129 |
0
| public String getGenerationDirectory() {
|
130 |
0
| throw new IllegalStateException("Kernel not initialized");
|
131 |
| } |
132 |
| |
133 |
0
| public ModuleProperties getModuleProperties(final String address) {
|
134 |
0
| throw new IllegalStateException("Kernel not initialized");
|
135 |
| } |
136 |
| |
137 |
| }; |
138 |
| |
139 |
| |
140 |
| private final KernelState readyState = new KernelState() { |
141 |
| |
142 |
0
| public void startup(final ModuleFactory moduleFactory) throws IOException {
|
143 |
| |
144 |
| } |
145 |
| |
146 |
0
| public boolean isReady() {
|
147 |
0
| return false;
|
148 |
| } |
149 |
| |
150 |
9
| public QedeqConfig getConfig() {
|
151 |
9
| return config;
|
152 |
| } |
153 |
| |
154 |
3
| public void shutdown() {
|
155 |
3
| try {
|
156 |
3
| config.setLoadedModules(moduleFactory.getAllLoadedModules());
|
157 |
3
| config.store();
|
158 |
3
| config = null;
|
159 |
3
| QedeqLog.getInstance().logMessage("Current config file successfully saved.");
|
160 |
| } catch (IOException e) { |
161 |
0
| Trace.trace(this, "shutdown()", e);
|
162 |
0
| QedeqLog.getInstance().logMessage("Saving current config file failed.");
|
163 |
| } |
164 |
3
| currentState = initialState;
|
165 |
3
| QedeqLog.getInstance().logMessage("QEDEQ Kernel closed.");
|
166 |
| } |
167 |
| |
168 |
0
| public void init() {
|
169 |
0
| throw new IllegalStateException("Kernel is already initialized");
|
170 |
| } |
171 |
| |
172 |
2
| public void removeAllModules() {
|
173 |
2
| moduleFactory.removeAllModules();
|
174 |
| } |
175 |
| |
176 |
0
| public void clearLocalBuffer() throws IOException {
|
177 |
0
| moduleFactory.clearLocalBuffer();
|
178 |
| } |
179 |
| |
180 |
22
| public QedeqBo loadModule(final String address) throws XmlFileExceptionList {
|
181 |
22
| return moduleFactory.loadModule(address);
|
182 |
| } |
183 |
| |
184 |
0
| public QedeqBo loadModule(final ModuleAddress moduleAddress) throws XmlFileExceptionList {
|
185 |
0
| return moduleFactory.loadModule(moduleAddress);
|
186 |
| } |
187 |
| |
188 |
0
| public QedeqBo loadModule(final QedeqBo module, final Specification spec)
|
189 |
| throws XmlFileExceptionList { |
190 |
0
| return moduleFactory.loadModule(module, spec);
|
191 |
| } |
192 |
| |
193 |
0
| public boolean loadAllModulesFromQedeq() {
|
194 |
0
| return moduleFactory.loadAllModulesFromQedeq();
|
195 |
| } |
196 |
| |
197 |
0
| public String[] getAllLoadedModules() {
|
198 |
0
| return moduleFactory.getAllLoadedModules();
|
199 |
| } |
200 |
| |
201 |
0
| public String getBufferDirectory() {
|
202 |
0
| return moduleFactory.getBufferDirectory();
|
203 |
| } |
204 |
| |
205 |
0
| public String getGenerationDirectory() {
|
206 |
0
| return moduleFactory.getGenerationDirectory();
|
207 |
| } |
208 |
| |
209 |
0
| public ModuleProperties getModuleProperties(final String address) {
|
210 |
0
| return moduleFactory.getModuleProperties(address);
|
211 |
| } |
212 |
| |
213 |
| }; |
214 |
| |
215 |
| |
216 |
| private KernelState currentState = initialState; |
217 |
| |
218 |
| |
219 |
| private QedeqConfig config; |
220 |
| |
221 |
| |
222 |
| private ModuleFactory moduleFactory; |
223 |
| |
224 |
| |
225 |
| |
226 |
| |
227 |
3
| private KernelContext() {
|
228 |
| |
229 |
| } |
230 |
| |
231 |
| |
232 |
| |
233 |
| |
234 |
| |
235 |
| |
236 |
460
| public static final KernelContext getInstance() {
|
237 |
460
| return INSTANCE;
|
238 |
| } |
239 |
| |
240 |
| |
241 |
| |
242 |
| |
243 |
| |
244 |
| |
245 |
0
| public final String getKernelVersion() {
|
246 |
0
| return KERNEL_VERSION;
|
247 |
| } |
248 |
| |
249 |
| |
250 |
| |
251 |
| |
252 |
| |
253 |
| |
254 |
419
| public final String getKernelVersionDirectory() {
|
255 |
419
| return KERNEL_VERSION_DIRECTORY;
|
256 |
| } |
257 |
| |
258 |
| |
259 |
| |
260 |
| |
261 |
| |
262 |
| |
263 |
5
| public final String getDescriptiveKernelVersion() {
|
264 |
5
| return DESCRIPTIVE_KERNEL_VERSION;
|
265 |
| } |
266 |
| |
267 |
| |
268 |
| |
269 |
| |
270 |
| |
271 |
| |
272 |
3
| public final String getMaximalRuleVersion() {
|
273 |
3
| return MAXIMAL_RULE_VERSION;
|
274 |
| } |
275 |
| |
276 |
| |
277 |
| |
278 |
| |
279 |
| |
280 |
| |
281 |
| |
282 |
0
| public final boolean isRuleVersionSupported(final String ruleVersion) {
|
283 |
0
| return MAXIMAL_RULE_VERSION.equals(ruleVersion);
|
284 |
| } |
285 |
| |
286 |
3
| public void startup(final ModuleFactory moduleFactory) throws IOException {
|
287 |
3
| currentState.startup(moduleFactory);
|
288 |
| } |
289 |
| |
290 |
0
| public boolean isReady() {
|
291 |
0
| return currentState.isReady();
|
292 |
| } |
293 |
| |
294 |
9
| public QedeqConfig getConfig() {
|
295 |
9
| return currentState.getConfig();
|
296 |
| } |
297 |
| |
298 |
3
| public void shutdown() {
|
299 |
3
| currentState.shutdown();
|
300 |
| } |
301 |
| |
302 |
0
| public void init() {
|
303 |
0
| currentState.init();
|
304 |
| } |
305 |
| |
306 |
2
| public void removeAllModules() {
|
307 |
2
| currentState.removeAllModules();
|
308 |
| } |
309 |
| |
310 |
0
| public void clearLocalBuffer() throws IOException {
|
311 |
0
| currentState.clearLocalBuffer();
|
312 |
| } |
313 |
| |
314 |
22
| public QedeqBo loadModule(final String address) throws XmlFileExceptionList {
|
315 |
22
| return currentState.loadModule(address);
|
316 |
| } |
317 |
| |
318 |
0
| public QedeqBo loadModule(final ModuleAddress moduleAddress) throws XmlFileExceptionList {
|
319 |
0
| return currentState.loadModule(moduleAddress);
|
320 |
| } |
321 |
| |
322 |
0
| public QedeqBo loadModule(final QedeqBo module, final Specification spec)
|
323 |
| throws XmlFileExceptionList { |
324 |
0
| return currentState.loadModule(module, spec);
|
325 |
| } |
326 |
| |
327 |
0
| public boolean loadAllModulesFromQedeq() {
|
328 |
0
| return currentState.loadAllModulesFromQedeq();
|
329 |
| } |
330 |
| |
331 |
0
| public String[] getAllLoadedModules() {
|
332 |
0
| return currentState.getAllLoadedModules();
|
333 |
| } |
334 |
| |
335 |
0
| public String getBufferDirectory() {
|
336 |
0
| return currentState.getBufferDirectory();
|
337 |
| } |
338 |
| |
339 |
0
| public String getGenerationDirectory() {
|
340 |
0
| return currentState.getGenerationDirectory();
|
341 |
| } |
342 |
| |
343 |
0
| public ModuleProperties getModuleProperties(final String address) {
|
344 |
0
| return currentState.getModuleProperties(address);
|
345 |
| } |
346 |
| |
347 |
| } |