Clover coverage report - picocontainer - 1.2-beta-1
Coverage timestamp: Sun May 29 2005 14:29:04 BST
file stats: LOC: 104   Methods: 8
NCLOC: 60   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ImplementationHidingCachingPicoContainer.java 100% 100% 100% 100%
coverage
 1    /*****************************************************************************
 2    * Copyright (C) PicoContainer Organization. All rights reserved. *
 3    * ------------------------------------------------------------------------- *
 4    * The software in this package is published under the terms of the BSD *
 5    * style license a copy of which has been included with this distribution in *
 6    * the LICENSE.txt file. *
 7    * *
 8    * Original code by the committers *
 9    *****************************************************************************/
 10    package org.picocontainer.alternatives;
 11   
 12    import org.picocontainer.ComponentAdapter;
 13    import org.picocontainer.MutablePicoContainer;
 14    import org.picocontainer.Parameter;
 15    import org.picocontainer.PicoContainer;
 16    import org.picocontainer.PicoRegistrationException;
 17    import org.picocontainer.LifecycleManager;
 18    import org.picocontainer.defaults.CachingComponentAdapter;
 19    import org.picocontainer.defaults.CachingComponentAdapterFactory;
 20    import org.picocontainer.defaults.ComponentAdapterFactory;
 21    import org.picocontainer.defaults.DefaultComponentAdapterFactory;
 22    import org.picocontainer.defaults.DefaultLifecycleManager;
 23   
 24    import java.io.Serializable;
 25   
 26    /**
 27    * This special MutablePicoContainer hides implementations of components if the key is an interface.
 28    * It's very simple. Instances that are registered directly and components registered without key
 29    * are not hidden.
 30    *
 31    * @author Paul Hammant
 32    * @version $Revision: 1845 $
 33    * @since 1.1
 34    */
 35    public class ImplementationHidingCachingPicoContainer extends AbstractDelegatingMutablePicoContainer implements Serializable {
 36   
 37    private CachingComponentAdapterFactory caf;
 38    private LifecycleManager lifecycleManager;
 39   
 40    /**
 41    * Creates a new container with a parent container.
 42    */
 43   
 44  84 public ImplementationHidingCachingPicoContainer(ComponentAdapterFactory caf, PicoContainer parent) {
 45  84 this(parent, new CachingComponentAdapterFactory(caf), new DefaultLifecycleManager());
 46    }
 47   
 48  10 public ImplementationHidingCachingPicoContainer(ComponentAdapterFactory caf, PicoContainer parent, LifecycleManager lifecyleManager) {
 49  10 this(parent, new CachingComponentAdapterFactory(caf), lifecyleManager);
 50    }
 51   
 52  102 private ImplementationHidingCachingPicoContainer(PicoContainer parent, CachingComponentAdapterFactory caf, LifecycleManager lifecycleManager) {
 53  102 super(new ImplementationHidingPicoContainer(caf, parent, lifecycleManager));
 54  102 this.caf = caf;
 55  102 this.lifecycleManager = lifecycleManager;
 56    }
 57   
 58    /**
 59    * Creates a new container with a parent container.
 60    */
 61  82 public ImplementationHidingCachingPicoContainer(PicoContainer parent) {
 62  82 this(new DefaultComponentAdapterFactory(), parent);
 63    }
 64   
 65   
 66    /**
 67    * Creates a new container with no parent container.
 68    */
 69  12 public ImplementationHidingCachingPicoContainer() {
 70  12 this(null);
 71    }
 72   
 73  30 public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation) throws PicoRegistrationException {
 74  30 if (componentKey instanceof Class) {
 75  16 Class clazz = (Class) componentKey;
 76  16 if (clazz.isInterface()) {
 77  14 ComponentAdapter delegate = caf.createComponentAdapter(componentKey, componentImplementation, null);
 78  14 return getDelegate().registerComponent(new CachingComponentAdapter(new ImplementationHidingComponentAdapter(delegate, true)));
 79    }
 80    }
 81  16 return getDelegate().registerComponentImplementation(componentKey, componentImplementation);
 82    }
 83   
 84  10 public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoRegistrationException {
 85  10 if (componentKey instanceof Class) {
 86  4 Class clazz = (Class) componentKey;
 87  4 if (clazz.isInterface()) {
 88  2 ComponentAdapter delegate = caf.createComponentAdapter(componentKey, componentImplementation, parameters);
 89  2 ImplementationHidingComponentAdapter ihDelegate = new ImplementationHidingComponentAdapter(delegate, true);
 90  2 return getDelegate().registerComponent(new CachingComponentAdapter(ihDelegate));
 91    }
 92    }
 93  8 return getDelegate().registerComponentImplementation(componentKey, componentImplementation, parameters);
 94    }
 95   
 96   
 97  8 public MutablePicoContainer makeChildContainer() {
 98  8 ImplementationHidingCachingPicoContainer pc = new ImplementationHidingCachingPicoContainer(this, caf, lifecycleManager);
 99  8 getDelegate().addChildContainer(pc);
 100  8 return pc;
 101   
 102    }
 103   
 104    }