//throws ClassNotFoundException, IllegalAccessException, // InstantiationException /** * Creates a new instance of the specified class name * * Package private so this code is not exposed at the API level. */ internal static Object newInstance(java.lang.ClassLoader classLoader, String className) { java.lang.Class driverClass; if (classLoader == null) { driverClass = java.lang.Class.forName(className); } else { driverClass = classLoader.loadClass(className); } return driverClass.newInstance(); }
//throws ConfigurationError /** * Create an instance of a class using the specified ClassLoader and * optionally fall back to the current ClassLoader if not found. * * @param className Name of the concrete class corresponding to the * service provider * * @param cl ClassLoader to use to load the class, null means to use * the bootstrap ClassLoader * * @param doFallback true if the current ClassLoader should be tried as * a fallback if the class is not found using cl */ internal static Object newInstance(String className, java.lang.ClassLoader cl, bool doFallback) { // assert(className != null); try { java.lang.Class providerClass; if (cl == null) { // If classloader is null Use the bootstrap ClassLoader. // Thus Class.forName(String) will use the current // ClassLoader which will be the bootstrap ClassLoader. providerClass = java.lang.Class.forName (className); } else { try { providerClass = cl.loadClass (className); } catch (java.lang.ClassNotFoundException x) { if (doFallback) { // Fall back to current classloader cl = typeof(FactoryFinder).getClass ().getClassLoader (); if (cl != null) { providerClass = cl.loadClass (className); } else { providerClass = java.lang.Class.forName (className); } } else { throw x; } } } Object instance = providerClass.newInstance (); if (debug) dPrint ("created new instance of " + providerClass + " using ClassLoader: " + cl); return instance; } catch (java.lang.ClassNotFoundException x) { throw new ConfigurationError ( "Provider " + className + " not found", x); } catch (java.lang.Exception x) { throw new ConfigurationError ( "Provider " + className + " could not be instantiated: " + x, x); } }