Clover coverage report - PicoContainer - 1.0-RC-1
Coverage timestamp: Tue May 18 2004 16:19:33 EDT
file stats: LOC: 63   Methods: 3
NCLOC: 25   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
ComponentParameter.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.Parameter;
 14   
 import org.picocontainer.PicoContainer;
 15   
 import org.picocontainer.PicoIntrospectionException;
 16   
 
 17   
 import java.io.Serializable;
 18   
 
 19   
 /**
 20   
  * A ComponentParameter should be used to pass in a particular component
 21   
  * as argument to a different component's constructor. This is particularly
 22   
  * useful in cases where several components of the same type have been registered,
 23   
  * but with a different key. Passing a ComponentParameter as a parameter
 24   
  * when registering a component will give PicoContainer a hint about what
 25   
  * other component to use in the constructor.
 26   
  *
 27   
  * @author Jon Tirsén
 28   
  * @author Aslak Hellesøy
 29   
  * @version $Revision: 1.17 $
 30   
  */
 31   
 public class ComponentParameter implements Parameter, Serializable {
 32   
 
 33   
     private Object componentKey;
 34   
 
 35   
     /**
 36   
      * Expect a parameter matching a component of a specific key.
 37   
      * @param componentKey the key of the desired component
 38   
      */
 39  8
     public ComponentParameter(Object componentKey) {
 40  8
         this.componentKey = componentKey;
 41   
     }
 42   
 
 43   
     /**
 44   
      * Expect any paramter of the appropriate type.
 45   
      */
 46  506
     public ComponentParameter() {}
 47   
 
 48  544
     public ComponentAdapter resolveAdapter(PicoContainer picoContainer, Class expectedType) throws PicoIntrospectionException {
 49  544
         ComponentAdapter result;
 50  544
         if (componentKey != null) {
 51  18
             result = picoContainer.getComponentAdapter(componentKey);
 52  18
             if(result != null && !expectedType.isAssignableFrom(result.getComponentImplementation())) {
 53   
                 // found one, but it wasn't of the expected type
 54  9
                 result = null;
 55   
             }
 56   
         } else {
 57  526
             result = picoContainer.getComponentAdapterOfType(expectedType);
 58   
         }
 59  542
         return result;
 60   
     }
 61   
 
 62   
 }
 63