1 package com.icl.saxon; 2 3 import java.lang.ClassNotFoundException ; 4 import java.lang.IllegalAccessException ; 5 import java.lang.InstantiationException ; 6 import java.lang.SecurityException ; 7 import java.lang.ClassCastException ; 8 9 import javax.xml.transform.TransformerException ; 10 11 12 18 19 20 public class Loader { 21 22 private static boolean tracing = false; 23 24 27 28 public synchronized static void setTracing(boolean onOrOff) { 29 tracing = onOrOff; 30 } 31 32 42 43 public static Class getClass(String className) throws TransformerException 44 { 45 if (tracing) { 46 System.err.println("Loading " + className); 47 } 48 if (Version.isPreJDK12()) { 49 try { 50 return Class.forName(className); 51 } 52 catch (Exception e) { 53 throw new TransformerException ("Failed to load " + className, e ); 54 } 55 } else { 56 57 try { 58 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 59 if (loader!=null) { 60 try { 61 return loader.loadClass(className); 62 } catch (Exception ex) { 63 return Class.forName(className); 64 } 65 } else { 66 return Class.forName(className); 67 } 68 } 69 catch (Exception e) { 70 throw new TransformerException ("Failed to load " + className, e ); 71 } 72 73 } 74 75 } 76 77 87 88 public static Object getInstance(String className) throws TransformerException { 89 Class theclass = getClass(className); 90 try { 91 return theclass.newInstance(); 92 } catch (Exception err) { 93 throw new TransformerException ("Failed to instantiate class " + className, err); 94 } 95 } 96 97 98 } 99 100 | Popular Tags |