|
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 |
| import java.net.URL; |
|
23 |
| |
|
24 |
| import org.qedeq.kernel.base.module.Specification; |
|
25 |
| import org.qedeq.kernel.bo.module.Kernel; |
|
26 |
| import org.qedeq.kernel.bo.module.KernelState; |
|
27 |
| import org.qedeq.kernel.bo.module.ModuleAddress; |
|
28 |
| import org.qedeq.kernel.bo.module.ModuleFactory; |
|
29 |
| import org.qedeq.kernel.bo.module.ModuleProperties; |
|
30 |
| import org.qedeq.kernel.bo.module.QedeqBo; |
|
31 |
| import org.qedeq.kernel.common.SourceFileExceptionList; |
|
32 |
| import org.qedeq.kernel.config.QedeqConfig; |
|
33 |
| import org.qedeq.kernel.log.QedeqLog; |
|
34 |
| import org.qedeq.kernel.trace.Trace; |
|
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.07"; |
|
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 |
28
| public void init(final ModuleFactory moduleFactory, final QedeqConfig qedeqConfig)
|
|
65 |
| throws IOException { |
|
66 |
28
| QedeqLog.getInstance().logMessage("This is "
|
|
67 |
| + KernelContext.getInstance().getDescriptiveKernelVersion()); |
|
68 |
28
| QedeqLog.getInstance().logMessage(" see \"http://www.qedeq.org\" for more "
|
|
69 |
| + "information"); |
|
70 |
28
| QedeqLog.getInstance().logMessage(" supports rules till version "
|
|
71 |
| + KernelContext.getInstance().getMaximalRuleVersion()); |
|
72 |
28
| config = qedeqConfig;
|
|
73 |
28
| KernelContext.this.moduleFactory = moduleFactory;
|
|
74 |
28
| currentState = initializedState;
|
|
75 |
| } |
|
76 |
| |
|
77 |
0
| public boolean isReady() {
|
|
78 |
0
| return false;
|
|
79 |
| } |
|
80 |
| |
|
81 |
0
| public QedeqConfig getConfig() {
|
|
82 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
83 |
| } |
|
84 |
| |
|
85 |
9
| public void shutdown() {
|
|
86 |
| } |
|
87 |
| |
|
88 |
0
| public void startup() {
|
|
89 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
90 |
| } |
|
91 |
| |
|
92 |
0
| public void removeAllModules() {
|
|
93 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
94 |
| } |
|
95 |
| |
|
96 |
0
| public void removeModule(final URL address) {
|
|
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 URL address) throws SourceFileExceptionList {
|
|
105 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
106 |
| } |
|
107 |
| |
|
108 |
0
| public QedeqBo loadModule(final ModuleAddress moduleAddress)
|
|
109 |
| throws SourceFileExceptionList { |
|
110 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
111 |
| } |
|
112 |
| |
|
113 |
0
| public QedeqBo loadModule(final QedeqBo module, final Specification spec)
|
|
114 |
| throws SourceFileExceptionList { |
|
115 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
116 |
| } |
|
117 |
| |
|
118 |
0
| public boolean loadAllModulesFromQedeq() {
|
|
119 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
120 |
| } |
|
121 |
| |
|
122 |
0
| public void loadRequiredModules(final URL address) {
|
|
123 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
124 |
| } |
|
125 |
| |
|
126 |
0
| public URL[] getAllLoadedModules() {
|
|
127 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
128 |
| } |
|
129 |
| |
|
130 |
0
| public File getBufferDirectory() {
|
|
131 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
132 |
| } |
|
133 |
| |
|
134 |
0
| public File getGenerationDirectory() {
|
|
135 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
136 |
| } |
|
137 |
| |
|
138 |
0
| public ModuleProperties getModuleProperties(final URL address) {
|
|
139 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
140 |
| } |
|
141 |
| |
|
142 |
0
| public String getLocalFilePath(final ModuleAddress address) {
|
|
143 |
0
| throw new IllegalStateException("Kernel not initialized");
|
|
144 |
| } |
|
145 |
| }; |
|
146 |
| |
|
147 |
| |
|
148 |
| private final KernelState initializedState = new KernelState() { |
|
149 |
| |
|
150 |
0
| public void init(final ModuleFactory moduleFactory, final QedeqConfig qedeqConfig)
|
|
151 |
| throws IOException { |
|
152 |
0
| throw new IllegalStateException("Kernel is already initialized");
|
|
153 |
| } |
|
154 |
| |
|
155 |
0
| public boolean isReady() {
|
|
156 |
0
| return false;
|
|
157 |
| } |
|
158 |
| |
|
159 |
60
| public QedeqConfig getConfig() {
|
|
160 |
60
| return config;
|
|
161 |
| } |
|
162 |
| |
|
163 |
0
| public void shutdown() {
|
|
164 |
0
| currentState = initialState;
|
|
165 |
0
| KernelContext.this.moduleFactory = null;
|
|
166 |
0
| QedeqLog.getInstance().logMessage("QEDEQ Kernel closed.");
|
|
167 |
| } |
|
168 |
| |
|
169 |
28
| public void startup() {
|
|
170 |
28
| moduleFactory.startup();
|
|
171 |
28
| currentState = readyState;
|
|
172 |
28
| QedeqLog.getInstance().logMessage("QEDEQ kernel opened.");
|
|
173 |
| } |
|
174 |
| |
|
175 |
0
| public void removeAllModules() {
|
|
176 |
0
| throw new IllegalStateException("Kernel not started");
|
|
177 |
| } |
|
178 |
| |
|
179 |
0
| public void removeModule(final URL address) {
|
|
180 |
0
| throw new IllegalStateException("Kernel not started");
|
|
181 |
| } |
|
182 |
| |
|
183 |
0
| public void clearLocalBuffer() throws IOException {
|
|
184 |
0
| throw new IllegalStateException("Kernel not started");
|
|
185 |
| } |
|
186 |
| |
|
187 |
0
| public QedeqBo loadModule(final URL address) throws SourceFileExceptionList {
|
|
188 |
0
| throw new IllegalStateException("Kernel not started");
|
|
189 |
| } |
|
190 |
| |
|
191 |
0
| public QedeqBo loadModule(final ModuleAddress moduleAddress)
|
|
192 |
| throws SourceFileExceptionList { |
|
193 |
0
| throw new IllegalStateException("Kernel not started");
|
|
194 |
| } |
|
195 |
| |
|
196 |
0
| public QedeqBo loadModule(final QedeqBo module, final Specification spec)
|
|
197 |
| throws SourceFileExceptionList { |
|
198 |
0
| throw new IllegalStateException("Kernel not started");
|
|
199 |
| } |
|
200 |
| |
|
201 |
0
| public boolean loadAllModulesFromQedeq() {
|
|
202 |
0
| throw new IllegalStateException("Kernel not started");
|
|
203 |
| } |
|
204 |
| |
|
205 |
0
| public void loadRequiredModules(final URL address) {
|
|
206 |
0
| throw new IllegalStateException("Kernel not started");
|
|
207 |
| } |
|
208 |
| |
|
209 |
0
| public URL[] getAllLoadedModules() {
|
|
210 |
0
| throw new IllegalStateException("Kernel not started");
|
|
211 |
| } |
|
212 |
| |
|
213 |
0
| public File getBufferDirectory() {
|
|
214 |
0
| throw new IllegalStateException("Kernel not started");
|
|
215 |
| } |
|
216 |
| |
|
217 |
0
| public File getGenerationDirectory() {
|
|
218 |
0
| throw new IllegalStateException("Kernel not started");
|
|
219 |
| } |
|
220 |
| |
|
221 |
0
| public ModuleProperties getModuleProperties(final URL address) {
|
|
222 |
0
| throw new IllegalStateException("Kernel not started");
|
|
223 |
| } |
|
224 |
| |
|
225 |
0
| public String getLocalFilePath(final ModuleAddress address) {
|
|
226 |
0
| throw new IllegalStateException("Kernel not started");
|
|
227 |
| } |
|
228 |
| }; |
|
229 |
| |
|
230 |
| |
|
231 |
| private final KernelState readyState = new KernelState() { |
|
232 |
| |
|
233 |
0
| public void init(final ModuleFactory moduleFactory, final QedeqConfig qedeqConfig)
|
|
234 |
| throws IOException { |
|
235 |
| |
|
236 |
| } |
|
237 |
| |
|
238 |
0
| public boolean isReady() {
|
|
239 |
0
| return false;
|
|
240 |
| } |
|
241 |
| |
|
242 |
997
| public QedeqConfig getConfig() {
|
|
243 |
997
| return config;
|
|
244 |
| } |
|
245 |
| |
|
246 |
28
| public void shutdown() {
|
|
247 |
28
| try {
|
|
248 |
28
| config.setLoadedModules(moduleFactory.getAllLoadedModules());
|
|
249 |
28
| config.store();
|
|
250 |
28
| QedeqLog.getInstance().logMessage("Current config file successfully saved.");
|
|
251 |
| } catch (IOException e) { |
|
252 |
0
| Trace.trace(this, "shutdown()", e);
|
|
253 |
0
| QedeqLog.getInstance().logMessage("Saving current config file failed.");
|
|
254 |
| } |
|
255 |
28
| currentState = initialState;
|
|
256 |
28
| KernelContext.this.moduleFactory = null;
|
|
257 |
28
| QedeqLog.getInstance().logMessage("QEDEQ Kernel closed.");
|
|
258 |
| } |
|
259 |
| |
|
260 |
0
| public void startup() {
|
|
261 |
0
| throw new IllegalStateException("Kernel is already initialized");
|
|
262 |
| } |
|
263 |
| |
|
264 |
0
| public void removeAllModules() {
|
|
265 |
0
| moduleFactory.removeAllModules();
|
|
266 |
| } |
|
267 |
| |
|
268 |
3
| public void removeModule(final URL address) throws IOException {
|
|
269 |
3
| moduleFactory.removeModule(address);
|
|
270 |
| } |
|
271 |
| |
|
272 |
4
| public void clearLocalBuffer() throws IOException {
|
|
273 |
4
| moduleFactory.clearLocalBuffer();
|
|
274 |
| } |
|
275 |
| |
|
276 |
2435
| public QedeqBo loadModule(final URL address) throws SourceFileExceptionList {
|
|
277 |
2435
| return moduleFactory.loadModule(address);
|
|
278 |
| } |
|
279 |
| |
|
280 |
0
| public QedeqBo loadModule(final ModuleAddress moduleAddress)
|
|
281 |
| throws SourceFileExceptionList { |
|
282 |
0
| return moduleFactory.loadModule(moduleAddress);
|
|
283 |
| } |
|
284 |
| |
|
285 |
2543
| public QedeqBo loadModule(final QedeqBo module, final Specification spec)
|
|
286 |
| throws SourceFileExceptionList { |
|
287 |
2543
| return moduleFactory.loadModule(module, spec);
|
|
288 |
| } |
|
289 |
| |
|
290 |
3
| public boolean loadAllModulesFromQedeq() {
|
|
291 |
3
| return moduleFactory.loadAllModulesFromQedeq();
|
|
292 |
| } |
|
293 |
| |
|
294 |
9
| public void loadRequiredModules(final URL address) throws SourceFileExceptionList {
|
|
295 |
9
| moduleFactory.loadRequiredModules(address);
|
|
296 |
| } |
|
297 |
| |
|
298 |
0
| public URL[] getAllLoadedModules() {
|
|
299 |
0
| return moduleFactory.getAllLoadedModules();
|
|
300 |
| } |
|
301 |
| |
|
302 |
458
| public File getBufferDirectory() {
|
|
303 |
458
| return moduleFactory.getBufferDirectory();
|
|
304 |
| } |
|
305 |
| |
|
306 |
0
| public File getGenerationDirectory() {
|
|
307 |
0
| return moduleFactory.getGenerationDirectory();
|
|
308 |
| } |
|
309 |
| |
|
310 |
2581
| public ModuleProperties getModuleProperties(final URL address) {
|
|
311 |
2581
| return moduleFactory.getModuleProperties(address);
|
|
312 |
| } |
|
313 |
| |
|
314 |
25717
| public String getLocalFilePath(final ModuleAddress address) {
|
|
315 |
25717
| return moduleFactory.getLocalFilePath(address);
|
|
316 |
| } |
|
317 |
| |
|
318 |
| }; |
|
319 |
| |
|
320 |
| |
|
321 |
| private KernelState currentState = initialState; |
|
322 |
| |
|
323 |
| |
|
324 |
| private QedeqConfig config; |
|
325 |
| |
|
326 |
| |
|
327 |
| private ModuleFactory moduleFactory; |
|
328 |
| |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
6
| private KernelContext() {
|
|
333 |
| |
|
334 |
| } |
|
335 |
| |
|
336 |
| |
|
337 |
| |
|
338 |
| |
|
339 |
| |
|
340 |
| |
|
341 |
11737
| public static final KernelContext getInstance() {
|
|
342 |
11737
| return INSTANCE;
|
|
343 |
| } |
|
344 |
| |
|
345 |
| |
|
346 |
| |
|
347 |
| |
|
348 |
| |
|
349 |
| |
|
350 |
0
| public final String getKernelVersion() {
|
|
351 |
0
| return KERNEL_VERSION;
|
|
352 |
| } |
|
353 |
| |
|
354 |
| |
|
355 |
| |
|
356 |
| |
|
357 |
| |
|
358 |
| |
|
359 |
1349
| public final String getKernelVersionDirectory() {
|
|
360 |
1349
| return KERNEL_VERSION_DIRECTORY;
|
|
361 |
| } |
|
362 |
| |
|
363 |
| |
|
364 |
| |
|
365 |
| |
|
366 |
| |
|
367 |
| |
|
368 |
34
| public final String getDescriptiveKernelVersion() {
|
|
369 |
34
| return DESCRIPTIVE_KERNEL_VERSION;
|
|
370 |
| } |
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
| |
|
377 |
28
| public final String getMaximalRuleVersion() {
|
|
378 |
28
| return MAXIMAL_RULE_VERSION;
|
|
379 |
| } |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
| |
|
387 |
0
| public final boolean isRuleVersionSupported(final String ruleVersion) {
|
|
388 |
0
| return MAXIMAL_RULE_VERSION.equals(ruleVersion);
|
|
389 |
| } |
|
390 |
| |
|
391 |
28
| public void init(final ModuleFactory moduleFactory, final QedeqConfig qedeqConfig)
|
|
392 |
| throws IOException { |
|
393 |
28
| currentState.init(moduleFactory, qedeqConfig);
|
|
394 |
| } |
|
395 |
| |
|
396 |
0
| public boolean isReady() {
|
|
397 |
0
| return currentState.isReady();
|
|
398 |
| } |
|
399 |
| |
|
400 |
1057
| public QedeqConfig getConfig() {
|
|
401 |
1057
| return currentState.getConfig();
|
|
402 |
| } |
|
403 |
| |
|
404 |
37
| public void shutdown() {
|
|
405 |
37
| currentState.shutdown();
|
|
406 |
| } |
|
407 |
| |
|
408 |
28
| public void startup() {
|
|
409 |
28
| currentState.startup();
|
|
410 |
| } |
|
411 |
| |
|
412 |
0
| public void removeAllModules() {
|
|
413 |
0
| currentState.removeAllModules();
|
|
414 |
| } |
|
415 |
| |
|
416 |
3
| public void removeModule(final URL address) throws IOException {
|
|
417 |
3
| currentState.removeModule(address);
|
|
418 |
| } |
|
419 |
| |
|
420 |
4
| public void clearLocalBuffer() throws IOException {
|
|
421 |
4
| currentState.clearLocalBuffer();
|
|
422 |
| } |
|
423 |
| |
|
424 |
2435
| public QedeqBo loadModule(final URL address) throws SourceFileExceptionList {
|
|
425 |
2435
| return currentState.loadModule(address);
|
|
426 |
| } |
|
427 |
| |
|
428 |
0
| public QedeqBo loadModule(final ModuleAddress moduleAddress) throws SourceFileExceptionList {
|
|
429 |
0
| return currentState.loadModule(moduleAddress);
|
|
430 |
| } |
|
431 |
| |
|
432 |
2543
| public QedeqBo loadModule(final QedeqBo module, final Specification spec)
|
|
433 |
| throws SourceFileExceptionList { |
|
434 |
2543
| return currentState.loadModule(module, spec);
|
|
435 |
| } |
|
436 |
| |
|
437 |
3
| public boolean loadAllModulesFromQedeq() {
|
|
438 |
3
| return currentState.loadAllModulesFromQedeq();
|
|
439 |
| } |
|
440 |
| |
|
441 |
9
| public void loadRequiredModules(final URL address) throws SourceFileExceptionList {
|
|
442 |
9
| currentState.loadRequiredModules(address);
|
|
443 |
| } |
|
444 |
| |
|
445 |
0
| public URL[] getAllLoadedModules() {
|
|
446 |
0
| return currentState.getAllLoadedModules();
|
|
447 |
| } |
|
448 |
| |
|
449 |
458
| public File getBufferDirectory() {
|
|
450 |
458
| return currentState.getBufferDirectory();
|
|
451 |
| } |
|
452 |
| |
|
453 |
0
| public File getGenerationDirectory() {
|
|
454 |
0
| return currentState.getGenerationDirectory();
|
|
455 |
| } |
|
456 |
| |
|
457 |
2581
| public ModuleProperties getModuleProperties(final URL address) {
|
|
458 |
2581
| return currentState.getModuleProperties(address);
|
|
459 |
| } |
|
460 |
| |
|
461 |
25717
| public String getLocalFilePath(final ModuleAddress address) {
|
|
462 |
25717
| return currentState.getLocalFilePath(address);
|
|
463 |
| } |
|
464 |
| |
|
465 |
| } |