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.test.util;
023:
024: import java.net.MalformedURLException;
025:
026: import java.rmi.server.RMIClassLoader;
027: import java.rmi.server.RMIClassLoaderSpi;
028: import java.util.Arrays;
029: import java.util.Collection;
030:
031: import org.jboss.logging.Logger;
032:
033: /**
034: * Logs RMI classloading activity
035: *
036: * @author <a href="mailto:adrian.brock@happeningtimes.com">Adrian Brock</a>
037: * @version $Revision: 57211 $
038: */
039: public class LoggingRMIClassLoader extends RMIClassLoaderSpi {
040: private static final Logger log = Logger
041: .getLogger(LoggingRMIClassLoader.class);
042:
043: // Attributes ----------------------------------------------------
044:
045: /**
046: * The JVM implementation (we delegate most work to it)
047: */
048: RMIClassLoaderSpi delegate = RMIClassLoader
049: .getDefaultProviderInstance();
050:
051: // Constructors --------------------------------------------------
052:
053: /**
054: * Required constructor
055: */
056: public LoggingRMIClassLoader() {
057: }
058:
059: // RMIClassLoaderSpi Implementation ------------------------------
060:
061: public Class loadProxyClass(String codebase, String[] interfaces,
062: ClassLoader cl) throws MalformedURLException,
063: ClassNotFoundException {
064: Collection c = null;
065: try {
066: if (interfaces != null)
067: c = Arrays.asList(interfaces);
068: Class result = delegate.loadProxyClass(codebase,
069: interfaces, cl);
070: log.debug("loadClass: codebase=" + codebase
071: + " interfaces=" + c + " cl=" + cl + " result="
072: + result);
073: return result;
074: } catch (MalformedURLException e) {
075: log.debug("loadClass: codebase=" + codebase
076: + " interfaces=" + c + " cl=" + cl, e);
077: throw e;
078: } catch (ClassNotFoundException e) {
079: log.debug("loadClass: codebase=" + codebase
080: + " interfaces=" + c + " cl=" + cl, e);
081: throw e;
082: }
083: }
084:
085: public Class loadClass(String codebase, String name, ClassLoader cl)
086: throws MalformedURLException, ClassNotFoundException {
087: try {
088: Class result = delegate.loadClass(codebase, name, cl);
089: log.debug("loadClass: codebase=" + codebase + " name="
090: + name + " cl=" + cl + " result=" + result);
091: return result;
092: } catch (MalformedURLException e) {
093: log.debug("loadClass: codebase=" + codebase + " name="
094: + name + " cl=" + cl, e);
095: throw e;
096: } catch (ClassNotFoundException e) {
097: log.debug("loadClass: codebase=" + codebase + " name="
098: + name + " cl=" + cl, e);
099: throw e;
100: }
101: }
102:
103: public ClassLoader getClassLoader(String codebase)
104: throws MalformedURLException {
105: try {
106: ClassLoader result = delegate.getClassLoader(codebase);
107: log.debug("getClassLoader: codebase=" + codebase
108: + " result=" + result);
109: return result;
110: } catch (MalformedURLException e) {
111: log.debug("getClassLoader: codebase=" + codebase, e);
112: throw e;
113: }
114: }
115:
116: public String getClassAnnotation(Class clazz) {
117: String result = delegate.getClassAnnotation(clazz);
118: log.debug("getClassAnnotation: class=" + clazz + " result="
119: + result);
120: return result;
121: }
122: }
|