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