Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 334   Methods: 28
NCLOC: 241   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultModuleProperties.java 58,9% 76,2% 96,4% 74,1%
coverage coverage
 1    /* $Id: DefaultModuleProperties.java,v 1.6 2008/01/26 12:39:08 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, 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.load;
 19   
 20    import java.net.URL;
 21   
 22    import org.qedeq.kernel.bo.logic.ExistenceChecker;
 23    import org.qedeq.kernel.bo.module.DependencyState;
 24    import org.qedeq.kernel.bo.module.LoadingState;
 25    import org.qedeq.kernel.bo.module.LogicalState;
 26    import org.qedeq.kernel.bo.module.ModuleAddress;
 27    import org.qedeq.kernel.bo.module.ModuleProperties;
 28    import org.qedeq.kernel.bo.module.ModuleReferenceList;
 29    import org.qedeq.kernel.bo.module.QedeqBo;
 30    import org.qedeq.kernel.common.SourceFileExceptionList;
 31   
 32   
 33    /**
 34    * Represents a module and its states.
 35    *
 36    * @version $Revision: 1.6 $
 37    * @author Michael Meyling
 38    */
 39    public class DefaultModuleProperties implements ModuleProperties {
 40   
 41    /** Address and module specification. */
 42    private final ModuleAddress address;
 43   
 44    /** Completeness during loading from web. */
 45    private int loadingCompleteness;
 46   
 47    /** Describes QEDEQ module loading state. */
 48    private LoadingState loadingState;
 49   
 50    /** Describes QEDEQ module dependency state. */
 51    private DependencyState dependencyState;
 52   
 53    /** Describes QEDEQ module logical state. */
 54    private LogicalState logicalState;
 55   
 56    /** Loaded QEDEQ module. */
 57    private QedeqBo module;
 58   
 59    /** Failure exception. */
 60    private SourceFileExceptionList exception;
 61   
 62    /** Required QEDEQ modules. */
 63    private ModuleReferenceList required;
 64   
 65    /** Predicate and function constant existence checker. */
 66    private ExistenceChecker checker;
 67   
 68   
 69    /**
 70    * Creates new module properties.
 71    *
 72    * @param address Module address (not <code>null</code>).
 73    */
 74  333 public DefaultModuleProperties(final ModuleAddress address) {
 75  333 this.address = address;
 76  333 loadingState = LoadingState.STATE_UNDEFINED;
 77  333 loadingCompleteness = 0;
 78  333 dependencyState = DependencyState.STATE_UNDEFINED;
 79  333 logicalState = LogicalState.STATE_UNCHECKED;
 80    }
 81   
 82  132 public final boolean hasFailures() {
 83  132 return loadingState.isFailure() || dependencyState.isFailure() || logicalState.isFailure();
 84    }
 85   
 86  2281 public final ModuleAddress getModuleAddress() {
 87  2281 return address;
 88    }
 89   
 90  349 public final void setLoadingCompleteness(final int completeness) {
 91  349 this.loadingCompleteness = completeness;
 92    }
 93   
 94    // TODO mime 20070704: shouldn't stand here:
 95    // ModuleEventLog.getInstance().stateChanged(props[i]);
 96    // and not in DefaultModuleFactory?
 97  627 public final void setLoadingProgressState(final LoadingState state) {
 98  627 if (state == LoadingState.STATE_LOADED) {
 99  0 throw new IllegalArgumentException(
 100    "this state could only be set by calling method setLoaded");
 101    }
 102  627 if (state.isFailure()) {
 103  0 throw new IllegalArgumentException(
 104    "this is a failure state, call setLoadingFailureState");
 105    }
 106    // FIXME mime 20071113: what about LogicalState and DependencyState of dependent modules?
 107  627 this.loadingState = state;
 108  627 this.module = null;
 109  627 this.dependencyState = DependencyState.STATE_UNDEFINED;
 110  627 this.logicalState = LogicalState.STATE_UNCHECKED;
 111  627 this.exception = null;
 112    }
 113   
 114  19 public final void setLoadingFailureState(final LoadingState state,
 115    final SourceFileExceptionList e) {
 116  19 if (!state.isFailure()) {
 117  0 throw new IllegalArgumentException(
 118    "this is no failure state, call setLoadingProgressState");
 119    }
 120    // FIXME mime 20071113: what about LogicalState and DependencyState of dependent modules?
 121    // they must be killed too!
 122  19 this.module = null;
 123  19 this.loadingState = state;
 124  19 this.dependencyState = DependencyState.STATE_UNDEFINED;
 125  19 this.logicalState = LogicalState.STATE_UNCHECKED;
 126  19 this.exception = e;
 127    }
 128   
 129  3605 public final LoadingState getLoadingState() {
 130  3605 return this.loadingState;
 131    }
 132   
 133  2209 public final boolean isLoaded() {
 134  2209 return loadingState == LoadingState.STATE_LOADED;
 135    }
 136   
 137  316 public final void setLoaded(final QedeqBo module) {
 138  316 loadingState = LoadingState.STATE_LOADED;
 139  316 this.module = module;
 140    }
 141   
 142  335 public final QedeqBo getModule() {
 143  335 if (loadingState != LoadingState.STATE_LOADED) {
 144  0 throw new IllegalStateException(
 145    "module exists only if state is \"" + LoadingState.STATE_LOADED.getText()
 146    + "\"");
 147    }
 148  335 return this.module;
 149    }
 150   
 151  69 public final void setDependencyProgressState(final DependencyState state) {
 152  69 if (!isLoaded() && state != DependencyState.STATE_UNDEFINED) {
 153  0 throw new IllegalArgumentException("module is not yet loaded");
 154    }
 155  69 if (state.isFailure()) {
 156  0 throw new IllegalArgumentException(
 157    "this is a failure state, call setDependencyFailureState");
 158    }
 159  69 if (state == DependencyState.STATE_LOADED_REQUIRED_MODULES) {
 160  0 throw new IllegalArgumentException(
 161    "this state could only be set by calling method setLoadedRequiredModules");
 162    }
 163  69 if (state != DependencyState.STATE_LOADED_REQUIRED_MODULES) {
 164    // FIXME mime 20071113: what about LogicalState and DependencyState of dependent modules?
 165    // they must be killed too!
 166  69 this.logicalState = LogicalState.STATE_UNCHECKED;
 167  69 this.required = null;
 168    }
 169  69 this.exception = null;
 170  69 this.dependencyState = state;
 171    }
 172   
 173  0 public final void setDependencyFailureState(final DependencyState state,
 174    final SourceFileExceptionList e) {
 175  0 if (!isLoaded()) {
 176  0 throw new IllegalArgumentException("module is not yet loaded");
 177    }
 178  0 if (!state.isFailure()) {
 179  0 throw new IllegalArgumentException(
 180    "this is no failure state, call setLoadingProgressState");
 181    }
 182    // FIXME mime 20071113: what about LogicalState and DependencyState of dependent modules?
 183    // they must be killed too!
 184  0 this.logicalState = LogicalState.STATE_UNCHECKED;
 185  0 this.dependencyState = state;
 186  0 this.exception = e;
 187    }
 188   
 189  2240 public final DependencyState getDependencyState() {
 190  2240 return this.dependencyState;
 191    }
 192   
 193  84 public final void setLoadedRequiredModules(final ModuleReferenceList list) {
 194  84 if (!isLoaded()) {
 195  0 throw new IllegalStateException(
 196    "Required modules can only be set if module is loaded."
 197    + "\"\nCurrently the status for the module"
 198    + "\"" + getName() + "\" is \"" + getLoadingState() + "\"");
 199    }
 200  84 dependencyState = DependencyState.STATE_LOADED_REQUIRED_MODULES;
 201  84 required = list;
 202    }
 203   
 204  1243 public final ModuleReferenceList getRequiredModules() {
 205  1243 if (!hasLoadedRequiredModules()) {
 206  0 throw new IllegalStateException(
 207    "module reference list exists only if state is \""
 208    + DependencyState.STATE_LOADED_REQUIRED_MODULES.getText() + "\"");
 209    }
 210  1243 return required;
 211    }
 212   
 213  3890 public final boolean hasLoadedRequiredModules() {
 214  3890 return loadingState == LoadingState.STATE_LOADED
 215    && dependencyState == DependencyState.STATE_LOADED_REQUIRED_MODULES;
 216    }
 217   
 218  38 public final void setChecked(final ExistenceChecker checker) {
 219  38 if (!hasLoadedRequiredModules()) {
 220  0 throw new IllegalStateException(
 221    "Checked can only be set if all required modules are loaded."
 222    + "\"\nCurrently the status for the module"
 223    + "\"" + getName() + "\" is \"" + getLoadingState() + "\"");
 224    }
 225  38 logicalState = LogicalState.STATE_CHECKED;
 226  38 this.checker = checker;
 227    }
 228   
 229  1898 public final ExistenceChecker getExistenceChecker() {
 230  1898 if (!hasLoadedRequiredModules()) {
 231  0 throw new IllegalStateException(
 232    "existence checker exists only if state is \""
 233    + LogicalState.STATE_CHECKED.getText() + "\"");
 234    }
 235  1898 return checker;
 236    }
 237   
 238  349 public final boolean isChecked() {
 239  349 return loadingState == LoadingState.STATE_LOADED
 240    && dependencyState == DependencyState.STATE_LOADED_REQUIRED_MODULES
 241    && logicalState == LogicalState.STATE_CHECKED;
 242    }
 243   
 244    // TODO mime 20070704: shouldn't stand here:
 245    // ModuleEventLog.getInstance().stateChanged(props[i]);
 246    // and not in DefaultModuleFactory?
 247  118 public final void setLogicalProgressState(final LogicalState state) {
 248  118 if (dependencyState.getCode() < DependencyState.STATE_LOADED_REQUIRED_MODULES.getCode()
 249    && state != LogicalState.STATE_UNCHECKED) {
 250  0 throw new IllegalArgumentException(
 251    "this state could only be set if all required modules are loaded ");
 252    }
 253  118 if (state.isFailure()) {
 254  0 throw new IllegalArgumentException(
 255    "this is a failure state, call setLogicalFailureState");
 256    }
 257  118 if (state == LogicalState.STATE_CHECKED) {
 258  0 throw new IllegalArgumentException(
 259    "set with setChecked(ExistenceChecker)");
 260    }
 261  118 this.exception = null;
 262  118 this.logicalState = state;
 263    }
 264   
 265  21 public final void setLogicalFailureState(final LogicalState state,
 266    final SourceFileExceptionList e) {
 267  21 if ((!isLoaded() || !hasLoadedRequiredModules()) && state != LogicalState.STATE_UNCHECKED) {
 268  0 throw new IllegalArgumentException(
 269    "this state could only be set if all required modules are loaded ");
 270    }
 271  21 if (!state.isFailure()) {
 272  0 throw new IllegalArgumentException(
 273    "this is no failure state, call setLogicalProgressState");
 274    }
 275  21 this.logicalState = state;
 276  21 this.exception = e;
 277    }
 278   
 279  3007 public final LogicalState getLogicalState() {
 280  3007 return this.logicalState;
 281    }
 282   
 283  423 public final SourceFileExceptionList getException() {
 284  423 return this.exception;
 285    }
 286   
 287  1588 public final String getStateDescription() {
 288  1588 if (loadingState == LoadingState.STATE_LOADING_FROM_WEB) {
 289  34 return loadingState.getText() + " (" + loadingCompleteness + "%)";
 290  1554 } else if (!isLoaded()) {
 291  952 return loadingState.getText();
 292  602 } else if (!hasLoadedRequiredModules()) {
 293  352 if (dependencyState == DependencyState.STATE_UNDEFINED) {
 294  282 return loadingState.getText();
 295    }
 296  70 return dependencyState.getText();
 297  250 } else if (!isChecked()) {
 298  210 if (logicalState == LogicalState.STATE_UNCHECKED) {
 299  69 return dependencyState.getText();
 300    }
 301  141 return logicalState.getText();
 302    }
 303  40 return logicalState.getText();
 304    }
 305   
 306  2248 public final String getName() {
 307  2248 if (address == null) {
 308  0 return "null";
 309    }
 310  2248 return address.getName();
 311    }
 312   
 313  132 public final String getRuleVersion() {
 314  132 if (address == null || module == null || module.getQedeq() == null
 315    || module.getQedeq().getHeader() == null
 316    || module.getQedeq().getHeader().getSpecification() == null
 317    || module.getQedeq().getHeader().getSpecification().getRuleVersion() == null) {
 318  117 return "";
 319    }
 320  15 return module.getQedeq().getHeader().getSpecification().getRuleVersion();
 321    }
 322   
 323  3648 public final URL getUrl() {
 324  3648 if (address == null) {
 325  0 return null;
 326    }
 327  3648 return address.getURL();
 328    }
 329   
 330  386 public final String toString() {
 331  386 return super.toString() + ":" + address + ";" + loadingState;
 332    }
 333   
 334    }