Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 156   Methods: 5
NCLOC: 96   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Modules.java 80% 61,7% 60% 64,5%
coverage coverage
 1    /* $Id: Modules.java,v 1.5 2008/01/26 12:39:08 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.util.ArrayList;
 21    import java.util.HashMap;
 22    import java.util.Iterator;
 23    import java.util.List;
 24    import java.util.Map;
 25   
 26    import org.qedeq.kernel.bo.module.LoadingState;
 27    import org.qedeq.kernel.bo.module.ModuleAddress;
 28    import org.qedeq.kernel.bo.module.ModuleProperties;
 29    import org.qedeq.kernel.log.ModuleEventLog;
 30    import org.qedeq.kernel.trace.Trace;
 31   
 32    /**
 33    * Encapsulates all modules.
 34    */
 35    class Modules {
 36   
 37    /** This class. */
 38    private static final Class CLASS = Modules.class;
 39   
 40    /** properties of modules; key: ModuleAddress, value: ModuleProperties.*/
 41    private final Map moduleProperties = new HashMap();
 42   
 43   
 44    /**
 45    * Get module properties for an module address. If it is unknown it will be created.
 46    *
 47    * @param address Module address.
 48    * @return Module properties for module.
 49    */
 50  513 final ModuleProperties getModuleProperties(final ModuleAddress address) {
 51  513 synchronized (moduleProperties) {
 52  513 if (moduleProperties.containsKey(address)) {
 53  192 return (ModuleProperties) moduleProperties.get(address);
 54    } else {
 55  321 final ModuleProperties prop = new DefaultModuleProperties(address);
 56  321 moduleProperties.put(address, prop);
 57  321 return prop;
 58    }
 59    }
 60    }
 61   
 62   
 63    /**
 64    * Remove all modules from memory.
 65    */
 66  2 final void removeAllModules() {
 67  2 final String method = "removeAllModules";
 68  2 Trace.begin(CLASS, this, method);
 69  2 try {
 70  2 synchronized (moduleProperties) {
 71  2 for (final Iterator iterator
 72    = moduleProperties.entrySet().iterator();
 73  33 iterator.hasNext(); ) {
 74  31 Map.Entry entry = (Map.Entry) iterator.next();
 75  31 final ModuleProperties prop = (ModuleProperties) entry.getValue();
 76  31 Trace.trace(CLASS, this, method, "remove " + prop);
 77  31 ModuleEventLog.getInstance().removeModule(prop);
 78    }
 79  2 moduleProperties.clear();
 80    }
 81    } catch (RuntimeException e) {
 82  0 Trace.trace(CLASS, this, method, e);
 83    } finally {
 84  2 Trace.end(CLASS, this, method);
 85    }
 86    }
 87   
 88   
 89    /**
 90    * Remove a QEDEQ module from memory.
 91    *
 92    * @param prop Defines the module.
 93    */
 94  0 final void removeModule(final ModuleProperties prop) {
 95  0 final String method = "removeModule";
 96  0 Trace.begin(CLASS, this, method);
 97  0 try {
 98  0 synchronized (moduleProperties) {
 99  0 Trace.trace(CLASS, this, method, "remove module "
 100    + prop.getUrl());
 101  0 if (!prop.isLoaded()) {
 102  0 Trace.trace(CLASS, this, method, "removing " + prop.getUrl());
 103  0 ModuleEventLog.getInstance().removeModule(prop);
 104  0 moduleProperties.remove(prop.getModuleAddress());
 105    } else {
 106  0 Trace.trace(CLASS, this, method, "module number=" + moduleProperties.size());
 107  0 Trace.trace(CLASS, this, method, "removing module itself: " + prop.getUrl());
 108  0 ModuleEventLog.getInstance().removeModule(prop);
 109  0 moduleProperties.remove(prop.getModuleAddress());
 110  0 Trace.trace(CLASS, this, method, "module number=" + moduleProperties.size());
 111    }
 112    }
 113    } catch (RuntimeException e) {
 114  0 Trace.trace(CLASS, this, method, e);
 115    } finally {
 116  0 Trace.end(CLASS, this, method);
 117    }
 118    }
 119   
 120    /**
 121    * Get list of all successfully loaded modules.
 122    *
 123    * @return list of all successfully loaded modules.
 124    */
 125  27 final ModuleAddress[] getAllLoadedModules() {
 126  27 final String method = "getAllModules";
 127  27 Trace.begin(CLASS, this, method);
 128  27 try {
 129  27 final List list = new ArrayList();
 130  27 synchronized (moduleProperties) {
 131  27 for (final Iterator iterator
 132    = moduleProperties.entrySet().iterator();
 133  274 iterator.hasNext(); ) {
 134  247 Map.Entry entry = (Map.Entry) iterator.next();
 135  247 final ModuleProperties prop = (ModuleProperties) entry.getValue();
 136  247 if (prop.getLoadingState().getCode() >= LoadingState.STATE_LOADED.getCode()) {
 137  227 list.add(prop.getModuleAddress());
 138    }
 139    }
 140    }
 141  27 return (ModuleAddress[]) list.toArray(new ModuleAddress[] {});
 142    } finally {
 143  27 Trace.end(CLASS, this, method);
 144    }
 145    }
 146   
 147    /**
 148    * Get number of QEDEQ modules in STATE_LOADED.
 149    *
 150    * @return Number of loaded modules.
 151    */
 152  0 final int getNumberOfLoadedModules() {
 153  0 return getAllLoadedModules().length;
 154    }
 155   
 156    }