Clover coverage report - PicoContainer - 1.1
Coverage timestamp: Thu Nov 4 2004 11:55:45 CST
file stats: LOC: 88   Methods: 6
NCLOC: 49   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 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.Parameter;
 13   
 import org.picocontainer.PicoContainer;
 14   
 import org.picocontainer.PicoRegistrationException;
 15   
 import org.picocontainer.MutablePicoContainer;
 16   
 import org.picocontainer.defaults.ComponentAdapterFactory;
 17   
 import org.picocontainer.defaults.DefaultComponentAdapterFactory;
 18   
 import org.picocontainer.defaults.DefaultPicoContainer;
 19   
 
 20   
 import java.io.Serializable;
 21   
 
 22   
 /**
 23   
  * This special MutablePicoContainer hides implementations of components if the key is an interface.
 24   
  * It's very simple. Instances that are registered directly and components registered without key
 25   
  * are not hidden.
 26   
  *
 27   
  * @author Paul Hammant
 28   
  * @version $Revision: 1.21 $
 29   
  * @since 1.1
 30   
  */
 31   
 public class ImplementationHidingPicoContainer extends AbstractDelegatingMutablePicoContainer implements Serializable {
 32   
 
 33   
     private ComponentAdapterFactory caf;
 34   
 
 35   
     /**
 36   
      * Creates a new container with a parent container.
 37   
      */
 38  192
     public ImplementationHidingPicoContainer(ComponentAdapterFactory caf, PicoContainer parent) {
 39  192
         super(new DefaultPicoContainer(caf, parent));
 40  192
         this.caf = caf;
 41   
     }
 42   
 
 43   
     /**
 44   
      * Creates a new container with a parent container.
 45   
      */
 46  92
     public ImplementationHidingPicoContainer(PicoContainer parent) {
 47  92
         this(new DefaultComponentAdapterFactory(), parent);
 48   
     }
 49   
 
 50   
 
 51   
     /**
 52   
      * Creates a new container with no parent container.
 53   
      */
 54  14
     public ImplementationHidingPicoContainer() {
 55  14
         this(null);
 56   
     }
 57   
 
 58  36
     public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation) throws PicoRegistrationException {
 59  36
         if (componentKey instanceof Class) {
 60  20
             Class clazz = (Class) componentKey;
 61  20
             if (clazz.isInterface()) {
 62  16
                 ComponentAdapter delegate = caf.createComponentAdapter(componentKey, componentImplementation, null);
 63  16
                 return getDelegate().registerComponent(new ImplementationHidingComponentAdapter(delegate, true));
 64   
             }
 65   
         }
 66  20
         return getDelegate().registerComponentImplementation(componentKey, componentImplementation);
 67   
     }
 68   
 
 69  18
     public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoRegistrationException {
 70  18
         if (componentKey instanceof Class) {
 71  6
             Class clazz = (Class) componentKey;
 72  6
             if (clazz.isInterface()) {
 73  2
                 ComponentAdapter delegate = caf.createComponentAdapter(componentKey, componentImplementation, parameters);
 74  2
                 ImplementationHidingComponentAdapter ihDelegate = new ImplementationHidingComponentAdapter(delegate, true);
 75  2
                 return getDelegate().registerComponent(ihDelegate);
 76   
             }
 77   
         }
 78  16
         return getDelegate().registerComponentImplementation(componentKey, componentImplementation, parameters);
 79   
     }
 80   
 
 81  6
     public MutablePicoContainer makeChildContainer() {
 82  6
         ImplementationHidingPicoContainer pc = new ImplementationHidingPicoContainer(this);
 83  6
         getDelegate().addChildContainer(pc);
 84  6
         return pc;
 85   
     }
 86   
 
 87   
 }
 88