KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > server > TCLAction


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mx.server;
23
24 import java.security.PrivilegedAction JavaDoc;
25 import java.security.AccessController JavaDoc;
26
27 /**
28  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
29  * @version <tt>$Revision: 37459 $</tt>
30  */

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 JavaDoc getContextClassLoader()
41       {
42          return getTCLAction().getContextClassLoader();
43       }
44
45       static ClassLoader JavaDoc getContextClassLoader(Thread JavaDoc thread)
46       {
47          return getTCLAction().getContextClassLoader(thread);
48       }
49
50       static void setContextClassLoader(ClassLoader JavaDoc cl)
51       {
52          getTCLAction().setContextClassLoader(cl);
53       }
54
55       static void setContextClassLoader(Thread JavaDoc thread, ClassLoader JavaDoc cl)
56       {
57          getTCLAction().setContextClassLoader(thread, cl);
58       }
59    }
60
61    TCLAction NON_PRIVILEGED = new TCLAction()
62    {
63       public ClassLoader JavaDoc getContextClassLoader()
64       {
65          return Thread.currentThread().getContextClassLoader();
66       }
67
68       public ClassLoader JavaDoc getContextClassLoader(Thread JavaDoc thread)
69       {
70          return thread.getContextClassLoader();
71       }
72
73       public void setContextClassLoader(ClassLoader JavaDoc cl)
74       {
75          Thread.currentThread().setContextClassLoader(cl);
76       }
77
78       public void setContextClassLoader(Thread JavaDoc thread, ClassLoader JavaDoc cl)
79       {
80          thread.setContextClassLoader(cl);
81       }
82    };
83
84    TCLAction PRIVILEGED = new TCLAction()
85    {
86       private final PrivilegedAction JavaDoc getTCLPrivilegedAction = new PrivilegedAction JavaDoc()
87       {
88          public Object JavaDoc run()
89          {
90             return Thread.currentThread().getContextClassLoader();
91          }
92       };
93
94       public ClassLoader JavaDoc getContextClassLoader()
95       {
96          return (ClassLoader JavaDoc)AccessController.doPrivileged(getTCLPrivilegedAction);
97       }
98
99       public ClassLoader JavaDoc getContextClassLoader(final Thread JavaDoc thread)
100       {
101          return (ClassLoader JavaDoc)AccessController.doPrivileged(new PrivilegedAction JavaDoc()
102          {
103             public Object JavaDoc run()
104             {
105                return thread.getContextClassLoader();
106             }
107          });
108       }
109
110       public void setContextClassLoader(final ClassLoader JavaDoc cl)
111       {
112          AccessController.doPrivileged(
113             new PrivilegedAction JavaDoc()
114             {
115                public Object JavaDoc run()
116                {
117                   Thread.currentThread().setContextClassLoader(cl);
118                   return null;
119                }
120             }
121          );
122       }
123
124       public void setContextClassLoader(final Thread JavaDoc thread, final ClassLoader JavaDoc cl)
125       {
126          AccessController.doPrivileged(
127             new PrivilegedAction JavaDoc()
128             {
129                public Object JavaDoc run()
130                {
131                   thread.setContextClassLoader(cl);
132                   return null;
133                }
134             }
135          );
136       }
137    };
138
139    ClassLoader JavaDoc getContextClassLoader();
140
141    ClassLoader JavaDoc getContextClassLoader(Thread JavaDoc thread);
142
143    void setContextClassLoader(ClassLoader JavaDoc cl);
144
145    void setContextClassLoader(Thread JavaDoc thread, ClassLoader JavaDoc cl);
146 }
147
Popular Tags