Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 501   Methods: 87
NCLOC: 325   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
KernelContext.java - 46,5% 41,4% 44,1%
coverage coverage
 1    /* $Id: KernelContext.java,v 1.17 2008/01/26 12:39:11 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.context;
 19   
 20    import java.io.File;
 21    import java.io.IOException;
 22    import java.net.URL;
 23   
 24    import org.qedeq.kernel.base.module.Specification;
 25    import org.qedeq.kernel.bo.module.Kernel;
 26    import org.qedeq.kernel.bo.module.KernelState;
 27    import org.qedeq.kernel.bo.module.ModuleAddress;
 28    import org.qedeq.kernel.bo.module.ModuleFactory;
 29    import org.qedeq.kernel.bo.module.ModuleProperties;
 30    import org.qedeq.kernel.bo.module.QedeqBo;
 31    import org.qedeq.kernel.common.SourceFileExceptionList;
 32    import org.qedeq.kernel.config.QedeqConfig;
 33    import org.qedeq.kernel.log.QedeqLog;
 34    import org.qedeq.kernel.trace.Trace;
 35   
 36   
 37    /**
 38    * This class provides static access methods for basic informations.
 39    *
 40    * @version $Revision: 1.17 $
 41    * @author Michael Meyling
 42    */
 43    public final class KernelContext implements Kernel {
 44   
 45    /** This class. */
 46    private static final Class CLASS = KernelContext.class;
 47   
 48    /** Version of this kernel. */
 49    private static final String KERNEL_VERSION = "0.03.08";
 50   
 51    /** Version dependent directory of this kernel. */
 52    private static final String KERNEL_VERSION_DIRECTORY = KERNEL_VERSION.replace('.', '_');
 53   
 54    /** Descriptive version information of this kernel. */
 55    private static final String DESCRIPTIVE_KERNEL_VERSION
 56    = "Hilbert II - Version " + KERNEL_VERSION + " (mongaga)";
 57   
 58    /** Maximal supported rule version of this kernel. */
 59    private static final String MAXIMAL_RULE_VERSION = "1.00.00";
 60   
 61    /** One and only instance of this class. */
 62    private static final KernelContext INSTANCE = new KernelContext();
 63   
 64    /** Initial kernel state. */
 65    private final KernelState initialState = new KernelState() {
 66   
 67  27 public void init(final ModuleFactory moduleFactory, final QedeqConfig qedeqConfig)
 68    throws IOException {
 69  27 QedeqLog.getInstance().logMessage("This is "
 70    + KernelContext.getInstance().getDescriptiveKernelVersion());
 71  27 QedeqLog.getInstance().logMessage(" see \"http://www.qedeq.org\" for more "
 72    + "information");
 73  27 QedeqLog.getInstance().logMessage(" supports rules till version "
 74    + KernelContext.getInstance().getMaximalRuleVersion());
 75  27 config = qedeqConfig;
 76  27 KernelContext.this.moduleFactory = moduleFactory;
 77  27 currentState = initializedState;
 78    }
 79   
 80  0 public boolean isReady() {
 81  0 return false;
 82    }
 83   
 84  0 public QedeqConfig getConfig() {
 85  0 throw new IllegalStateException("Kernel not initialized");
 86    }
 87   
 88  4 public void shutdown() {
 89    }
 90   
 91  0 public void startup() {
 92  0 throw new IllegalStateException("Kernel not initialized");
 93    }
 94   
 95  0 public void removeAllModules() {
 96  0 throw new IllegalStateException("Kernel not initialized");
 97    }
 98   
 99  0 public void removeModule(final ModuleAddress address) {
 100  0 throw new IllegalStateException("Kernel not initialized");
 101    }
 102   
 103  0 public void clearLocalBuffer() throws IOException {
 104  0 throw new IllegalStateException("Kernel not initialized");
 105    }
 106   
 107  0 public ModuleProperties loadModule(final ModuleAddress address)
 108    throws SourceFileExceptionList {
 109  0 throw new IllegalStateException("Kernel not initialized");
 110    }
 111   
 112  0 public ModuleProperties loadModule(final QedeqBo module, final Specification spec)
 113    throws SourceFileExceptionList {
 114  0 throw new IllegalStateException("Kernel not initialized");
 115    }
 116   
 117  0 public boolean loadAllModulesFromQedeq() {
 118  0 throw new IllegalStateException("Kernel not initialized");
 119    }
 120   
 121  0 public void loadRequiredModules(final ModuleAddress address) {
 122  0 throw new IllegalStateException("Kernel not initialized");
 123    }
 124   
 125  0 public ModuleAddress[] getAllLoadedModules() {
 126  0 throw new IllegalStateException("Kernel not initialized");
 127    }
 128   
 129  1 public File getBufferDirectory() {
 130  1 throw new IllegalStateException("Kernel not initialized");
 131    }
 132   
 133  0 public File getGenerationDirectory() {
 134  0 throw new IllegalStateException("Kernel not initialized");
 135    }
 136   
 137  0 public ModuleProperties getModuleProperties(final ModuleAddress address) {
 138  0 throw new IllegalStateException("Kernel not initialized");
 139    }
 140   
 141  0 public ModuleAddress getModuleAddress(final URL url) {
 142  0 throw new IllegalStateException("Kernel not initialized");
 143    }
 144   
 145  0 public ModuleAddress getModuleAddress(final String url) {
 146  0 throw new IllegalStateException("Kernel not initialized");
 147    }
 148   
 149  0 public ModuleAddress getModuleAddress(final File file) {
 150  0 throw new IllegalStateException("Kernel not initialized");
 151    }
 152   
 153  0 public File getLocalFilePath(final ModuleAddress address) {
 154  0 throw new IllegalStateException("Kernel not initialized");
 155    }
 156    };
 157   
 158    /** Initial kernel state. */
 159    private final KernelState initializedState = new KernelState() {
 160   
 161  0 public void init(final ModuleFactory moduleFactory, final QedeqConfig qedeqConfig)
 162    throws IOException {
 163  0 throw new IllegalStateException("Kernel is already initialized");
 164    }
 165   
 166  0 public boolean isReady() {
 167  0 return false;
 168    }
 169   
 170  57 public QedeqConfig getConfig() {
 171  57 return config;
 172    }
 173   
 174  0 public void shutdown() {
 175  0 currentState = initialState;
 176  0 KernelContext.this.moduleFactory = null;
 177  0 QedeqLog.getInstance().logMessage("QEDEQ Kernel closed.");
 178    }
 179   
 180  27 public void startup() {
 181  27 moduleFactory.startup();
 182  27 currentState = readyState;
 183  27 QedeqLog.getInstance().logMessage("QEDEQ kernel opened.");
 184    }
 185   
 186  0 public void removeAllModules() {
 187  0 throw new IllegalStateException("Kernel not started");
 188    }
 189   
 190  0 public void removeModule(final ModuleAddress address) {
 191  0 throw new IllegalStateException("Kernel not started");
 192    }
 193   
 194  0 public void clearLocalBuffer() throws IOException {
 195  0 throw new IllegalStateException("Kernel not started");
 196    }
 197   
 198  0 public ModuleProperties loadModule(final ModuleAddress address)
 199    throws SourceFileExceptionList {
 200  0 throw new IllegalStateException("Kernel not started");
 201    }
 202   
 203  0 public ModuleProperties loadModule(final QedeqBo module, final Specification spec)
 204    throws SourceFileExceptionList {
 205  0 throw new IllegalStateException("Kernel not started");
 206    }
 207   
 208  0 public boolean loadAllModulesFromQedeq() {
 209  0 throw new IllegalStateException("Kernel not started");
 210    }
 211   
 212  0 public void loadRequiredModules(final ModuleAddress address) {
 213  0 throw new IllegalStateException("Kernel not started");
 214    }
 215   
 216  0 public ModuleAddress[] getAllLoadedModules() {
 217  0 throw new IllegalStateException("Kernel not started");
 218    }
 219   
 220  0 public File getBufferDirectory() {
 221  0 throw new IllegalStateException("Kernel not started");
 222    }
 223   
 224  0 public File getGenerationDirectory() {
 225  0 throw new IllegalStateException("Kernel not started");
 226    }
 227   
 228  0 public ModuleProperties getModuleProperties(final ModuleAddress address) {
 229  0 throw new IllegalStateException("Kernel not started");
 230    }
 231   
 232  0 public ModuleAddress getModuleAddress(final URL url) {
 233  0 throw new IllegalStateException("Kernel not started");
 234    }
 235   
 236  0 public ModuleAddress getModuleAddress(final String url) {
 237  0 throw new IllegalStateException("Kernel not started");
 238    }
 239   
 240  0 public ModuleAddress getModuleAddress(final File file) {
 241  0 throw new IllegalStateException("Kernel not started");
 242    }
 243   
 244  0 public File getLocalFilePath(final ModuleAddress address) {
 245  0 throw new IllegalStateException("Kernel not started");
 246    }
 247    };
 248   
 249    /** State for ready kernel. */
 250    private final KernelState readyState = new KernelState() {
 251   
 252  0 public void init(final ModuleFactory moduleFactory, final QedeqConfig qedeqConfig)
 253    throws IOException {
 254    // we are already ready
 255    }
 256   
 257  0 public boolean isReady() {
 258  0 return false;
 259    }
 260   
 261  341 public QedeqConfig getConfig() {
 262  341 return config;
 263    }
 264   
 265  27 public void shutdown() {
 266  27 try {
 267  27 config.setLoadedModules(moduleFactory.getAllLoadedModules());
 268  27 config.store();
 269  27 QedeqLog.getInstance().logMessage("Current config file successfully saved.");
 270    } catch (IOException e) {
 271  0 Trace.trace(CLASS, this, "shutdown()", e);
 272  0 QedeqLog.getInstance().logMessage("Saving current config file failed.");
 273    }
 274  27 currentState = initialState;
 275  27 KernelContext.this.moduleFactory = null;
 276  27 QedeqLog.getInstance().logMessage("QEDEQ Kernel closed.");
 277    }
 278   
 279  0 public void startup() {
 280  0 throw new IllegalStateException("Kernel is already initialized");
 281    }
 282   
 283  0 public void removeAllModules() {
 284  0 moduleFactory.removeAllModules();
 285    }
 286   
 287  0 public void removeModule(final ModuleAddress address) throws IOException {
 288  0 moduleFactory.removeModule(address);
 289    }
 290   
 291  2 public void clearLocalBuffer() throws IOException {
 292  2 moduleFactory.clearLocalBuffer();
 293    }
 294   
 295  94 public ModuleProperties loadModule(final ModuleAddress address)
 296    throws SourceFileExceptionList {
 297  94 return moduleFactory.loadModule(address);
 298    }
 299   
 300  57 public ModuleProperties loadModule(final QedeqBo module, final Specification spec)
 301    throws SourceFileExceptionList {
 302  57 return moduleFactory.loadModule(module, spec);
 303    }
 304   
 305  1 public boolean loadAllModulesFromQedeq() {
 306  1 return moduleFactory.loadAllModulesFromQedeq();
 307    }
 308   
 309  55 public void loadRequiredModules(final ModuleAddress address)
 310    throws SourceFileExceptionList {
 311  55 moduleFactory.loadRequiredModules(address);
 312    }
 313   
 314  0 public ModuleAddress[] getAllLoadedModules() {
 315  0 return moduleFactory.getAllLoadedModules();
 316    }
 317   
 318  265 public File getBufferDirectory() {
 319  265 return moduleFactory.getBufferDirectory();
 320    }
 321   
 322  0 public File getGenerationDirectory() {
 323  0 return moduleFactory.getGenerationDirectory();
 324    }
 325   
 326  13 public ModuleProperties getModuleProperties(final ModuleAddress address) {
 327  13 return moduleFactory.getModuleProperties(address);
 328    }
 329   
 330  39 public ModuleAddress getModuleAddress(final URL url) throws IOException {
 331  39 return moduleFactory.getModuleAddress(url);
 332    }
 333   
 334  0 public ModuleAddress getModuleAddress(final String url) throws IOException {
 335  0 return moduleFactory.getModuleAddress(url);
 336    }
 337   
 338  1 public ModuleAddress getModuleAddress(final File file) throws IOException {
 339  1 return moduleFactory.getModuleAddress(file);
 340    }
 341   
 342  24676 public File getLocalFilePath(final ModuleAddress address) {
 343  24676 return moduleFactory.getLocalFilePath(address);
 344    }
 345   
 346    };
 347   
 348    /** Initial kernel state. */
 349    private KernelState currentState = initialState;
 350   
 351    /** For config access. */
 352    private QedeqConfig config;
 353   
 354    /** This factory can produce QEDEQ modules. */
 355    private ModuleFactory moduleFactory;
 356   
 357    /**
 358    * Constructor.
 359    */
 360  4 private KernelContext() {
 361    // nothing to do
 362    }
 363   
 364    /**
 365    * Get instance of kernel context.
 366    *
 367    * @return Singleton, which is responsible for the kernel access.
 368    */
 369  1594 public static final KernelContext getInstance() {
 370  1594 return INSTANCE;
 371    }
 372   
 373    /**
 374    * Get version of this kernel.
 375    *
 376    * @return Kernel version.
 377    */
 378  0 public final String getKernelVersion() {
 379  0 return KERNEL_VERSION;
 380    }
 381   
 382    /**
 383    * Get relative version directory of this kernel.
 384    *
 385    * @return Version sub directory.
 386    */
 387  1050 public final String getKernelVersionDirectory() {
 388  1050 return KERNEL_VERSION_DIRECTORY;
 389    }
 390   
 391    /**
 392    * Get descriptive version information of this kernel.
 393    *
 394    * @return Version Information.
 395    */
 396  31 public final String getDescriptiveKernelVersion() {
 397  31 return DESCRIPTIVE_KERNEL_VERSION;
 398    }
 399   
 400    /**
 401    * Get maximal supported rule version of this kernel.
 402    *
 403    * @return Maximal supported rule version.
 404    */
 405  27 public final String getMaximalRuleVersion() {
 406  27 return MAXIMAL_RULE_VERSION;
 407    }
 408   
 409    /**
 410    * Is a given rule version supported?
 411    *
 412    * @param ruleVersion Check this one.
 413    * @return Is the given rule version supported?
 414    */
 415  0 public final boolean isRuleVersionSupported(final String ruleVersion) {
 416  0 return MAXIMAL_RULE_VERSION.equals(ruleVersion);
 417    }
 418   
 419  27 public void init(final ModuleFactory moduleFactory, final QedeqConfig qedeqConfig)
 420    throws IOException {
 421  27 currentState.init(moduleFactory, qedeqConfig);
 422    }
 423   
 424  0 public boolean isReady() {
 425  0 return currentState.isReady();
 426    }
 427   
 428  398 public QedeqConfig getConfig() {
 429  398 return currentState.getConfig();
 430    }
 431   
 432  31 public void shutdown() {
 433  31 currentState.shutdown();
 434    }
 435   
 436  27 public void startup() {
 437  27 currentState.startup();
 438    }
 439   
 440  0 public void removeAllModules() {
 441  0 currentState.removeAllModules();
 442    }
 443   
 444  0 public void removeModule(final ModuleAddress address) throws IOException {
 445  0 currentState.removeModule(address);
 446    }
 447   
 448  2 public void clearLocalBuffer() throws IOException {
 449  2 currentState.clearLocalBuffer();
 450    }
 451   
 452  94 public ModuleProperties loadModule(final ModuleAddress address) throws SourceFileExceptionList {
 453  94 return currentState.loadModule(address);
 454    }
 455   
 456  57 public ModuleProperties loadModule(final QedeqBo module, final Specification spec)
 457    throws SourceFileExceptionList {
 458  57 return currentState.loadModule(module, spec);
 459    }
 460   
 461  1 public boolean loadAllModulesFromQedeq() {
 462  1 return currentState.loadAllModulesFromQedeq();
 463    }
 464   
 465  55 public void loadRequiredModules(final ModuleAddress address) throws SourceFileExceptionList {
 466  55 currentState.loadRequiredModules(address);
 467    }
 468   
 469  0 public ModuleAddress[] getAllLoadedModules() {
 470  0