001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.jaxws.util;
021:
022: import java.security.PrivilegedActionException;
023: import java.security.PrivilegedExceptionAction;
024:
025: import org.apache.axis2.java.security.AccessController;
026: import org.apache.axis2.jaxws.ExceptionFactory;
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: public class ClassLoaderUtils {
031:
032: private static final Log log = LogFactory
033: .getLog(ClassLoaderUtils.class);
034:
035: private ClassLoaderUtils() {
036: }
037:
038: /** @return ClassLoader */
039: public static ClassLoader getClassLoader(final Class cls) {
040: ClassLoader cl = null;
041: try {
042: cl = (ClassLoader) AccessController
043: .doPrivileged(new PrivilegedExceptionAction() {
044: public Object run()
045: throws ClassNotFoundException {
046: return cls.getClassLoader();
047: }
048: });
049: } catch (PrivilegedActionException e) {
050: if (log.isDebugEnabled()) {
051: log.debug("Exception thrown from AccessController: "
052: + e);
053: }
054: throw ExceptionFactory.makeWebServiceException(e
055: .getException());
056: }
057:
058: return cl;
059: }
060:
061: /** @return ClassLoader */
062: public static ClassLoader getContextClassLoader() {
063: ClassLoader cl = null;
064: try {
065: cl = (ClassLoader) AccessController
066: .doPrivileged(new PrivilegedExceptionAction() {
067: public Object run()
068: throws ClassNotFoundException {
069: return Thread.currentThread()
070: .getContextClassLoader();
071: }
072: });
073: } catch (PrivilegedActionException e) {
074: if (log.isDebugEnabled()) {
075: log.debug("Exception thrown from AccessController: "
076: + e.getMessage(), e);
077: }
078: throw ExceptionFactory.makeWebServiceException(e
079: .getException());
080: }
081:
082: return cl;
083: }
084:
085: /**
086: * Return the class for this name
087: *
088: * @return Class
089: */
090: public static Class forName(final String className,
091: final boolean initialize, final ClassLoader classloader)
092: throws ClassNotFoundException {
093: Class cl = null;
094: try {
095: cl = (Class) AccessController
096: .doPrivileged(new PrivilegedExceptionAction() {
097: public Object run()
098: throws ClassNotFoundException {
099: return Class.forName(className, initialize,
100: classloader);
101: }
102: });
103: } catch (PrivilegedActionException e) {
104: if (log.isDebugEnabled()) {
105: log.debug("Exception thrown from AccessController: "
106: + e.getMessage(), e);
107: }
108: throw (ClassNotFoundException) e.getException();
109: }
110:
111: return cl;
112: }
113:
114: /**
115: * Return the class for this name
116: *
117: * @return Class
118: */
119: public static Class forName(final String className)
120: throws ClassNotFoundException {
121: Class cl = null;
122: try {
123: cl = (Class) AccessController
124: .doPrivileged(new PrivilegedExceptionAction() {
125: public Object run()
126: throws ClassNotFoundException {
127: return Class.forName(className);
128: }
129: });
130: } catch (PrivilegedActionException e) {
131: if (log.isDebugEnabled()) {
132: log.debug("Exception thrown from AccessController: "
133: + e.getMessage(), e);
134: }
135: throw (ClassNotFoundException) e.getException();
136: }
137:
138: return cl;
139: }
140:
141: }
|