1 8 package org.codehaus.aspectwerkz.util; 9 10 import java.io.InputStream ; 11 import java.net.URL ; 12 13 18 public final class ContextClassLoader { 19 20 28 public static Class forName(final ClassLoader loader, final String name) throws ClassNotFoundException { 29 Class klass = null; 30 if (loader != null) { 31 klass = Class.forName(name, false, loader); 32 } else { 33 klass = Class.forName(name, false, ClassLoader.getSystemClassLoader()); 34 } 35 return klass; 36 } 37 38 39 46 public static Class forName(final String name) throws ClassNotFoundException { 47 Class cls = null; 48 try { 49 cls = Class.forName(name, false, Thread.currentThread().getContextClassLoader()); 50 } catch (Exception e) { 51 cls = Class.forName(name); 52 } 53 return cls; 54 } 55 56 62 public static URL loadResource(final String name) { 63 try { 64 return Thread.currentThread().getContextClassLoader().getResource(name); 65 } catch (Exception e) { 66 return ClassLoader .class.getClassLoader().getResource(name); 67 } 68 } 69 70 91 96 public static ClassLoader getLoader() { 97 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 98 if (loader == null) { 99 loader = ClassLoader .class.getClassLoader(); 100 } 101 return loader; 102 } 103 } | Popular Tags |