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