1 package com.wikihouse.wildcats0201.jdbcchart.reflectionutil; 2 3 import java.lang.reflect.Constructor; 4 import java.lang.reflect.InvocationTargetException; 5 6 /*** 7 * <B>ReflectionUtil </B>. 8 * 9 * @deprecated 10 * @author wildcats 11 */ 12 public final class ReflectionUtil { 13 14 private ReflectionUtil() { 15 } 16 17 public static ClassWrapper forName(String className) { 18 Class clazz = null; 19 try { 20 clazz = Class.forName(className); 21 } catch (ClassNotFoundException e) { 22 throw new RuntimeException(getExceptionName(e) + "/" + className); 23 } 24 return new ClassWrapper(clazz); 25 } 26 27 public static ConstructorWrapper getConstructor(ClassWrapper clazz, 28 ClassArrayWrapper args) { 29 Constructor constructor = null; 30 try { 31 constructor = clazz.get().getConstructor(args.get()); 32 } catch (SecurityException e) { 33 throw new RuntimeException(getExceptionName(e) + "/" + clazz + "/" 34 + args); 35 } catch (NoSuchMethodException e) { 36 throw new RuntimeException(getExceptionName(e) + "/" + clazz + "/" 37 + args); 38 } 39 return new ConstructorWrapper(constructor); 40 } 41 42 public static Object newInstance(ConstructorWrapper constructor, 43 ObjectArrayWrapper objects) { 44 Object obj = null; 45 try { 46 obj = constructor.get().newInstance(objects.get()); 47 } catch (IllegalArgumentException e) { 48 throw new RuntimeException(e); 49 } catch (InstantiationException e) { 50 throw new RuntimeException(e); 51 } catch (IllegalAccessException e) { 52 throw new RuntimeException(e); 53 } catch (InvocationTargetException e) { 54 throw new RuntimeException(e.getTargetException()); 55 } 56 return obj; 57 } 58 59 private static String getExceptionName(Exception e) { 60 return e.getClass().getName(); 61 } 62 63 }