Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 151   Methods: 13
NCLOC: 105   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConfigurationComponent.java 70% 86.2% 84.6% 82.7%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.config;
 8   
 9    import org.apache.commons.logging.Log;
 10    import org.apache.commons.logging.LogFactory;
 11    import org.jboss.cache.CacheImpl;
 12   
 13    import java.io.Serializable;
 14    import java.util.Collection;
 15    import java.util.Collections;
 16    import java.util.HashSet;
 17    import java.util.Set;
 18   
 19    /**
 20    * Base superclass of Cache configuration classes that expose some properties
 21    * that can be changed after the cache is started.
 22    *
 23    * @author <a href="brian.stansberry@jboss.com">Brian Stansberry</a>
 24    * @version $Revision: 1.6 $
 25    * @see #testImmutability(String)
 26    */
 27    public class ConfigurationComponent implements Serializable, Cloneable
 28    {
 29    private static final long serialVersionUID = 4879873994727821938L;
 30   
 31    protected transient Log log = LogFactory.getLog(getClass());
 32    private transient CacheImpl cache; // back-reference to test whether the cache is running.
 33    private final Set<ConfigurationComponent> children =
 34    Collections.synchronizedSet(new HashSet<ConfigurationComponent>());
 35   
 36  23261 protected ConfigurationComponent()
 37    {
 38    }
 39   
 40  0 public void passCacheToChildConfig(ConfigurationComponent child)
 41    {
 42  0 if (child != null)
 43    {
 44  0 child.setCacheImpl(cache);
 45    }
 46    }
 47   
 48  13056 protected void addChildConfig(ConfigurationComponent child)
 49    {
 50  13056 if (child != null && children.add(child))
 51  12243 child.setCacheImpl(cache);
 52    }
 53   
 54  2069 protected void addChildConfigs(Collection<? extends ConfigurationComponent> toAdd)
 55    {
 56  2069 if (toAdd != null)
 57    {
 58  2069 for (ConfigurationComponent child : toAdd)
 59  4166 addChildConfig(child);
 60    }
 61    }
 62   
 63  4022 protected void removeChildConfig(ConfigurationComponent child)
 64    {
 65  4022 children.remove(child);
 66    }
 67   
 68  2069 protected void removeChildConfigs(Collection<? extends ConfigurationComponent> toRemove)
 69    {
 70  2069 if (toRemove != null)
 71    {
 72  1060 for (ConfigurationComponent child : toRemove)
 73  1142 removeChildConfig(child);
 74    }
 75    }
 76   
 77  2868 protected void replaceChildConfig(ConfigurationComponent oldConfig, ConfigurationComponent newConfig)
 78    {
 79  2868 removeChildConfig(oldConfig);
 80  2868 addChildConfig(newConfig);
 81    }
 82   
 83  2069 protected void replaceChildConfigs(Collection<? extends ConfigurationComponent> oldConfigs,
 84    Collection<? extends ConfigurationComponent> newConfigs)
 85    {
 86  2069 synchronized (children)
 87    {
 88  2069 removeChildConfigs(oldConfigs);
 89  2069 addChildConfigs(newConfigs);
 90    }
 91    }
 92   
 93    /**
 94    * Checks field modifications via setters
 95    *
 96    * @param fieldName
 97    */
 98  97365 protected void testImmutability(String fieldName)
 99    {
 100  97365 try
 101    {
 102  97365 if (cache != null && cache.isStarted() && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class))
 103    {
 104  2 throw new ConfigurationException("Attempted to modify a non-Dynamic configuration element [" + fieldName + "] after the cache has started!");
 105    }
 106    }
 107    catch (NoSuchFieldException e)
 108    {
 109  0 log.warn("Field " + fieldName + " not found!!");
 110    }
 111    }
 112   
 113  0 protected CacheImpl getTreeCache()
 114    {
 115  0 return cache;
 116    }
 117   
 118    /**
 119    * Sets a back-reference to the cache associated with this configuration
 120    *
 121    * @param cache
 122    */
 123  24104 public void setCacheImpl(CacheImpl cache)
 124    {
 125  24104 this.cache = cache;
 126  24104 synchronized (children)
 127    {
 128  24104 for (ConfigurationComponent child : children)
 129    {
 130  5186 child.setCacheImpl(cache);
 131    }
 132    }
 133    }
 134   
 135  48 public ConfigurationComponent clone() throws CloneNotSupportedException
 136    {
 137  48 ConfigurationComponent c = (ConfigurationComponent) super.clone();
 138  48 c.setCacheImpl(null);
 139  48 return c;
 140    }
 141   
 142    /**
 143    * Null-safe equality test.
 144    * <p/>
 145    * FIXME this must be written elsewhere.
 146    */
 147  42 protected static boolean safeEquals(Object a, Object b)
 148    {
 149  42 return (a == b) || (a != null && a.equals(b));
 150    }
 151    }