KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > util > LoggingRMIClassLoader


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.test.util;
23
24 import java.net.MalformedURLException JavaDoc;
25
26 import java.rmi.server.RMIClassLoader JavaDoc;
27 import java.rmi.server.RMIClassLoaderSpi JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.Collection JavaDoc;
30
31 import org.jboss.logging.Logger;
32
33 /**
34  * Logs RMI classloading activity
35  *
36  * @author <a HREF="mailto:adrian.brock@happeningtimes.com">Adrian Brock</a>
37  * @version $Revision: 37406 $
38  */

39 public class LoggingRMIClassLoader
40    extends RMIClassLoaderSpi JavaDoc
41 {
42    private static final Logger log = Logger.getLogger(LoggingRMIClassLoader.class);
43    
44    // Attributes ----------------------------------------------------
45

46    /**
47     * The JVM implementation (we delegate most work to it)
48     */

49    RMIClassLoaderSpi JavaDoc delegate = RMIClassLoader.getDefaultProviderInstance();
50    
51    // Constructors --------------------------------------------------
52

53    /**
54     * Required constructor
55     */

56    public LoggingRMIClassLoader()
57    {
58    }
59    
60    // RMIClassLoaderSpi Implementation ------------------------------
61

62    public Class JavaDoc loadProxyClass(String JavaDoc codebase, String JavaDoc[] interfaces, ClassLoader JavaDoc cl)
63       throws MalformedURLException JavaDoc, ClassNotFoundException JavaDoc
64    {
65       Collection JavaDoc c = null;
66       try
67       {
68          if (interfaces != null)
69             c = Arrays.asList(interfaces);
70          Class JavaDoc result = delegate.loadProxyClass(codebase, interfaces, cl);
71          log.debug("loadClass: codebase=" + codebase + " interfaces=" + c + " cl=" + cl + " result=" + result);
72          return result;
73       }
74       catch (MalformedURLException JavaDoc e)
75       {
76          log.debug("loadClass: codebase=" + codebase + " interfaces=" + c + " cl=" + cl, e);
77          throw e;
78       }
79       catch (ClassNotFoundException JavaDoc e)
80       {
81          log.debug("loadClass: codebase=" + codebase + " interfaces=" + c + " cl=" + cl, e);
82          throw e;
83       }
84    }
85
86    public Class JavaDoc loadClass(String JavaDoc codebase, String JavaDoc name, ClassLoader JavaDoc cl)
87       throws MalformedURLException JavaDoc, ClassNotFoundException JavaDoc
88    {
89       try
90       {
91          Class JavaDoc result = delegate.loadClass(codebase, name, cl);
92          log.debug("loadClass: codebase=" + codebase + " name=" + name + " cl=" + cl + " result=" + result);
93          return result;
94       }
95       catch (MalformedURLException JavaDoc e)
96       {
97          log.debug("loadClass: codebase=" + codebase + " name=" + name + " cl=" + cl, e);
98          throw e;
99       }
100       catch (ClassNotFoundException JavaDoc e)
101       {
102          log.debug("loadClass: codebase=" + codebase + " name=" + name + " cl=" + cl, e);
103          throw e;
104       }
105    }
106
107    public ClassLoader JavaDoc getClassLoader(String JavaDoc codebase)
108       throws MalformedURLException JavaDoc
109    {
110       try
111       {
112          ClassLoader JavaDoc result = delegate.getClassLoader(codebase);
113          log.debug("getClassLoader: codebase=" + codebase + " result=" + result);
114          return result;
115       }
116       catch (MalformedURLException JavaDoc e)
117       {
118          log.debug("getClassLoader: codebase=" + codebase, e);
119          throw e;
120       }
121    }
122
123    public String JavaDoc getClassAnnotation(Class JavaDoc clazz)
124    {
125       String JavaDoc result = delegate.getClassAnnotation(clazz);
126       log.debug("getClassAnnotation: class=" + clazz + " result=" + result);
127       return result;
128    }
129 }
130
Popular Tags