1 22 package org.jboss.varia.scheduler; 23 24 import java.security.PrivilegedAction ; 25 import java.security.AccessController ; 26 27 33 class TCLActions 34 { 35 private static class GetTCLAction implements PrivilegedAction 36 { 37 static PrivilegedAction ACTION = new GetTCLAction(); 38 public Object run() 39 { 40 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 41 return loader; 42 } 43 } 44 private static class GetClassLoaderAction implements PrivilegedAction 45 { 46 Class c; 47 GetClassLoaderAction(Class c) 48 { 49 this.c = c; 50 } 51 public Object run() 52 { 53 ClassLoader loader = c.getClassLoader(); 54 c = null; 55 return loader; 56 } 57 } 58 private static class SetTCLAction implements PrivilegedAction 59 { 60 ClassLoader loader; 61 SetTCLAction(ClassLoader loader) 62 { 63 this.loader = loader; 64 } 65 public Object run() 66 { 67 Thread.currentThread().setContextClassLoader(loader); 68 loader = null; 69 return null; 70 } 71 } 72 73 static ClassLoader getContextClassLoader() 74 { 75 ClassLoader loader = (ClassLoader ) AccessController.doPrivileged(GetTCLAction.ACTION); 76 return loader; 77 } 78 static ClassLoader getClassLoader(Class c) 79 { 80 GetClassLoaderAction action = new GetClassLoaderAction(c); 81 ClassLoader loader = (ClassLoader ) AccessController.doPrivileged(action); 82 return loader; 83 } 84 static void setContextClassLoader(ClassLoader loader) 85 { 86 PrivilegedAction action = new SetTCLAction(loader); 87 AccessController.doPrivileged(action); 88 } 89 } 90 | Popular Tags |