Clover coverage report - PicoContainer - 1.1
Coverage timestamp: Thu Nov 4 2004 11:55:45 CST
file stats: LOC: 89   Methods: 6
NCLOC: 39   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 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                                                          *
 9   
  *****************************************************************************/
 10   
 package org.picocontainer.defaults;
 11   
 
 12   
 import org.picocontainer.ComponentAdapter;
 13   
 import org.picocontainer.PicoVisitor;
 14   
 
 15   
 import java.io.Serializable;
 16   
 
 17   
 /**
 18   
  * Base class for a ComponentAdapter with general functionality.
 19   
  * This implementation provides basic checks for a healthy implementation of a ComponentAdapter.
 20   
  * It does not allow to use <code>null</code> for the component key or the implementation, 
 21   
  * ensures that the implementation is a concrete class and that the key is assignable from the 
 22   
  * implementation if the key represents a type.   
 23   
  *  
 24   
  * @author Paul Hammant
 25   
  * @author Aslak Helles&oslash;y
 26   
  * @author Jon Tirs&eacute;n
 27   
  * @version $Revision: 1.20 $
 28   
  * @since 1.0
 29   
  */
 30   
 public abstract class AbstractComponentAdapter implements ComponentAdapter, Serializable {
 31   
     private Object componentKey;
 32   
     private Class componentImplementation;
 33   
 
 34   
     /**
 35   
      * Constructs a new ComponentAdapter for the given key and implementation. 
 36   
      * @param componentKey the search key for this implementation
 37   
      * @param componentImplementation the concrete implementation
 38   
      * @throws AssignabilityRegistrationException if the key is a type and the implementation cannot be assigned to.
 39   
      */
 40  1488
     protected AbstractComponentAdapter(Object componentKey, Class componentImplementation) throws AssignabilityRegistrationException {
 41  1488
         if (componentImplementation == null) {
 42  2
             throw new NullPointerException("componentImplementation");
 43   
         }
 44  1486
         this.componentKey = componentKey;
 45  1486
         this.componentImplementation = componentImplementation;
 46  1486
         checkTypeCompatibility();
 47   
     }
 48   
 
 49   
     /**
 50   
      * {@inheritDoc}
 51   
      * @see org.picocontainer.ComponentAdapter#getComponentKey()
 52   
      */
 53  6832
     public Object getComponentKey() {
 54  6832
         if (componentKey == null) {
 55  2
             throw new NullPointerException("componentKey");
 56   
         }
 57  6830
         return componentKey;
 58   
     }
 59   
 
 60   
     /**
 61   
      * {@inheritDoc}
 62   
      * @see org.picocontainer.ComponentAdapter#getComponentImplementation()
 63   
      */
 64  11308
     public Class getComponentImplementation() {
 65  11308
         return componentImplementation;
 66   
     }
 67   
 
 68  1486
     protected void checkTypeCompatibility() throws AssignabilityRegistrationException {
 69  1486
         if (componentKey instanceof Class) {
 70  1116
             Class componentType = (Class) componentKey;
 71  1116
             if (!componentType.isAssignableFrom(componentImplementation)) {
 72  14
                 throw new AssignabilityRegistrationException(componentType, componentImplementation);
 73   
             }
 74   
         }
 75   
     }
 76   
 
 77   
     /**
 78   
      * @return Returns the ComponentAdapter's class name and the component's key.
 79   
      * @see java.lang.Object#toString()
 80   
      */
 81  2
     public String toString() {
 82  2
         return getClass().getName() + "[" + getComponentKey() + "]";
 83   
     }
 84   
 
 85  550
     public void accept(PicoVisitor visitor) {
 86  550
         visitor.visitComponentAdapter(this);
 87   
     }
 88   
 }
 89