1 23 package org.mdarad.framework.util; 24 25 import java.lang.reflect.Constructor ; 26 import java.lang.reflect.InvocationTargetException ; 27 28 36 public class ClassUtils { 37 38 48 public static Object getInstance(Class type, Class [] constructorArgTypes, Object [] constructorArgs) 49 throws ClassUtilsException { 50 if (type == null) { 51 throw new IllegalArgumentException ("The type should never be null"); 52 } 53 Object object = null; 54 try { 55 Constructor constructor = 56 type.getConstructor(constructorArgTypes); 57 object = constructor.newInstance(constructorArgs); 58 } catch (NoSuchMethodException nsme) { 59 throw new ClassUtilsException("Constructor could not be found", nsme); 60 } catch (InstantiationException ie) { 61 throw new ClassUtilsException("Instance could not be created", ie); 62 } catch (IllegalAccessException ie) { 63 throw new ClassUtilsException("Instance could not be created", ie); 64 } catch (InvocationTargetException ie) { 65 throw new ClassUtilsException("Instance could not be created", ie); 66 } 67 return object; 68 } 69 } 70 | Popular Tags |