1 21 22 package org.apache.derby.iapi.services.loader; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.InvocationTargetException ; 26 27 public class ClassInfo implements InstanceGetter { 28 29 private static final Class [] noParameters = new Class [0]; 30 private static final Object [] noArguments = new Object [0]; 31 32 private final Class clazz; 33 private boolean useConstructor = true; 34 private Constructor noArgConstructor; 35 36 public ClassInfo(Class clazz) { 37 this.clazz = clazz; 38 } 39 40 43 public final String getClassName() { 44 return clazz.getName(); 45 } 46 47 51 public final Class getClassObject() { 52 53 return clazz; 54 } 55 56 67 public Object getNewInstance() 68 throws InstantiationException , IllegalAccessException , InvocationTargetException { 69 70 if (!useConstructor) { 71 72 return clazz.newInstance(); 73 } 74 75 if (noArgConstructor == null) { 76 77 try { 78 noArgConstructor = clazz.getConstructor(noParameters); 79 80 } catch (NoSuchMethodException nsme) { 81 useConstructor = false; 83 return getNewInstance(); 84 85 } catch (SecurityException se) { 86 useConstructor = false; 89 return getNewInstance(); 90 } 91 } 92 93 try { 94 return noArgConstructor.newInstance(noArguments); 95 } catch (IllegalArgumentException iae) { 96 return null; 98 } 99 } 100 } 101 | Popular Tags |