1 8 package org.xml.sax.helpers; 9 10 import java.lang.reflect.Method ; 11 import java.lang.reflect.InvocationTargetException ; 12 13 34 class NewInstance { 35 36 41 static Object newInstance (ClassLoader classLoader, String className) 42 throws ClassNotFoundException , IllegalAccessException , 43 InstantiationException 44 { 45 Class driverClass; 46 if (classLoader == null) { 47 driverClass = Class.forName(className); 48 } else { 49 driverClass = classLoader.loadClass(className); 50 } 51 return driverClass.newInstance(); 52 } 53 54 58 static ClassLoader getClassLoader () 59 { 60 Method m = null; 61 62 try { 63 m = Thread .class.getMethod("getContextClassLoader", null); 64 } catch (NoSuchMethodException e) { 65 return NewInstance .class.getClassLoader(); 67 } 68 69 try { 70 return (ClassLoader ) m.invoke(Thread.currentThread(), null); 71 } catch (IllegalAccessException e) { 72 throw new UnknownError (e.getMessage()); 74 } catch (InvocationTargetException e) { 75 throw new UnknownError (e.getMessage()); 77 } 78 } 79 } 80 | Popular Tags |