1 22 package org.jboss.mx.server; 23 24 import java.security.PrivilegedAction ; 25 import java.security.AccessController ; 26 27 31 interface TCLAction 32 { 33 class UTIL 34 { 35 static TCLAction getTCLAction() 36 { 37 return System.getSecurityManager() == null ? NON_PRIVILEGED : PRIVILEGED; 38 } 39 40 static ClassLoader getContextClassLoader() 41 { 42 return getTCLAction().getContextClassLoader(); 43 } 44 45 static ClassLoader getContextClassLoader(Thread thread) 46 { 47 return getTCLAction().getContextClassLoader(thread); 48 } 49 50 static void setContextClassLoader(ClassLoader cl) 51 { 52 getTCLAction().setContextClassLoader(cl); 53 } 54 55 static void setContextClassLoader(Thread thread, ClassLoader cl) 56 { 57 getTCLAction().setContextClassLoader(thread, cl); 58 } 59 } 60 61 TCLAction NON_PRIVILEGED = new TCLAction() 62 { 63 public ClassLoader getContextClassLoader() 64 { 65 return Thread.currentThread().getContextClassLoader(); 66 } 67 68 public ClassLoader getContextClassLoader(Thread thread) 69 { 70 return thread.getContextClassLoader(); 71 } 72 73 public void setContextClassLoader(ClassLoader cl) 74 { 75 Thread.currentThread().setContextClassLoader(cl); 76 } 77 78 public void setContextClassLoader(Thread thread, ClassLoader cl) 79 { 80 thread.setContextClassLoader(cl); 81 } 82 }; 83 84 TCLAction PRIVILEGED = new TCLAction() 85 { 86 private final PrivilegedAction getTCLPrivilegedAction = new PrivilegedAction () 87 { 88 public Object run() 89 { 90 return Thread.currentThread().getContextClassLoader(); 91 } 92 }; 93 94 public ClassLoader getContextClassLoader() 95 { 96 return (ClassLoader )AccessController.doPrivileged(getTCLPrivilegedAction); 97 } 98 99 public ClassLoader getContextClassLoader(final Thread thread) 100 { 101 return (ClassLoader )AccessController.doPrivileged(new PrivilegedAction () 102 { 103 public Object run() 104 { 105 return thread.getContextClassLoader(); 106 } 107 }); 108 } 109 110 public void setContextClassLoader(final ClassLoader cl) 111 { 112 AccessController.doPrivileged( 113 new PrivilegedAction () 114 { 115 public Object run() 116 { 117 Thread.currentThread().setContextClassLoader(cl); 118 return null; 119 } 120 } 121 ); 122 } 123 124 public void setContextClassLoader(final Thread thread, final ClassLoader cl) 125 { 126 AccessController.doPrivileged( 127 new PrivilegedAction () 128 { 129 public Object run() 130 { 131 thread.setContextClassLoader(cl); 132 return null; 133 } 134 } 135 ); 136 } 137 }; 138 139 ClassLoader getContextClassLoader(); 140 141 ClassLoader getContextClassLoader(Thread thread); 142 143 void setContextClassLoader(ClassLoader cl); 144 145 void setContextClassLoader(Thread thread, ClassLoader cl); 146 } 147 | Popular Tags |