Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart8.png 47% of files have more coverage
86   530   66   1,69
24   252   0,77   51
51     1,29  
1    
 
  DefaultKernelQedeqBo       Line # 50 86 66 77% 0.77018636
 
  (43)
 
1    /* $Id: DefaultKernelQedeqBo.java,v 1.1 2008/07/26 07:58:29 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.kernel.bo.service;
19   
20    import java.net.URL;
21   
22    import org.qedeq.base.utility.EqualsUtility;
23    import org.qedeq.kernel.base.module.Qedeq;
24    import org.qedeq.kernel.bo.ModuleReferenceList;
25    import org.qedeq.kernel.bo.logic.wf.ExistenceChecker;
26    import org.qedeq.kernel.bo.module.InternalKernelServices;
27    import org.qedeq.kernel.bo.module.KernelModuleReferenceList;
28    import org.qedeq.kernel.bo.module.KernelQedeqBo;
29    import org.qedeq.kernel.bo.module.QedeqFileDao;
30    import org.qedeq.kernel.common.DefaultSourceFileExceptionList;
31    import org.qedeq.kernel.common.DependencyState;
32    import org.qedeq.kernel.common.LoadingState;
33    import org.qedeq.kernel.common.LogicalState;
34    import org.qedeq.kernel.common.ModuleAddress;
35    import org.qedeq.kernel.common.ModuleContext;
36    import org.qedeq.kernel.common.ModuleDataException;
37    import org.qedeq.kernel.common.ModuleLabels;
38    import org.qedeq.kernel.common.SourceArea;
39    import org.qedeq.kernel.common.SourceFileException;
40    import org.qedeq.kernel.common.SourceFileExceptionList;
41    import org.qedeq.kernel.dto.module.QedeqVo;
42   
43   
44    /**
45    * Represents a module and its states. This is a kernel intern representation.
46    *
47    * @version $Revision: 1.1 $
48    * @author Michael Meyling
49    */
 
