Clover coverage report - PicoContainer - 1.0
Coverage timestamp: Sat Jun 5 2004 21:34:14 EDT
file stats: LOC: 112   Methods: 8
NCLOC: 51   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
AbstractComponentAdapter.java 80% 85% 87.5% 84.2%
coverage 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                                                          *
 9   
  *****************************************************************************/
 10   
 package org.picocontainer.defaults;
 11   
 
 12   
 import org.picocontainer.ComponentAdapter;
 13   
 import org.picocontainer.PicoContainer;
 14   
 
 15   
 import java.io.Serializable;
 16   
 import java.lang.reflect.Modifier;
 17   
 
 18   
 /**
 19   
  * Base class for a ComponentAdapter with general functionality.
 20   
  * This implementation provides basic checks for a healthy implementation of a ComponentAdapter.
 21   
  * It does not allow to use <code>null</code> for the component key or the implementation, 
 22   
  * ensures that the implementation is a concrete class and that the key is assignable from the 
 23   
  * implementation if the key represents a type.   
 24   
  *  
 25   
  * @author Paul Hammant
 26   
  * @author Aslak Helles&oslash;y
 27   
  * @author Jon Tirs&eacute;n
 28   
  * @version $Revision: 1.14 $
 29   
  * @since 1.0
 30   
  */
 31   
 public abstract class AbstractComponentAdapter implements ComponentAdapter, Serializable {
 32   
     private Object componentKey;
 33   
     private Class componentImplementation;
 34   
     private PicoContainer container;
 35   
 
 36   
     /**
 37   
      * Constructs a new ComponentAdapter for the given key and implementation. 
 38   
      * @param componentKey the search key for this implementation
 39   
      * @param componentImplementation the concrete implementation
 40   
      * @throws AssignabilityRegistrationException if the key is a type and the implementation cannot be assigned to.
 41   
      * @throws NotConcreteRegistrationException if the implementation is not a concrete class.
 42   
      */
 43  332
     protected AbstractComponentAdapter(Object componentKey, Class componentImplementation) throws AssignabilityRegistrationException, NotConcreteRegistrationException {
 44  332
         if (componentImplementation == null) {
 45  0
             throw new NullPointerException("componentImplementation");
 46   
         }
 47  332
         this.componentKey = componentKey;
 48  332
         this.componentImplementation = componentImplementation;
 49  332
         checkTypeCompatibility();
 50  329
         checkConcrete();
 51   
     }
 52   
 
 53   
     /**
 54   
      * {@inheritDoc}
 55   
      * @see org.picocontainer.ComponentAdapter#getComponentKey()
 56   
      */
 57  650
     public Object getComponentKey() {
 58  650
         if (componentKey == null) {
 59  0
             throw new NullPointerException("componentKey");
 60   
         }
 61  650
         return componentKey;
 62   
     }
 63   
 
 64   
     /**
 65   
      * {@inheritDoc}
 66   
      * @see org.picocontainer.ComponentAdapter#getComponentImplementation()
 67   
      */
 68  1714
     public Class getComponentImplementation() {
 69  1714
         return componentImplementation;
 70   
     }
 71   
 
 72  332
     private void checkTypeCompatibility() throws AssignabilityRegistrationException {
 73  332
         if (componentKey instanceof Class) {
 74  205
             Class componentType = (Class) componentKey;
 75  205
             if (!componentType.isAssignableFrom(componentImplementation)) {
 76  3
                 throw new AssignabilityRegistrationException(componentType, componentImplementation);
 77   
             }
 78   
         }
 79   
     }
 80   
 
 81  329
     private void checkConcrete() throws NotConcreteRegistrationException {
 82   
         // Assert that the component class is concrete.
 83  329
         boolean isAbstract = (componentImplementation.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT;
 84  329
         if (componentImplementation.isInterface() || isAbstract) {
 85  2
             throw new NotConcreteRegistrationException(componentImplementation);
 86   
         }
 87   
     }
 88   
 
 89   
 
 90   
     /**
 91   
      * @return Returns the ComponentAdapter's class name and the component's key.
 92   
      * @see java.lang.Object#toString()
 93   
      */
 94  0
     public String toString() {
 95  0
         return getClass().getName() + "[" + getComponentKey() + "]";
 96   
     }
 97   
 
 98   
     /**
 99   
      * @see org.picocontainer.ComponentAdapter#getContainer()
 100   
      */
 101  911
     public PicoContainer getContainer() {
 102  911
         return container;
 103   
     }
 104   
 
 105   
     /**
 106   
      * @see org.picocontainer.ComponentAdapter#setContainer(org.picocontainer.PicoContainer)
 107   
      */
 108  270
     public void setContainer(PicoContainer picoContainer) {
 109  270
         this.container = picoContainer;
 110   
     }
 111   
 }
 112