001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mx.server;
023:
024: import java.security.PrivilegedAction;
025: import java.security.AccessController;
026:
027: /**
028: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
029: * @version <tt>$Revision: 57200 $</tt>
030: */
031: interface TCLAction {
032: class UTIL {
033: static TCLAction getTCLAction() {
034: return System.getSecurityManager() == null ? NON_PRIVILEGED
035: : PRIVILEGED;
036: }
037:
038: static ClassLoader getContextClassLoader() {
039: return getTCLAction().getContextClassLoader();
040: }
041:
042: static ClassLoader getContextClassLoader(Thread thread) {
043: return getTCLAction().getContextClassLoader(thread);
044: }
045:
046: static void setContextClassLoader(ClassLoader cl) {
047: getTCLAction().setContextClassLoader(cl);
048: }
049:
050: static void setContextClassLoader(Thread thread, ClassLoader cl) {
051: getTCLAction().setContextClassLoader(thread, cl);
052: }
053: }
054:
055: TCLAction NON_PRIVILEGED = new TCLAction() {
056: public ClassLoader getContextClassLoader() {
057: return Thread.currentThread().getContextClassLoader();
058: }
059:
060: public ClassLoader getContextClassLoader(Thread thread) {
061: return thread.getContextClassLoader();
062: }
063:
064: public void setContextClassLoader(ClassLoader cl) {
065: Thread.currentThread().setContextClassLoader(cl);
066: }
067:
068: public void setContextClassLoader(Thread thread, ClassLoader cl) {
069: thread.setContextClassLoader(cl);
070: }
071: };
072:
073: TCLAction PRIVILEGED = new TCLAction() {
074: private final PrivilegedAction getTCLPrivilegedAction = new PrivilegedAction() {
075: public Object run() {
076: return Thread.currentThread().getContextClassLoader();
077: }
078: };
079:
080: public ClassLoader getContextClassLoader() {
081: return (ClassLoader) AccessController
082: .doPrivileged(getTCLPrivilegedAction);
083: }
084:
085: public ClassLoader getContextClassLoader(final Thread thread) {
086: return (ClassLoader) AccessController
087: .doPrivileged(new PrivilegedAction() {
088: public Object run() {
089: return thread.getContextClassLoader();
090: }
091: });
092: }
093:
094: public void setContextClassLoader(final ClassLoader cl) {
095: AccessController.doPrivileged(new PrivilegedAction() {
096: public Object run() {
097: Thread.currentThread().setContextClassLoader(cl);
098: return null;
099: }
100: });
101: }
102:
103: public void setContextClassLoader(final Thread thread,
104: final ClassLoader cl) {
105: AccessController.doPrivileged(new PrivilegedAction() {
106: public Object run() {
107: thread.setContextClassLoader(cl);
108: return null;
109: }
110: });
111: }
112: };
113:
114: ClassLoader getContextClassLoader();
115:
116: ClassLoader getContextClassLoader(Thread thread);
117:
118: void setContextClassLoader(ClassLoader cl);
119:
120: void setContextClassLoader(Thread thread, ClassLoader cl);
121: }
|