50    public class DefaultKernelQedeqBo implements KernelQedeqBo {
51   
52    /** Internal kernel services. */
53    private final InternalKernelServices services;
54   
55    /** Address and module specification. */
56    private final ModuleAddress address;
57   
58    /** Completeness during loading from web. */
59    private int loadingCompleteness;
60   
61    /** Describes QEDEQ module loading state. */
62    private LoadingState loadingState;
63   
64    /** Describes QEDEQ module dependency state. */
65    private DependencyState dependencyState;
66   
67    /** Describes QEDEQ module logical state. */
68    private LogicalState logicalState;
69   
70    /** Loaded QEDEQ module. */
71    private QedeqVo qedeq;
72   
73    /** Failure exceptions. */
74    private SourceFileExceptionList exception;
75   
76    /** Required QEDEQ modules. */
77    private KernelModuleReferenceList required;
78   
79    /** Dependent QEDEQ modules. */
80    private KernelModuleReferenceList dependent;
81   
82    /** Predicate and function constant existence checker. */
83    private ExistenceChecker checker;
84   
85    /** Labels for this module. */
86    private ModuleLabels labels;
87   
88    /** Loader used for loading this object. */
89    private QedeqFileDao loader;
90   
91    /** State change manager. */
92    private final StateManager stateManager;
93   
94    /**
95    * Creates new module properties.
96    *
97    * @param services Internal kernel services.
98    * @param address Module address (not <code>null</code>).
99    * @throws NullPointerException <code>address</code> is null.
100    */
 
101  132 toggle public DefaultKernelQedeqBo(final InternalKernelServices services,
102    final ModuleAddress address) {
103  132 this.services = services;
104  132 this.address = address;
105  132 if (address == null) {
106  1 throw new NullPointerException("ModuleAddress must not be null");
107    }
108  131 loadingState = LoadingState.STATE_UNDEFINED;
109  131 loadingCompleteness = 0;
110  131 dependencyState = DependencyState.STATE_UNDEFINED;
111  131 logicalState = LogicalState.STATE_UNCHECKED;
112  131 required = new KernelModuleReferenceList();
113  131 dependent = new KernelModuleReferenceList();
114  131 stateManager = new StateManager(this);
115    }
116   
117    /**
118    * Set loader used for loading this object.
119    *
120    * @param loader
121    */
 
122  124 toggle public void setQedeqFileDao(final QedeqFileDao loader) {
123  124 this.loader = loader;
124    }
125   
126    /**
127    * Get loader used to load this object.
128    *
129    * @return Loader.
130    */
 
131  0 toggle public QedeqFileDao getLoader() {
132  0 return this.loader;
133    }
134   
 
135  1020 toggle public boolean hasFailures() {
136  1020 return loadingState.isFailure() || dependencyState.isFailure() || logicalState.isFailure();
137    }
138   
 
139  3925 toggle public ModuleAddress getModuleAddress() {
140  3925 return address;
141    }
142   
143    /**
144    * Get internal kernel services.
145    *
146    * @return Internal kernel services.
147    */
 
148  188 toggle public InternalKernelServices getKernelServices() {
149  188 return this.services;
150    }
151   
152    /**
153    * Set completeness percentage.
154    *
155    * LATER manage per state handler?
156    *
157    * @param completeness Completeness of loading into memory.
158    */
 
159  0 toggle public void setLoadingCompleteness(final int completeness) {
160  0 this.loadingCompleteness = completeness;
161    }
162   
 
163  0 toggle public int getLoadingCompleteness() {
164  0 return this.loadingCompleteness;
165    }
166   
167    /**
168    * Delete QEDEQ module. Invalidates all dependent modules.
169    */
 
170  0 toggle public void delete() {
171  0 stateManager.delete();
172    }
173   
174    /**
175    * Set loading progress module state.
176    *
177    * @param state Module loading state. Must not be <code>null</code>.
178    * @throws IllegalStateException State is a failure state or module loaded state.
179    */
 
180  230 toggle public void setLoadingProgressState(final LoadingState state) {
181  230 stateManager.setLoadingProgressState(state);
182    }
183   
184    /**
185    * Set failure module state.
186    *
187    * @param state Module loading state. Must not be <code>null</code>.
188    * @param e Exception that occurred during loading. Must not be <code>null</code>.
189    * @throws IllegalArgumentException <code>state</code> is no failure state
190    */
 
191  21 toggle public void setLoadingFailureState(final LoadingState state,
192    final SourceFileExceptionList e) {
193  21 stateManager.setLoadingFailureState(state, e);
194    }
195   
 
196  1138 toggle public LoadingState getLoadingState() {
197  1138 return this.loadingState;
198    }
199   
 
200  4761 toggle public boolean isLoaded() {
201  4761 return loadingState == LoadingState.STATE_LOADED;
202    }
203   
204    /**
205    * Set loading state to "loaded". Also puts <code>null</code> to {@link #getLabels()}.
206    *
207    * @param qedeq This module was loaded. Must not be <code>null</code>.
208    * @param labels Module labels.
209    * @throws NullPointerException One argument was <code>null</code>.
210    */
 
211  122 toggle public void setLoaded(final QedeqVo qedeq, final ModuleLabels labels) {
212  122 stateManager.setLoaded(qedeq, labels);
213    }
214   
 
215  852 toggle public Qedeq getQedeq() {
216  852 return this.qedeq;
217    }
218   
219    /**
220    * Set dependency progress module state.
221    *
222    * @param state Module state. Must not be <code>null</code>.
223    * @throws IllegalStateException Module is not yet loaded.
224    * @throws IllegalArgumentException <code>state</code> is failure state or loaded required
225    * state.
226    * @throws NullPointerException <code>state</code> is <code>null</code>.
227    */
 
228  159 toggle public void setDependencyProgressState(final DependencyState state) {
229  159 stateManager.setDependencyProgressState(state);
230    }
231   
232    /**
233    * Set failure module state.
234    *
235    * @param state Module dependency state. Must not be <code>null</code>.
236    * @param e Exception that occurred during loading. Must not be <code>null</code>.
237    * @throws IllegalStateException Module is not yet loaded.
238    * @throws IllegalArgumentException <code>state</code> is no failure state.
239    * @throws NullPointerException <code>state</code> is <code>null</code>.
240    */
 
241  81 toggle public void setDependencyFailureState(final DependencyState state,
242    final SourceFileExceptionList e) {
243  81 stateManager.setDependencyFailureState(state, e);
244    }
245   
 
246  615 toggle public DependencyState getDependencyState() {
247  615 return this.dependencyState;
248    }
249   
250    /**
251    * Set loaded required requirements state.
252    *
253    * @param list URLs of all referenced modules. Must not be <code>null</code>.
254    * @throws IllegalStateException Module is not yet loaded.
255    */
 
256  90 toggle public void setLoadedRequiredModules(final KernelModuleReferenceList list) {
257  90 stateManager.setLoadedRequiredModules(list);
258    }
259   
 
260  1238 toggle public ModuleReferenceList getRequiredModules() {
261  1238 return getKernelRequiredModules();
262    }
263   
264    /**
265    * Get labels and URLs of all referenced modules.
266    *
267    * @return URLs of all referenced modules.
268    */
 
269  2368 toggle public KernelModuleReferenceList getKernelRequiredModules() {
270  2368 return required;
271    }
272   
 
273  2278 toggle public boolean hasLoadedRequiredModules() {
274  2278 return isLoaded() && dependencyState == DependencyState.STATE_LOADED_REQUIRED_MODULES;
275    }
276   
277    /**
278    * Get labels and URLs of all directly dependent modules.
279    *
280    * @return URLs of all referenced modules.
281    */
 
282  866 toggle public KernelModuleReferenceList getDependentModules() {
283  866 return dependent;
284    }
285   
286    /**
287    * Set logic checked state. Also set the predicate and function existence checker.
288    *
289    * @param checker Checks if a predicate or function constant is defined.
290    */
 
291  52 toggle public void setChecked(final ExistenceChecker checker) {
292  52 stateManager.setChecked(checker);
293    }
294   
 
295  1876 toggle public ExistenceChecker getExistenceChecker() {
296  1876 return checker;
297    }
298   
 
299  772 toggle public boolean isChecked() {
300  772 return isLoaded() && hasLoadedRequiredModules()
301    && logicalState == LogicalState.STATE_CHECKED;
302    }
303   
304    /**
305    * Set loading progress module state. Must not be <code>null</code>.
306    *
307    * @param state module state
308    */
 
309  124 toggle public void setLogicalProgressState(final LogicalState state) {
310  124 stateManager.setLogicalProgressState(state);
311    }
312   
313    /**
314    * Set failure module state.
315    *
316    * @param state module state
317    * @param e Exception that occurred during loading.
318    * @throws IllegalArgumentException <code>state</code> is no failure state
319    */
 
320  11 toggle public void setLogicalFailureState(final LogicalState state,
321    final SourceFileExceptionList e) {
322  11 stateManager.setLogicalFailureState(state, e);
323    }
324   
 
325  0 toggle public LogicalState getLogicalState() {
326  0 return this.logicalState;
327    }
328   
 
329  116 toggle public SourceFileExceptionList getException() {
330  116 return this.exception;
331    }
332   
333    /**
334    * Get warnings for this BO.
335    * <p>
336    * FIXME mime 20080324: implement this method. Put in interface and use in GUI.
337    *
338    * @return Warnings for this BO.
339    */
 
340  0 toggle public SourceFileExceptionList getWarnings() {
341  0 return null;
342    }
343   
 
344  846 toggle public String getStateDescription() {
345  846 if (loadingState == LoadingState.STATE_LOADING_FROM_WEB) {
346  0 return loadingState.getText() + " (" + loadingCompleteness + "%)";
347  846 } else if (!isLoaded()) {
348  224 return loadingState.getText();
349  622 } else if (!hasLoadedRequiredModules()) {
350  347 if (dependencyState == DependencyState.STATE_UNDEFINED) {
351  117 return loadingState.getText();
352    }
353  230 return dependencyState.getText();
354  275 } else if (!isChecked()) {
355  224 if (logicalState == LogicalState.STATE_UNCHECKED) {
356  89 return dependencyState.getText();
357    }
358  135 return logicalState.getText();
359    }
360  51 return logicalState.getText();
361    }
362   
 
363  18 toggle public String getName() {
364  18 if (address == null) {
365  0 return "null";
366    }
367  18 return address.getName();
368    }
369   
 
370  0 toggle public String getRuleVersion() {
371  0 if (address == null || qedeq == null
372    || qedeq.getHeader() == null
373    || qedeq.getHeader().getSpecification() == null
374    || qedeq.getHeader().getSpecification().getRuleVersion() == null) {
375  0 return "";
376    }
377  0 return qedeq.getHeader().getSpecification().getRuleVersion();
378    }
379   
 
380  1440 toggle public URL getUrl() {
381  1440 if (this.address == null) {
382  0 return null;
383    }
384  1440 return this.address.getURL();
385    }
386   
387    /**
388    * Set label references for QEDEQ module.
389    *
390    * @param labels Label references.
391    */
 
392  360 toggle public void setLabels(final ModuleLabels labels) {
393  360 this.labels = labels;
394    }
395   
 
396  160 toggle public ModuleLabels getLabels() {
397  160 return labels;
398    }
399   
400    /**
401    * Create exception out of {@link ModuleDataException}.
402    *
403    * @param exception Take this exception.
404    * @return Newly created instance.
405    */
 
406  0 toggle public SourceFileExceptionList createSourceFileExceptionList(
407    final ModuleDataException exception) {
408  0 final SourceFileException e = new SourceFileException(exception, createSourceArea(qedeq,
409    exception.getContext()), loader.createSourceArea(qedeq,
410    exception.getReferenceContext()));
411  0 final DefaultSourceFileExceptionList list = new DefaultSourceFileExceptionList(e);
412  0 return list;
413    }
414   
415    /**
416    * Create exception out of {@link ModuleDataException}.
417    *
418    * @param exception Take this exception.
419    * @param qedeq Take this QEDEQ source. (This might not be accessible via
420    * {@link #getQedeq()}.
421    * @return Newly created instance.
422    */
 
423  0 toggle public SourceFileExceptionList createSourceFileExceptionList(
424    final ModuleDataException exception, final Qedeq qedeq) {
425  0 final SourceFileException e = new SourceFileException(exception, createSourceArea(qedeq,
426    exception.getContext()), loader.createSourceArea(qedeq,
427    exception.getReferenceContext()));
428  0 final DefaultSourceFileExceptionList list = new DefaultSourceFileExceptionList(e);
429  0 return list;
430    }
431   
 
432  131 toggle public SourceFileException createSourceFileException(final ModuleDataException
433    exception) {
434  131 final SourceFileException e = new SourceFileException(exception, createSourceArea(qedeq,
435    exception.getContext()), loader.createSourceArea(qedeq,
436    exception.getReferenceContext()));
437  131 return e;
438    }
439   
440    /**
441    * Create area in source file for QEDEQ module context.
442    *
443    * @param qedeq Look at this QEDEQ module.
444    * @param context Search for this context.
445    * @return Created file area. Maybe <code>null</code>.
446    */
 
447  131 toggle public SourceArea createSourceArea(final Qedeq qedeq, final ModuleContext context) {
448  131 return loader.createSourceArea(qedeq, context);
449    }
450   
451    /**
452    * Set {@link QedeqVo}. Doesn't do any status handling. Only for internal use.
453    *
454    * @param qedeq Set this value.
455    */
 
456  477 toggle public void setQedeqVo(final QedeqVo qedeq) {
457  477 this.qedeq = qedeq;
458    }
459   
460    /**
461    * Set {@link LoadingState}. Doesn't do any status handling. Only for internal use.
462    *
463    * @param state Set this loading state.
464    */
 
465  476 toggle protected void setLoadingState(final LoadingState state) {
466  476 this.loadingState = state;
467    }
468   
469    /**
470    * Set {@link DependencyState}. Doesn't do any status handling. Only for internal use.
471    *
472    * @param state Set this dependency state.
473    */
 
474  684 toggle protected void setDependencyState(final DependencyState state) {
475  684 this.dependencyState = state;
476    }
477   
478    /**
479    * Set {@link LogicalState}. Doesn't do any status handling. Only for internal use.
480    *
481    * @param state Set this logical state.
482    */
 
483  706 toggle protected void setLogicalState(final LogicalState state) {
484  706 this.logicalState = state;
485    }
486   
487    /**
488    * Set {@link SourceFileExceptionList}. Doesn't do any status handling. Only for internal use.
489    *
490    * @param exception Set this exception.
491    */
 
492  729 toggle protected void setException(final SourceFileExceptionList exception) {
493  729 this.exception = exception;
494    }
495   
496    /**
497    * Get {@link StateManager}. Only for internal use.
498    *
499    * @return StateManager
500    */
 
501  0 toggle protected StateManager getStateManager() {
502  0 return this.stateManager;
503    }
504   
505    /**
506    * Set {@link ExistenceChecker}. Doesn't do any status handling. Only for internal use.
507    *
508    * @param checker Set this checker.
509    */
 
510  52 toggle protected void setExistenceChecker(final ExistenceChecker checker) {
511  52 this.checker = checker;
512    }
513   
 
514  661 toggle public int hashCode() {
515  661 return (getModuleAddress() == null ? 0 : getModuleAddress().hashCode());
516    }
517   
 
518  575 toggle public boolean equals(final Object obj) {
519  575 if (obj instanceof DefaultKernelQedeqBo) {
520  575 return EqualsUtility.equals(((DefaultKernelQedeqBo) obj).getModuleAddress(),
521    this.getModuleAddress());
522    }
523  0 return false;
524    }
525   
 
526  188 toggle public String toString() {
527  188 return address.getURL().toString();
528    }
529   
530    }