Clover coverage report - PicoContainer - 1.0-alpha-2
Coverage timestamp: Thu Jul 10 2003 10:40:43 BST
file stats: LOC: 74   Methods: 6
NCLOC: 48   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
ComponentSpecification.java 87.5% 95% 100% 94.1%
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.txt 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.PicoInstantiationException;
 15   
 import picocontainer.PicoIntrospectionException;
 16   
 
 17   
 import java.util.Arrays;
 18   
 
 19   
 class ComponentSpecification {
 20   
     private ComponentFactory componentFactory;
 21   
     private final Class compType;
 22   
     private final Class comp;
 23   
     private Parameter[] parameters;
 24   
 
 25  85
     public ComponentSpecification(ComponentFactory componentFactory, final Class compType, final Class comp, Parameter[] parameters) {
 26  85
         this.componentFactory = componentFactory;
 27  85
         this.compType = compType;
 28  85
         this.comp = comp;
 29  85
         this.parameters = parameters;
 30   
     }
 31   
 
 32  275
     public Class getComponentType() {
 33  275
         return compType;
 34   
     }
 35   
 
 36  43
     public Class getComponentImplementation() {
 37  43
         return comp;
 38   
     }
 39   
 
 40  70
     public Object instantiateComponent(DefaultPicoContainer picoContainer)
 41   
             throws PicoInstantiationException, PicoIntrospectionException {
 42  70
         Class[] dependencyTypes = componentFactory.getDependencies(comp);
 43  70
         Object[] dependencies = new Object[dependencyTypes.length];
 44  70
         for (int i = 0; i < dependencies.length; i++) {
 45  53
             dependencies[i] = parameters[i].resolve(picoContainer, this, dependencyTypes[i]);
 46   
         }
 47  67
         return componentFactory.createComponent(compType, comp, dependencyTypes, dependencies);
 48   
     }
 49   
 
 50  15
     static boolean isAssignableFrom(Class actual, Class requested) {
 51  15
         if (actual == Integer.TYPE || actual == Integer.class) {
 52  6
             return requested == Integer.TYPE || requested == Integer.class;
 53   
         }
 54   
 
 55   
         // TODO handle the rest of the primitive types in the same way (Java really sucks concerning this!)
 56   
 
 57  9
         return actual.isAssignableFrom(requested);
 58   
     }
 59   
 
 60  7
     public void addConstantParameterBasedOnType(Class componentType, Class parameter, Object arg) throws PicoIntrospectionException {
 61   
         // TODO this is an ugly hack and the feature should simply be removed
 62  7
         Class[] dependencies = componentFactory.getDependencies(comp);
 63  11
         for (int i = 0; i < dependencies.length; i++) {
 64   
 
 65  11
             if (isAssignableFrom(dependencies[i], parameter) && !(parameters[i] instanceof ConstantParameter)) {
 66  7
                 parameters[i] = new ConstantParameter(arg);
 67  7
                 return;
 68   
             }
 69   
         }
 70   
 
 71  0
         throw new RuntimeException("No such parameter " + parameter + " in " + Arrays.asList(dependencies));
 72   
     }
 73   
 }
 74