1 55 package org.jboss.axis.utils; 56 57 import java.io.InputStream ; 58 import java.security.AccessController ; 59 import java.security.PrivilegedAction ; 60 61 66 public final class ClassUtils 67 { 68 71 76 public static void setClassLoader(String className, ClassLoader loader) 77 { 78 } 82 83 90 public static ClassLoader getClassLoader(String className) 91 { 92 return null; 96 } 97 98 103 public static void removeClassLoader(String className) 104 { 105 } 108 109 110 117 public static Class forName(String className) 118 throws ClassNotFoundException 119 { 120 return loadClass(className); 121 } 122 123 125 public static Class forName(String _className, boolean init, ClassLoader _loader) 126 throws ClassNotFoundException 127 { 128 129 final String className = _className; 131 final ClassLoader loader = _loader; 132 try 133 { 134 Object ret = 136 AccessController.doPrivileged(new PrivilegedAction () 137 { 138 public Object run() 139 { 140 try 141 { 142 return Class.forName(className, true, loader); 143 } 144 catch (Throwable e) 145 { 146 return e; 147 } 148 } 149 }); 150 if (ret instanceof Class ) 152 { 153 return (Class )ret; 154 } 155 else if (ret instanceof ClassNotFoundException ) 156 { 157 throw (ClassNotFoundException )ret; 158 } 159 else 160 { 161 throw new ClassNotFoundException (_className); 162 } 163 } 164 catch (ClassNotFoundException cnfe) 165 { 166 return loadClass(className); 167 } 168 } 169 170 172 private static Class loadClass(String _className) 173 throws ClassNotFoundException 174 { 175 final String className = _className; 177 178 Object ret = 180 AccessController.doPrivileged(new PrivilegedAction () 181 { 182 public Object run() 183 { 184 try 185 { 186 ClassLoader classLoader = getClassLoader(className); 189 return Class.forName(className, true, classLoader); 190 } 191 catch (ClassNotFoundException cnfe) 192 { 193 } 194 195 try 196 { 197 ClassLoader classLoader = 199 Thread.currentThread().getContextClassLoader(); 200 return Class.forName(className, true, classLoader); 201 } 202 catch (ClassNotFoundException cnfe2) 203 { 204 try 205 { 206 ClassLoader classLoader = 208 ClassUtils.class.getClassLoader(); 209 return Class.forName(className, true, classLoader); 210 } 211 catch (ClassNotFoundException cnfe3) 212 { 213 try 215 { 216 return Class.forName(className); 217 } 218 catch (Throwable e) 219 { 220 return e; 222 } 223 } 224 } 225 } 226 }); 227 228 if (ret instanceof Class ) 230 { 231 return (Class )ret; 232 } 233 else if (ret instanceof ClassNotFoundException ) 234 { 235 throw (ClassNotFoundException )ret; 236 } 237 else 238 { 239 throw new ClassNotFoundException (_className); 240 } 241 } 242 243 public static InputStream getResourceAsStream(Class clazz, String resource) 244 { 245 InputStream myInputStream = null; 246 247 if (clazz.getClassLoader() != null) 248 { 249 myInputStream = clazz.getClassLoader().getResourceAsStream(resource); 251 } 252 else 253 { 254 myInputStream = ClassLoader.getSystemClassLoader().getResourceAsStream(resource); 256 } 257 if (myInputStream == null) 258 { 259 myInputStream = clazz.getResourceAsStream(resource); 261 } 262 return myInputStream; 263 } 264 } 265 | Popular Tags |