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