|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.bo.control; |
|
19 |
| |
|
20 |
| import java.io.File; |
|
21 |
| import java.io.FileNotFoundException; |
|
22 |
| import java.io.FileOutputStream; |
|
23 |
| import java.io.IOException; |
|
24 |
| import java.io.InputStream; |
|
25 |
| import java.io.UnsupportedEncodingException; |
|
26 |
| import java.net.MalformedURLException; |
|
27 |
| import java.net.URL; |
|
28 |
| import java.net.URLConnection; |
|
29 |
| import java.net.URLEncoder; |
|
30 |
| import java.util.ArrayList; |
|
31 |
| import java.util.List; |
|
32 |
| |
|
33 |
| import org.qedeq.kernel.base.module.Qedeq; |
|
34 |
| import org.qedeq.kernel.base.module.Specification; |
|
35 |
| import org.qedeq.kernel.bo.load.QedeqVoBuilder; |
|
36 |
| import org.qedeq.kernel.bo.module.KernelProperties; |
|
37 |
| import org.qedeq.kernel.bo.module.KernelServices; |
|
38 |
| import org.qedeq.kernel.common.DefaultSourceFileExceptionList; |
|
39 |
| import org.qedeq.kernel.common.DependencyState; |
|
40 |
| import org.qedeq.kernel.common.LoadingState; |
|
41 |
| import org.qedeq.kernel.common.LogicalState; |
|
42 |
| import org.qedeq.kernel.common.ModuleAddress; |
|
43 |
| import org.qedeq.kernel.common.ModuleDataException; |
|
44 |
| import org.qedeq.kernel.common.QedeqBo; |
|
45 |
| import org.qedeq.kernel.common.SourceArea; |
|
46 |
| import org.qedeq.kernel.common.SourceFileException; |
|
47 |
| import org.qedeq.kernel.common.SourceFileExceptionList; |
|
48 |
| import org.qedeq.kernel.dto.module.QedeqVo; |
|
49 |
| import org.qedeq.kernel.log.QedeqLog; |
|
50 |
| import org.qedeq.kernel.trace.Trace; |
|
51 |
| import org.qedeq.kernel.utility.IoUtility; |
|
52 |
| import org.qedeq.kernel.utility.StringUtility; |
|
53 |
| import org.qedeq.kernel.utility.TextInput; |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| public class DefaultInternalKernelServices implements KernelServices, InternalKernelServices { |
|
63 |
| |
|
64 |
| |
|
65 |
| private static final Class CLASS = DefaultInternalKernelServices.class; |
|
66 |
| |
|
67 |
| |
|
68 |
| private final String monitor = ""; |
|
69 |
| |
|
70 |
| |
|
71 |
| private final String syncToken = ""; |
|
72 |
| |
|
73 |
| |
|
74 |
| private volatile int processCounter = 0; |
|
75 |
| |
|
76 |
| |
|
77 |
| private final KernelQedeqBoPool modules; |
|
78 |
| |
|
79 |
| |
|
80 |
| private final KernelProperties kernel; |
|
81 |
| |
|
82 |
| |
|
83 |
| private final ModuleLoader loader; |
|
84 |
| |
|
85 |
| |
|
86 |
| private boolean validate = true; |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
31
| public DefaultInternalKernelServices(final KernelProperties kernel, final ModuleLoader loader) {
|
|
95 |
31
| modules = new KernelQedeqBoPool();
|
|
96 |
31
| this.kernel = kernel;
|
|
97 |
31
| this.loader = loader;
|
|
98 |
31
| loader.setServices(this);
|
|
99 |
| } |
|
100 |
| |
|
101 |
31
| public void startup() {
|
|
102 |
31
| if (kernel.getConfig().isAutoReloadLastSessionChecked()) {
|
|
103 |
0
| autoReloadLastSessionChecked();
|
|
104 |
| } |
|
105 |
| } |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
0
| public void autoReloadLastSessionChecked() {
|
|
111 |
0
| if (kernel.getConfig().isAutoReloadLastSessionChecked()) {
|
|
112 |
0
| final Thread thread = new Thread() {
|
|
113 |
0
| public void run() {
|
|
114 |
0
| final String method = "start()";
|
|
115 |
0
| try {
|
|
116 |
0
| Trace.begin(CLASS, this, method);
|
|
117 |
0
| QedeqLog.getInstance().logMessage(
|
|
118 |
| "Trying to load previously successfully loaded modules."); |
|
119 |
0
| final int number = kernel.getConfig().getPreviouslyCheckedModules().length;
|
|
120 |
0
| if (loadPreviouslySuccessfullyLoadedModules()) {
|
|
121 |
0
| QedeqLog.getInstance().logMessage(
|
|
122 |
| "Loading of " + number + " previously successfully loaded module" |
|
123 |
0
| + (number != 1 ? "s" : "") + " successfully done.");
|
|
124 |
| } else { |
|
125 |
0
| QedeqLog.getInstance().logMessage(
|
|
126 |
| "Loading of all previously successfully checked modules failed. " |
|
127 |
0
| + number + " module" + (number != 1 ? "s" : "") + " were tried.");
|
|
128 |
| } |
|
129 |
| } catch (Exception e) { |
|
130 |
0
| Trace.trace(CLASS, this, method, e);
|
|
131 |
| } finally { |
|
132 |
0
| Trace.begin(CLASS, this, method);
|
|
133 |
| } |
|
134 |
| } |
|
135 |
| }; |
|
136 |
0
| thread.setDaemon(true);
|
|
137 |
0
| thread.start();
|
|
138 |
| } |
|
139 |
| } |
|
140 |
| |
|
141 |
1
| public void removeAllModules() {
|
|
142 |
1
| do {
|
|
143 |
1
| synchronized (syncToken) {
|
|
144 |
1
| if (processCounter == 0) {
|
|
145 |
1
| getModules().removeAllModules();
|
|
146 |
1
| return;
|
|
147 |
| } |
|
148 |
| } |
|
149 |
0
| synchronized (monitor) {
|
|
150 |
0
| try {
|
|
151 |
0
| monitor.wait(10000);
|
|
152 |
| } catch (InterruptedException e) { |
|
153 |
| } |
|
154 |
| } |
|
155 |
| } while (true); |
|
156 |
| |
|
157 |
| } |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
6
| public void removeModule(final ModuleAddress address) {
|
|
165 |
6
| final QedeqBo prop = getQedeqBo(address);
|
|
166 |
6
| if (prop != null) {
|
|
167 |
6
| removeModule(getKernelQedeqBo(address));
|
|
168 |
6
| if (validate) {
|
|
169 |
6
| modules.validateDependencies();
|
|
170 |
| } |
|
171 |
| } |
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
6
| public void removeModule(final KernelQedeqBo prop) {
|
|
183 |
6
| do {
|
|
184 |
6
| synchronized (syncToken) {
|
|
185 |
6
| if (processCounter == 0) {
|
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
6
| prop.delete();
|
|
191 |
6
| getModules().removeModule(prop);
|
|
192 |
6
| return;
|
|
193 |
| } |
|
194 |
| } |
|
195 |
0
| synchronized (monitor) {
|
|
196 |
0
| try {
|
|
197 |
0
| this.monitor.wait(10000);
|
|
198 |
| } catch (InterruptedException e) { |
|
199 |
| } |
|
200 |
| } |
|
201 |
| } while (true); |
|
202 |
| |
|
203 |
| } |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
1
| public void clearLocalBuffer()
|
|
211 |
| throws IOException { |
|
212 |
1
| removeAllModules();
|
|
213 |
1
| final File bufferDir = getBufferDirectory().getCanonicalFile();
|
|
214 |
1
| if (bufferDir.exists() && !IoUtility.deleteDir(bufferDir, false)) {
|
|
215 |
0
| throw new IOException("buffer could not be deleted: " + bufferDir);
|
|
216 |
| } |
|
217 |
| } |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
206
| public QedeqBo loadModule(final ModuleAddress address) throws SourceFileExceptionList {
|
|
227 |
206
| final String method = "loadModule(ModuleAddress)";
|
|
228 |
206
| processInc();
|
|
229 |
206
| try {
|
|
230 |
206
| final KernelQedeqBo prop = getModules().getKernelQedeqBo(address);
|
|
231 |
206
| synchronized (prop) {
|
|
232 |
206
| if (prop.isLoaded()) {
|
|
233 |
117
| return prop;
|
|
234 |
| } |
|
235 |
| |
|
236 |
| |
|
237 |
89
| try {
|
|
238 |
89
| loadLocalModule(prop);
|
|
239 |
49
| return prop;
|
|
240 |
| } catch (ModuleFileNotFoundException e) { |
|
241 |
| |
|
242 |
| } catch (SourceFileExceptionList e) { |
|
243 |
19
| Trace.trace(CLASS, this, method, e);
|
|
244 |
19
| QedeqLog.getInstance().logFailureState("Loading of module failed!",
|
|
245 |
| address.getURL(), e.toString()); |
|
246 |
19
| throw e;
|
|
247 |
| } |
|
248 |
| |
|
249 |
| |
|
250 |
21
| try {
|
|
251 |
21
| makeLocalCopy(prop);
|
|
252 |
| } catch (IOException e) { |
|
253 |
1
| Trace.trace(CLASS, this, method, e);
|
|
254 |
1
| QedeqLog.getInstance().logFailureState("Loading of module failed!",
|
|
255 |
| address.getURL(), e.toString()); |
|
256 |
1
| throw createSourceFileExceptionList(e);
|
|
257 |
| } |
|
258 |
20
| try {
|
|
259 |
20
| loadLocalModule(prop);
|
|
260 |
| } catch (ModuleFileNotFoundException e) { |
|
261 |
| |
|
262 |
| |
|
263 |
3
| Trace.trace(CLASS, this, method, e);
|
|
264 |
3
| QedeqLog.getInstance().logFailureState("Loading of module failed!",
|
|
265 |
| address.getURL(), e.getMessage()); |
|
266 |
| |
|
267 |
3
| final SourceFileException sf = new SourceFileException(1021,
|
|
268 |
| "Loading of module \"" + address.getURL() + "\"failed", |
|
269 |
| e, (SourceArea) null, (SourceArea) null); |
|
270 |
3
| final DefaultSourceFileExceptionList sfl = new DefaultSourceFileExceptionList(
|
|
271 |
| sf); |
|
272 |
3
| throw sfl;
|
|
273 |
| } catch (SourceFileExceptionList e) { |
|
274 |
6
| Trace.trace(CLASS, this, method, e);
|
|
275 |
6
| QedeqLog.getInstance().logFailureState("Loading of module failed!",
|
|
276 |
| address.getURL(), e.getMessage()); |
|
277 |
6
| throw e;
|
|
278 |
| } |
|
279 |
11
| return prop;
|
|
280 |
| } |
|
281 |
| } finally { |
|
282 |
206
| processDec();
|
|
283 |
| } |
|
284 |
| } |
|
285 |
| |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
187
| private void loadLocalModule(final KernelQedeqBo prop)
|
|
294 |
| throws ModuleFileNotFoundException, SourceFileExceptionList { |
|
295 |
187
| final String method = "loadLocalModule(KernelQedeqBo)";
|
|
296 |
187
| final File localFile = getLocalFilePath(prop.getModuleAddress());
|
|
297 |
187
| prop.setLoader(loader);
|
|
298 |
187
| final Qedeq qedeq = loader.loadLocalModule(prop, localFile);
|
|
299 |
135
| prop.setLoadingProgressState(LoadingState.STATE_LOADING_INTO_MEMORY);
|
|
300 |
135
| QedeqVo vo = null;
|
|
301 |
135
| try {
|
|
302 |
135
| vo = QedeqVoBuilder.createQedeq(prop.getModuleAddress(), qedeq);
|
|
303 |
| } catch (ModuleDataException e) { |
|
304 |
0
| Trace.trace(CLASS, this, method, e);
|
|
305 |
0
| final SourceFileExceptionList xl
|
|
306 |
| = prop.createSourceFileExceptionList(e, qedeq); |
|
307 |
0
| prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl);
|
|
308 |
0
| throw xl;
|
|
309 |
| } |
|
310 |
135
| prop.setQedeqVo(vo);
|
|
311 |
135
| ModuleLabelsCreator moduleNodesCreator = new ModuleLabelsCreator(prop);
|
|
312 |
135
| try {
|
|
313 |
135
| prop.setLoaded(vo, moduleNodesCreator.createLabels());
|
|
314 |
| } catch (SourceFileExceptionList sfl) { |
|
315 |
5
| prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, sfl);
|
|
316 |
5
| throw sfl;
|
|
317 |
| } |
|
318 |
| } |
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
| |
|
324 |
| |
|
325 |
| |
|
326 |
| |
|
327 |
| |
|
328 |
162
| public KernelQedeqBo loadModule(final ModuleAddress parent,
|
|
329 |
| final Specification spec) throws SourceFileExceptionList { |
|
330 |
| |
|
331 |
162
| final String method = "loadModule(Module, Specification)";
|
|
332 |
162
| Trace.begin(CLASS, this, method);
|
|
333 |
162
| Trace.trace(CLASS, this, method, spec);
|
|
334 |
162
| processInc();
|
|
335 |
162
| try {
|
|
336 |
162
| final ModuleAddress[] modulePaths;
|
|
337 |
162
| try {
|
|
338 |
162
| modulePaths = DefaultModuleAddress.getModulePaths(parent, spec);
|
|
339 |
| } catch (IOException e) { |
|
340 |
0
| Trace.trace(CLASS, this, method, e);
|
|
341 |
0
| throw createSourceFileExceptionList(e);
|
|
342 |
| } |
|
343 |
| |
|
344 |
162
| for (int i = 0; i < modulePaths.length; i++) {
|
|
345 |
185
| final KernelQedeqBo prop
|
|
346 |
| = getModules().getKernelQedeqBo(modulePaths[i]); |
|
347 |
185
| synchronized (prop) {
|
|
348 |
185
| if (prop.isLoaded()) {
|
|
349 |
91
| return (prop);
|
|
350 |
| } |
|
351 |
| } |
|
352 |
| } |
|
353 |
| |
|
354 |
| |
|
355 |
71
| Trace.trace(CLASS, this, method, "searching file buffer");
|
|
356 |
71
| for (int i = 0; i < modulePaths.length; i++) {
|
|
357 |
75
| try {
|
|
358 |
75
| final KernelQedeqBo prop
|
|
359 |
| = getModules().getKernelQedeqBo(modulePaths[i]); |
|
360 |
75
| Trace.trace(CLASS, this, method, "synchronizing at prop=" + prop);
|
|
361 |
75
| synchronized (prop) {
|
|
362 |
75
| loadLocalModule(prop);
|
|
363 |
68
| return prop;
|
|
364 |
| } |
|
365 |
| } catch (Exception e) { |
|
366 |
| |
|
367 |
| } |
|
368 |
| } |
|
369 |
| |
|
370 |
| |
|
371 |
3
| SourceFileExceptionList sfl = null;
|
|
372 |
| |
|
373 |
| |
|
374 |
3
| for (int i = 0; i < modulePaths.length; i++) {
|
|
375 |
3
| KernelQedeqBo prop = null;
|
|
376 |
3
| try {
|
|
377 |
3
| prop = getModules().getKernelQedeqBo(modulePaths[i]);
|
|
378 |
3
| synchronized (prop) {
|
|
379 |
3
| makeLocalCopy(prop);
|
|
380 |
3
| loadLocalModule(prop);
|
|
381 |
2
| return prop;
|
|
382 |
| } |
|
383 |
| } catch (IOException e) { |
|
384 |
0
| QedeqLog.getInstance().logFailureState("Loading of module failed!",
|
|
385 |
| modulePaths[i].getURL(), e.toString()); |
|
386 |
0
| Trace.trace(CLASS, this, method, e);
|
|
387 |
0
| sfl = createSourceFileExceptionList(e);
|
|
388 |
| |
|
389 |
0
| if (i + 1 < modulePaths.length) {
|
|
390 |
0
| prop.delete();
|
|
391 |
0
| getModules().removeModule(prop);
|
|
392 |
| } |
|
393 |
| } catch (ModuleFileNotFoundException e) { |
|
394 |
1
| Trace.trace(CLASS, this, method, e);
|
|
395 |
1
| QedeqLog.getInstance().logFailureState("Loading of module failed!",
|
|
396 |
| modulePaths[i].getURL(), e.getMessage()); |
|
397 |
1
| sfl = createSourcelFileExceptionList(e);
|
|
398 |
| |
|
399 |
1
| if (i + 1 < modulePaths.length) {
|
|
400 |
0
| prop.delete();
|
|
401 |
0
| getModules().removeModule(prop);
|
|
402 |
| } |
|
403 |
| } |
|
404 |
| } |
|
405 |
| |
|
406 |
1
| throw sfl;
|
|
407 |
| } finally { |
|
408 |
162
| processDec();
|
|
409 |
162
| Trace.end(CLASS, this, method);
|
|
410 |
| } |
|
411 |
| } |
|
412 |
| |
|
413 |
31
| public ModuleAddress[] getAllLoadedModules() {
|
|
414 |
31
| return getModules().getAllLoadedModules();
|
|
415 |
| } |
|
416 |
| |
|
417 |
| |
|
418 |
60
| public void loadRequiredModules(final ModuleAddress address) throws SourceFileExceptionList {
|
|
419 |
60
| final KernelQedeqBo prop = (KernelQedeqBo) loadModule(address);
|
|
420 |
60
| LoadRequiredModules.loadRequired(prop, this);
|
|
421 |
| } |
|
422 |
| |
|
423 |
| |
|
424 |
| |
|
425 |
| |
|
426 |
| |
|
427 |
| |
|
428 |
0
| public boolean loadPreviouslySuccessfullyLoadedModules() {
|
|
429 |
0
| processInc();
|
|
430 |
0
| try {
|
|
431 |
0
| final String[] list = kernel.getConfig().getPreviouslyCheckedModules();
|
|
432 |
0
| boolean errors = false;
|
|
433 |
0
| for (int i = 0; i < list.length; i++) {
|
|
434 |
0
| try {
|
|
435 |
0
| final ModuleAddress address = getModuleAddress(list[i]);
|
|
436 |
0
| loadModule(address);
|
|
437 |
| } catch (SourceFileExceptionList e) { |
|
438 |
0
| errors = true;
|
|
439 |
| } catch (IOException e) { |
|
440 |
0
| Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules",
|
|
441 |
| "internal error: " |
|
442 |
| + "saved URLs are malformed", e); |
|
443 |
0
| errors = true;
|
|
444 |
| } |
|
445 |
| } |
|
446 |
0
| return !errors;
|
|
447 |
| } finally { |
|
448 |
0
| processDec();
|
|
449 |
| } |
|
450 |
| } |
|
451 |
| |
|
452 |
| |
|
453 |
3
| public boolean loadAllModulesFromQedeq() {
|
|
454 |
3
| processInc();
|
|
455 |
3
| try {
|
|
456 |
3
| final String prefix = "http://qedeq.org/"
|
|
457 |
| + kernel.getKernelVersionDirectory() + "/"; |
|
458 |
3
| final String[] list = new String[] {
|
|
459 |
| prefix + "doc/math/qedeq_logic_v1.xml", |
|
460 |
| prefix + "doc/math/qedeq_set_theory_v1.xml", |
|
461 |
| prefix + "doc/project/qedeq_basic_concept.xml", |
|
462 |
| prefix + "doc/project/qedeq_logic_language.xml", |
|
463 |
| prefix + "sample/qedeq_sample1.xml", |
|
464 |
| prefix + "sample/qedeq_error_sample_00.xml", |
|
465 |
| prefix + "sample/qedeq_error_sample_01.xml", |
|
466 |
| prefix + "sample/qedeq_error_sample_02.xml", |
|
467 |
| prefix + "sample/qedeq_error_sample_03.xml", |
|
468 |
| prefix + "sample/qedeq_error_sample_04.xml", |
|
469 |
| prefix + "sample/qedeq_sample2_error.xml", |
|
470 |
| prefix + "sample/qedeq_sample3_error.xml", |
|
471 |
| prefix + "sample/qedeq_sample4_error.xml", |
|
472 |
| prefix + "sample/qedeq_sample5_error.xml", |
|
473 |
| prefix + "sample/qedeq_sample6_error.xml", |
|
474 |
| prefix + "sample/qedeq_sample7_error.xml", |
|
475 |
| }; |
|
476 |
3
| boolean errors = false;
|
|
477 |
3
| for (int i = 0; i < list.length; i++) {
|
|
478 |
48
| try {
|
|
479 |
48
| final ModuleAddress address = getModuleAddress(list[i]);
|
|
480 |
48
| loadModule(address);
|
|
481 |
| } catch (SourceFileExceptionList e) { |
|
482 |
15
| errors = true;
|
|
483 |
| } catch (IOException e) { |
|
484 |
0
| Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules",
|
|
485 |
| "internal error: " |
|
486 |
| + "saved URLs are malformed", e); |
|
487 |
0
| errors = true;
|
|
488 |
| } |
|
489 |
| } |
|
490 |
3
| return !errors;
|
|
491 |
| } finally { |
|
492 |
3
| processDec();
|
|
493 |
| } |
|
494 |
| } |
|
495 |
| |
|
496 |
| |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
| |
|
502 |
24
| private synchronized void makeLocalCopy(
|
|
503 |
| final KernelQedeqBo prop) |
|
504 |
| throws IOException { |
|
505 |
24
| final String method = "makeLocalCopy";
|
|
506 |
24
| Trace.begin(CLASS, this, method);
|
|
507 |
| |
|
508 |
24
| prop.setLoadingProgressState(LoadingState.STATE_LOADING_FROM_WEB);
|
|
509 |
| |
|
510 |
24
| if (prop.getModuleAddress().isFileAddress()) {
|
|
511 |
4
| return;
|
|
512 |
| } |
|
513 |
20
| FileOutputStream out = null;
|
|
514 |
20
| InputStream in = null;
|
|
515 |
20
| final File f = getLocalFilePath(prop.getModuleAddress());
|
|
516 |
20
| try {
|
|
517 |
20
| final URLConnection connection = prop.getUrl().openConnection();
|
|
518 |
20
| in = connection.getInputStream();
|
|
519 |
19
| final int maximum = connection.getContentLength();
|
|
520 |
19
| if (!prop.getUrl().equals(connection.getURL())) {
|
|
521 |
0
| throw new FileNotFoundException("\"" + prop.getUrl()
|
|
522 |
| + "\" was substituted by " + "\"" + connection.getURL() |
|
523 |
| + "\" from server"); |
|
524 |
| } |
|
525 |
19
| IoUtility.createNecessaryDirectories(f);
|
|
526 |
19
| out = new FileOutputStream(f);
|
|
527 |
19
| final byte[] buffer = new byte[4096];
|
|
528 |
19
| int bytesRead;
|
|
529 |
19
| int position = 0;
|
|
530 |
| |
|
531 |
?
| while ((bytesRead = in.read(buffer)) != -1) {
|
|
532 |
264
| position += bytesRead;
|
|
533 |
264
| out.write(buffer, 0, bytesRead);
|
|
534 |
264
| int completeness = (int) (position * 100 / maximum);
|
|
535 |
264
| if (completeness < 0) {
|
|
536 |
0
| completeness = 0;
|
|
537 |
| } |
|
538 |
264
| if (completeness > 100) {
|
|
539 |
0
| completeness = 100;
|
|
540 |
| } |
|
541 |
264
| prop.setLoadingCompleteness(completeness);
|
|
542 |
| } |
|
543 |
19
| prop.setLoadingCompleteness(100);
|
|
544 |
| } catch (IOException e) { |
|
545 |
1
| Trace.trace(CLASS, this, method, e);
|
|
546 |
1
| try {
|
|
547 |
1
| out.close();
|
|
548 |
| } catch (Exception ex) { |
|
549 |
| } |
|
550 |
1
| try {
|
|
551 |
1
| f.delete();
|
|
552 |
| } catch (Exception ex) { |
|
553 |
0
| Trace.trace(CLASS, this, method, ex);
|
|
554 |
| } |
|
555 |
1
| prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_WEB_FAILED,
|
|
556 |
| new DefaultSourceFileExceptionList(e)); |
|
557 |
1
| Trace.trace(CLASS, this, method, "Couldn't access " + prop.getUrl());
|
|
558 |
1
| throw e;
|
|
559 |
| } finally { |
|
560 |
20
| try {
|
|
561 |
20
| out.close();
|
|
562 |
| } catch (Exception e) { |
|
563 |
| }; |
|
564 |
20
| try {
|
|
565 |
20
| in.close();
|
|
566 |
| } catch (Exception e) { |
|
567 |
| }; |
|
568 |
20
| Trace.end(CLASS, this, method);
|
|
569 |
| } |
|
570 |
| } |
|
571 |
| |
|
572 |
| |
|
573 |
| |
|
574 |
| |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
25410
| public final File getLocalFilePath(final ModuleAddress address) {
|
|
579 |
25410
| final String method = "localizeInFileSystem(URL)";
|
|
580 |
25410
| if (address.isFileAddress()) {
|
|
581 |
25047
| return new File(address.getURL().getFile());
|
|
582 |
| } |
|
583 |
363
| final URL url = address.getURL();
|
|
584 |
363
| Trace.param(CLASS, this, method, "protocol", url.getProtocol());
|
|
585 |
363
| Trace.param(CLASS, this, method, "host", url.getHost());
|
|
586 |
363
| Trace.param(CLASS, this, method, "port", url.getPort());
|
|
587 |
363
| Trace.param(CLASS, this, method, "path", url.getPath());
|
|
588 |
363
| Trace.param(CLASS, this, method, "file", url.getFile());
|
|
589 |
363
| StringBuffer file = new StringBuffer(url.getFile());
|
|
590 |
363
| StringUtility.replace(file, "_", "__");
|
|
591 |
363
| StringUtility.replace(file, "/", "_1");
|
|
592 |
363
| String encoded = file.toString();
|
|
593 |
363
| try {
|
|
594 |
363
| encoded = URLEncoder.encode(file.toString(), "UTF-8");
|
|
595 |
| } catch (UnsupportedEncodingException e) { |
|
596 |
| |
|
597 |
0
| Trace.trace(DefaultModuleAddress.class, "localizeInFileSystem(String)", e);
|
|
598 |
| } |
|
599 |
363
| file.setLength(0);
|
|
600 |
363
| file.append(encoded);
|
|
601 |
363
| StringUtility.replace(file, "#", "##");
|
|
602 |
363
| StringUtility.replace(file, "_1", "#");
|
|
603 |
363
| StringUtility.replace(file, "__", "_");
|
|
604 |
363
| StringBuffer adr = new StringBuffer(url.toExternalForm());
|
|
605 |
363
| try {
|
|
606 |
363
| adr = new StringBuffer(new URL(url.getProtocol(), url.getHost(),
|
|
607 |
| url.getPort(), file.toString()).toExternalForm()); |
|
608 |
| } catch (MalformedURLException e) { |
|
609 |
0
| Trace.fatal(CLASS, this, "localizeInFileSystem(URL)", "unexpected", e);
|
|
610 |
0
| e.printStackTrace();
|
|
611 |
| } |
|
612 |
| |
|
613 |
363
| StringUtility.replace(adr, "://", "_");
|
|
614 |
363
| StringUtility.replace(adr, ":", "_");
|
|
615 |
363
| return new File(getBufferDirectory(), adr.toString());
|
|
616 |
| } |
|
617 |
| |
|
618 |
| |
|
619 |
| |
|
620 |
| |
|
621 |
371
| private void processInc() {
|
|
622 |
371
| synchronized (syncToken) {
|
|
623 |
371
| this.processCounter++;
|
|
624 |
| } |
|
625 |
| } |
|
626 |
| |
|
627 |
| |
|
628 |
| |
|
629 |
| |
|
630 |
| |
|
631 |
371
| private void processDec() {
|
|
632 |
371
| synchronized (syncToken) {
|
|
633 |
371
| this.processCounter--;
|
|
634 |
| } |
|
635 |
| } |
|
636 |
| |
|
637 |
364
| public File getBufferDirectory() {
|
|
638 |
364
| return kernel.getConfig().getBufferDirectory();
|
|
639 |
| } |
|
640 |
| |
|
641 |
0
| public File getGenerationDirectory() {
|
|
642 |
0
| return kernel.getConfig().getGenerationDirectory();
|
|
643 |
| } |
|
644 |
| |
|
645 |
531
| public KernelQedeqBo getKernelQedeqBo(final ModuleAddress address) {
|
|
646 |
531
| return getModules().getKernelQedeqBo(address);
|
|
647 |
| } |
|
648 |
| |
|
649 |
29
| public QedeqBo getQedeqBo(final ModuleAddress address) {
|
|
650 |
29
| return getModules().getKernelQedeqBo(address);
|
|
651 |
| } |
|
652 |
| |
|
653 |
35
| public ModuleAddress getModuleAddress(final URL url) throws IOException {
|
|
654 |
35
| return new DefaultModuleAddress(url);
|
|
655 |
| } |
|
656 |
| |
|
657 |
53
| public ModuleAddress getModuleAddress(final String url) throws IOException {
|
|
658 |
53
| return new DefaultModuleAddress(url);
|
|
659 |
| } |
|
660 |
| |
|
661 |
2
| public ModuleAddress getModuleAddress(final File file) throws IOException {
|
|
662 |
2
| return new DefaultModuleAddress(file);
|
|
663 |
| } |
|
664 |
| |
|
665 |
439
| public String getSource(final ModuleAddress address) throws IOException {
|
|
666 |
439
| final KernelQedeqBo bo = getKernelQedeqBo(address);
|
|
667 |
439
| if (bo.getLoadingState().equals(LoadingState.STATE_UNDEFINED)
|
|
668 |
| || bo.getLoadingState().equals(LoadingState.STATE_LOADING_FROM_WEB) |
|
669 |
| || bo.getLoadingState().equals(LoadingState.STATE_LOADING_FROM_WEB_FAILED)) { |
|
670 |
63
| return null;
|
|
671 |
| |
|
672 |
| |
|
673 |
| } |
|
674 |
376
| final StringBuffer buffer = new StringBuffer();
|
|
675 |
376
| IoUtility.loadReader(loader.getModuleReader(bo), buffer);
|
|
676 |
376
| return buffer.toString();
|
|
677 |
| } |
|
678 |
| |
|
679 |
73
| public boolean checkModule(final ModuleAddress address) {
|
|
680 |
| |
|
681 |
73
| final String method = "checkModule(ModuleAddress)";
|
|
682 |
73
| final KernelQedeqBo prop = getKernelQedeqBo(address);
|
|
683 |
73
| try {
|
|
684 |
73
| QedeqLog.getInstance().logRequest("Check logical correctness for \""
|
|
685 |
| + prop.getUrl() + "\""); |
|
686 |
| |
|
687 |
73
| loadModule(address);
|
|
688 |
66
| LoadRequiredModules.loadRequired(prop, this);
|
|
689 |
| |
|
690 |
66
| QedeqBoFormalLogicChecker.check(prop);
|
|
691 |
48
| QedeqLog.getInstance().logSuccessfulReply(
|
|
692 |
| "Check of logical correctness successful for \"" |
|
693 |
| + prop.getUrl() + "\""); |
|
694 |
| } catch (final SourceFileExceptionList e) { |
|
695 |
25
| final String msg = "Check of logical correctness failed for \""
|
|
696 |
| + address.getURL() + "\""; |
|
697 |
25
| QedeqLog.getInstance().logFailureReply(msg, e.getMessage());
|
|
698 |
| } catch (final RuntimeException e) { |
|
699 |
0
| final String msg = "Check of logical correctness failed for \""
|
|
700 |
| + address.getURL() + "\""; |
|
701 |
0
| Trace.fatal(CLASS, this, method, msg, e);
|
|
702 |
0
| final SourceFileExceptionList xl =
|
|
703 |
| new DefaultSourceFileExceptionList(e); |
|
704 |
| |
|
705 |
| |
|
706 |
0
| if (!prop.isLoaded()) {
|
|
707 |
0
| if (!prop.getLoadingState().isFailure()) {
|
|
708 |
0
| prop.setLoadingFailureState(
|
|
709 |
| LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl); |
|
710 |
| } |
|
711 |
0
| } else if (!prop.hasLoadedRequiredModules()) {
|
|
712 |
0
| if (!prop.getDependencyState().isFailure()) {
|
|
713 |
0
| prop.setDependencyFailureState(
|
|
714 |
| DependencyState.STATE_LOADING_REQUIRED_MODULES_FAILED, xl); |
|
715 |
| } |
|
716 |
| } else { |
|
717 |
0
| if (!prop.getLogicalState().isFailure()) {
|
|
718 |
0
| prop.setLogicalFailureState(
|
|
719 |
| LogicalState.STATE_EXTERNAL_CHECKING_FAILED, xl); |
|
720 |
| } |
|
721 |
| } |
|
722 |
0
| QedeqLog.getInstance().logFailureReply(msg, e.toString());
|
|
723 |
| } catch (final Throwable e) { |
|
724 |
0
| final String msg = "Check of logical correctness failed for \""
|
|
725 |
| + prop.getUrl() + "\""; |
|
726 |
0
| Trace.fatal(CLASS, this, method, msg, e);
|
|
727 |
0
| final SourceFileExceptionList xl =
|
|
728 |
| new DefaultSourceFileExceptionList(e); |
|
729 |
| |
|
730 |
| |
|
731 |
0
| if (!prop.isLoaded()) {
|
|
732 |
0
| if (!prop.getLoadingState().isFailure()) {
|
|
733 |
0
| prop.setLoadingFailureState(
|
|
734 |
| LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl); |
|
735 |
| } |
|
736 |
0
| } else if (!prop.hasLoadedRequiredModules()) {
|
|
737 |
0
| if (!prop.getDependencyState().isFailure()) {
|
|
738 |
0
| prop.setDependencyFailureState(
|
|
739 |
| DependencyState.STATE_LOADING_REQUIRED_MODULES_FAILED, xl); |
|
740 |
| } |
|
741 |
| } else { |
|
742 |
0
| if (!prop.getLogicalState().isFailure()) {
|
|
743 |
0
| prop.setLogicalFailureState(
|
|
744 |
| LogicalState.STATE_EXTERNAL_CHECKING_FAILED, xl); |
|
745 |
| } |
|
746 |
| } |
|
747 |
0
| QedeqLog.getInstance().logFailureReply(msg, e.toString());
|
|
748 |
| } |
|
749 |
73
| if (validate) {
|
|
750 |
64
| modules.validateDependencies();
|
|
751 |
| } |
|
752 |
73
| return prop.isChecked();
|
|
753 |
| } |
|
754 |
| |
|
755 |
| |
|
756 |
| |
|
757 |
| |
|
758 |
| |
|
759 |
| |
|
760 |
1067
| private KernelQedeqBoPool getModules() {
|
|
761 |
1067
| return modules;
|
|
762 |
| } |
|
763 |
| |
|
764 |
1
| private SourceFileExceptionList createSourceFileExceptionList(final IOException e) {
|
|
765 |
1
| return new DefaultSourceFileExceptionList(e);
|
|
766 |
| } |
|
767 |
| |
|
768 |
1
| private SourceFileExceptionList createSourcelFileExceptionList(
|
|
769 |
| final ModuleFileNotFoundException e) { |
|
770 |
1
| return new DefaultSourceFileExceptionList(new IOException(e.getMessage()));
|
|
771 |
| } |
|
772 |
| |
|
773 |
13
| public String[] getSourceFileExceptionList(final ModuleAddress address) {
|
|
774 |
13
| final List list = new ArrayList();
|
|
775 |
13
| final KernelQedeqBo bo = getKernelQedeqBo(address);
|
|
776 |
13
| final SourceFileExceptionList sfl = bo.getException();
|
|
777 |
13
| if (sfl != null) {
|
|
778 |
13
| final StringBuffer buffer = new StringBuffer();
|
|
779 |
13
| do {
|
|
780 |
13
| try {
|
|
781 |
13
| IoUtility.loadReader(loader.getModuleReader(bo), buffer);
|
|
782 |
| } catch (IOException e) { |
|
783 |
3
| for (int i = 0; i < sfl.size(); i++) {
|
|
784 |
3
| list.add(sfl.get(i).getDescription());
|
|
785 |
| } |
|
786 |
3
| break;
|
|
787 |
| } |
|
788 |
10
| final TextInput input = new TextInput(buffer);
|
|
789 |
10
| input.setPosition(0);
|
|
790 |
10
| final StringBuffer buf = new StringBuffer();
|
|
791 |
10
| for (int i = 0; i < sfl.size(); i++) {
|
|
792 |
10
| buf.setLength(0);
|
|
793 |
10
| final SourceFileException sf = sfl.get(i);
|
|
794 |
10
| buf.append(sf.getDescription());
|
|
795 |
10
| try {
|
|
796 |
10
| if (sf.getSourceArea() != null && sf.getSourceArea().getStartPosition()
|
|
797 |
| != null) { |
|
798 |
8
| buf.append("\n");
|
|
799 |
8
| input.setRow(sf.getSourceArea().getStartPosition().getLine());
|
|
800 |
8
| buf.append(StringUtility.replace(input.getLine(), "\t", " "));
|
|
801 |
8
| buf.append("\n");
|
|
802 |
8
| final StringBuffer whitespace = StringUtility.getSpaces(
|
|
803 |
| sf.getSourceArea().getStartPosition().getColumn() - 1); |
|
804 |
8
| buffer.append(whitespace);
|
|
805 |
8
| buffer.append("^");
|
|
806 |
| } |
|
807 |
| } catch (Exception e) { |
|
808 |
0
| Trace.trace(CLASS, this, "getSourceFileExceptionList(ModuleAddress)",
|
|
809 |
| e); |
|
810 |
| } |
|
811 |
10
| list.add(buf.toString());
|
|
812 |
| } |
|
813 |
10
| break;
|
|
814 |
| } while (true); |
|
815 |
| } |
|
816 |
13
| return (String[]) list.toArray(new String[]{});
|
|
817 |
| } |
|
818 |
| |
|
819 |
| } |