Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
12   42   5   6
6   35   0.42   2
2     2.5  
1    
 
 
  ClassHelper       Line # 8 12 5 0% 0.0
 
No Tests
 
1    package com.atlassian.core.util;
2   
3    import com.atlassian.core.util.ClassLoaderUtils;
4   
5    import java.lang.reflect.Constructor;
6    import java.lang.reflect.InvocationTargetException;
7   
 
8    public class ClassHelper
9    {
 
10  0 toggle public static Object instantiateClass(Class clazz, Object[] constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
11    {
12  0 Class args[] = new Class[constructorArgs.length];
13  0 for (int i = 0; i < constructorArgs.length; i++)
14    {
15  0 if (constructorArgs == null)
16    {
17  0 args[i] = null;
18    }
19    else
20    {
21  0 args[i] = constructorArgs[i].getClass();
22    }
23    }
24  0 Constructor ctor = null;
25  0 if (clazz.getConstructors().length == 1)
26    {
27  0 ctor = clazz.getConstructors()[0];
28    } else {
29    //Obtaioning the ctor this way the class types need to be an exact match
30    //We could obtain the required behaviour by checkinng that our args are assignable
31    //for a given ctor... but I can't be bothered right now
32  0 ctor = clazz.getConstructor(args);
33    }
34  0 return ctor.newInstance(constructorArgs);
35    }
36   
 
37  0 toggle public static Object instantiateClass(String name, Object[] constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
38    {
39  0 Class clazz = ClassLoaderUtils.loadClass(name, ClassHelper.class);
40  0 return instantiateClass(clazz, constructorArgs);
41    }
42    }