Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: So Sep 2 2007 02:40:58 CEST
file stats: LOC: 217   Methods: 20
NCLOC: 145   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultModuleProperties.java 61,8% 77,4% 95% 75,9%
coverage coverage
 1    /* $Id: DefaultModuleProperties.java,v 1.3 2007/08/21 21:03:30 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.LoadingState;
 23    import org.qedeq.kernel.bo.module.LogicalState;
 24    import org.qedeq.kernel.bo.module.ModuleAddress;
 25    import org.qedeq.kernel.bo.module.ModuleProperties;
 26    import org.qedeq.kernel.bo.module.QedeqBo;
 27    import org.qedeq.kernel.log.ModuleEventLog;
 28   
 29   
 30    /**
 31    * Represents a module and its states.
 32    *
 33    * @version $Revision: 1.3 $
 34    * @author Michael Meyling
 35    */
 36    public class DefaultModuleProperties implements ModuleProperties {
 37   
 38    /** Address and module specification. */
 39    private final ModuleAddress address;
 40   
 41    /** Completeness during loading from web. */
 42    private int loadingCompleteness;
 43   
 44    /** describes QEDEQ module loading state. */
 45    private LoadingState loadingState;
 46   
 47    /** describes QEDEQ module logical state. */
 48    private LogicalState logicalState;
 49   
 50    /** loaded QEDEQ module. */
 51    private QedeqBo module;
 52   
 53    /** failure exception. */
 54    private Exception exception;
 55   
 56   
 57    /**
 58    * Creates new module properties.
 59    *
 60    * @param address module address
 61    */
 62  33 public DefaultModuleProperties(final ModuleAddress address) {
 63  33 this.address = address;
 64  33 this.loadingState = LoadingState.STATE_UNDEFINED;
 65  33 this.loadingCompleteness = 0;
 66  33 this.logicalState = LogicalState.STATE_UNCHECKED;
 67    }
 68   
 69  0 public final boolean hasFailures() {
 70  0 return this.loadingState.isFailure();
 71    }
 72   
 73  1036 public final String getAddress() {
 74  1036 if (address == null) {
 75  0 return "null";
 76    }
 77  1036 return address.getAddress();
 78    }
 79   
 80  351 public final ModuleAddress getModuleAddress() {
 81  351 return address;
 82    }
 83   
 84  86 public final void setLoadingCompleteness(final int completeness) {
 85  86 this.loadingCompleteness = completeness;
 86    }
 87   
 88    // TODO mime 20070704: shouldn't stand here:
 89    // ModuleEventLog.getInstance().stateChanged(props[i]);
 90    // and not in DefaultModuleFactory?
 91  64 public final void setLoadingProgressState(final LoadingState state) {
 92  64 if (state == LoadingState.STATE_LOADED) {
 93  0 throw new IllegalArgumentException(
 94    "this state could only be set by calling method setCheckedAndLoaded");
 95    }
 96  64 if (this.loadingState == LoadingState.STATE_LOADED) {
 97  0 this.module = null;
 98    }
 99  64 if (state.isFailure()) {
 100  0 throw new IllegalArgumentException(
 101    "this is a failure state, call setLoadingFailureState");
 102    }
 103  64 this.exception = null;
 104  64 this.loadingState = state;
 105    }
 106   
 107  10 public final void setLoadingFailureState(final LoadingState state, final Exception e) {
 108  10 if (!state.isFailure()) {
 109  0 throw new IllegalArgumentException(
 110    "this is no failure state, call setProgressState");
 111    }
 112  10 if (this.loadingState == LoadingState.STATE_LOADED) {
 113  0 this.module = null;
 114    }
 115  10 this.loadingState = state;
 116  10 this.exception = e;
 117    }
 118   
 119  1607 public final LoadingState getLoadingState() {
 120  1607 return this.loadingState;
 121    }
 122   
 123    // TODO mime 20070704: shouldn't stand here:
 124    // ModuleEventLog.getInstance().stateChanged(props[i]);
 125    // and not in DefaultModuleFactory?
 126  34 public final void setLogicalProgressState(final LogicalState state) {
 127  34 if (state != LogicalState.STATE_UNCHECKED && loadingState != LoadingState.STATE_LOADED) {
 128  0 throw new IllegalArgumentException(
 129    "this state could only be set for loaded modules");
 130    }
 131  34 if (state.isFailure()) {
 132  0 throw new IllegalArgumentException(
 133    "this is a failure state, call setLogicalFailureState");
 134    }
 135  34 this.exception = null;
 136  34 this.logicalState = state;
 137    }
 138   
 139  10 public final void setLogicalFailureState(final LogicalState state, final Exception e) {
 140  10 if (state != LogicalState.STATE_UNCHECKED && loadingState != LoadingState.STATE_LOADED) {
 141  0 throw new IllegalArgumentException(
 142    "this state could only be set for loaded modules");
 143    }
 144  10 if (!state.isFailure()) {
 145  0 throw new IllegalArgumentException(
 146    "this is no failure state, call setProgressState");
 147    }
 148  10 this.logicalState = state;
 149  10 this.exception = e;
 150    }
 151   
 152  3332 public final LogicalState getLogicalState() {
 153  3332 return this.logicalState;
 154    }
 155   
 156  217 public final Exception getException() {
 157  217 return this.exception;
 158    }
 159   
 160  765 public final String getStateDescription() {
 161  765 if (loadingState == LoadingState.STATE_LOADING_FROM_WEB) {
 162  173 return loadingState.getText() + " (" + loadingCompleteness + "%)";
 163  592 } else if (!isLoaded()) {
 164  470 return loadingState.getText();
 165  122 } else if (getLogicalState() != LogicalState.STATE_UNCHECKED) {
 166  72 return logicalState.getText();
 167    } else {
 168  50 return loadingState.getText();
 169    }
 170    }
 171   
 172  1439 public final String getName() {
 173  1439 if (address == null) {
 174  0 return "null";
 175    }
 176  1439 return address.getName();
 177    }
 178   
 179  91 public final String getRuleVersion() {
 180  91 if (address == null || module == null || module.getHeader() == null
 181    || module.getHeader().getSpecification() == null
 182    || module.getHeader().getSpecification().getRuleVersion() == null) {
 183  36 return "";
 184    }
 185  55 return module.getHeader().getSpecification().getRuleVersion();
 186    }
 187   
 188  232 public final URL getUrl() {
 189  232 if (address == null) {
 190  0 return null;
 191    }
 192  232 return address.getURL();
 193    }
 194   
 195  646 public final boolean isLoaded() {
 196  646 return (this.loadingState == LoadingState.STATE_LOADED);
 197    }
 198   
 199  23 public final void setLoaded(final QedeqBo module) {
 200  23 this.loadingState = LoadingState.STATE_LOADED;
 201  23 this.module = module;
 202    }
 203   
 204  69 public final QedeqBo getModule() {
 205  69 if (this.loadingState != LoadingState.STATE_LOADED) {
 206  0 throw new IllegalStateException(
 207    "module exists only if state is \"" + LoadingState.STATE_LOADED.getText()
 208    + "\"");
 209    }
 210  69 return this.module;
 211    }
 212   
 213  101 public final String toString() {
 214  101 return super.toString() + ":" + address + ";" + loadingState;
 215    }
 216   
 217    }