1 20 package org.apache.cactus.internal.util; 21 22 import java.util.Locale ; 23 import java.util.MissingResourceException ; 24 import java.util.PropertyResourceBundle ; 25 import java.util.ResourceBundle ; 26 27 32 public class ClassLoaderUtils 33 { 34 46 public static Class loadClass(String theClassName, Class theReferrer) 47 throws ClassNotFoundException 48 { 49 Class clazz = null; 51 52 try 53 { 54 clazz = loadClassFromWebappClassLoader(theClassName, theReferrer); 56 } 57 catch (Throwable internalException) 58 { 59 clazz = loadClassFromContextClassLoader(theClassName); 62 } 63 64 return clazz; 65 } 66 67 75 public static Class loadClassFromContextClassLoader(String theClassName) 76 throws ClassNotFoundException 77 { 78 return Class.forName(theClassName, true, 79 Thread.currentThread().getContextClassLoader()); 80 } 81 82 92 public static Class loadClassFromWebappClassLoader(String theClassName, 93 Class theReferrer) throws ClassNotFoundException 94 { 95 return Class.forName(theClassName, true, theReferrer.getClassLoader()); 96 } 97 98 107 public static ResourceBundle loadPropertyResourceBundle(String theName, 108 Class theReferrer) 109 { 110 ResourceBundle bundle; 111 112 try 113 { 114 116 if (theReferrer.getClassLoader() == null) 121 { 122 bundle = PropertyResourceBundle.getBundle(theName, 123 Locale.getDefault()); 124 } 125 else 126 { 127 bundle = PropertyResourceBundle.getBundle(theName, 128 Locale.getDefault(), theReferrer.getClassLoader()); 129 } 130 } 131 catch (MissingResourceException e) 132 { 133 bundle = PropertyResourceBundle.getBundle(theName, 135 Locale.getDefault(), 136 Thread.currentThread().getContextClassLoader()); 137 } 138 139 return bundle; 140 } 141 } 142 | Popular Tags |