Clover coverage report - PicoContainer - 1.0-alpha-2
Coverage timestamp: Thu Jul 10 2003 10:40:43 BST
file stats: LOC: 53   Methods: 3
NCLOC: 30   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
DefaultComponentFactory.java 100% 83.3% 100% 88.2%
coverage coverage
 1   
 /*****************************************************************************
 2   
  * Copyright (Cc) 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.html file.                                                    *
 7   
  *                                                                           *
 8   
  * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
 9   
  *****************************************************************************/
 10   
 
 11   
 package picocontainer.defaults;
 12   
 
 13   
 import picocontainer.ComponentFactory;
 14   
 import picocontainer.PicoIntrospectionException;
 15   
 
 16   
 import java.lang.reflect.Constructor;
 17   
 import java.lang.reflect.InvocationTargetException;
 18   
 
 19   
 /**
 20   
  * CompoentFactory that supports IoC type 3, which is constructor based.
 21   
  *
 22   
  * @author Aslak Hellesoy
 23   
  * @version $Revision: 1.8 $
 24   
  */
 25   
 public class DefaultComponentFactory implements ComponentFactory {
 26  66
     public Object createComponent(Class componentType, Class componentImplementation, Class[] dependencies, Object[] instanceDependencies) throws PicoInvocationTargetInitializationException, WrongNumberOfConstructorsException {
 27  66
         try {
 28  66
             Constructor constructor = getConstructor(componentImplementation);
 29  66
             return constructor.newInstance(instanceDependencies);
 30   
         } catch (InvocationTargetException e) {
 31  1
             throw new PicoInvocationTargetInitializationException(e.getCause());
 32   
         } catch (InstantiationException e) {
 33  0
             throw new RuntimeException(e);
 34   
         } catch (IllegalAccessException e) {
 35  0
             throw new RuntimeException(e);
 36   
         }
 37   
     }
 38   
 
 39  157
     public Class[] getDependencies(Class componentImplementation) throws PicoIntrospectionException {
 40  157
         Constructor constructor = getConstructor(componentImplementation);
 41  156
         return constructor.getParameterTypes();
 42   
     }
 43   
 
 44  223
     private Constructor getConstructor(Class componentImplementation) throws WrongNumberOfConstructorsException {
 45  223
         Constructor[] constructors = componentImplementation.getConstructors();
 46  223
         if (constructors.length != 1) {
 47  1
             throw new WrongNumberOfConstructorsException(constructors.length);
 48   
         }
 49   
         // Get the sole constructor
 50  222
         return componentImplementation.getConstructors()[0];
 51   
     }
 52   
 }
 53