1 11 package org.jivesoftware.util; 12 13 import java.io.InputStream ; 14 15 27 public class ClassUtils { 28 29 private static ClassUtils instance = new ClassUtils(); 30 31 38 public static Class forName(String className) throws ClassNotFoundException { 39 return instance.loadClass(className); 40 } 41 42 48 public static InputStream getResourceAsStream(String name) { 49 return instance.loadResource(name); 50 } 51 52 55 private ClassUtils() {} 56 57 public Class loadClass(String className) throws ClassNotFoundException { 58 Class theClass = null; 59 try { 60 theClass = Class.forName(className); 61 } 62 catch (ClassNotFoundException e1) { 63 try { 64 theClass = Thread.currentThread().getContextClassLoader().loadClass(className); 65 } 66 catch (ClassNotFoundException e2) { 67 theClass = getClass().getClassLoader().loadClass(className); 68 } 69 } 70 return theClass; 71 } 72 73 private InputStream loadResource(String name) { 74 InputStream in = getClass().getResourceAsStream(name); 75 if (in == null) { 76 in = Thread.currentThread().getContextClassLoader().getResourceAsStream(name); 77 if (in == null) { 78 in = getClass().getClassLoader().getResourceAsStream(name); 79 } 80 } 81 return in; 82 } 83 } 84 | Popular Tags |