1 22 package org.jboss.util.loading; 23 24 import java.security.AccessController ; 25 import java.security.PrivilegedAction ; 26 27 37 public class ContextClassLoader 38 { 39 42 public static final RuntimePermission GETCLASSLOADER = new RuntimePermission ("getClassLoader"); 43 44 47 public static final NewInstance INSTANTIATOR = new NewInstance(); 48 49 54 ContextClassLoader() 55 { 56 SecurityManager manager = System.getSecurityManager(); 57 if (manager != null) 58 { 59 manager.checkPermission(GETCLASSLOADER); 60 } 61 } 62 63 68 public ClassLoader getContextClassLoader() 69 { 70 return getContextClassLoader(Thread.currentThread()); 71 } 72 73 79 public ClassLoader getContextClassLoader(final Thread thread) 80 { 81 return (ClassLoader ) AccessController.doPrivileged(new PrivilegedAction () 82 { 83 public Object run() 84 { 85 return thread.getContextClassLoader(); 86 } 87 }); 88 } 89 90 private static class NewInstance 91 implements PrivilegedAction 92 { 93 public Object run() 94 { 95 return new ContextClassLoader(); 96 } 97 } 98 } 99 | Popular Tags |