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