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