KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > RemoteClassLoaderSpi


1 /*
2  * CoadunationBase: The base for a Coadunation instance.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * RemoteClassLoaderSpi.java
20  *
21  * This object implements the remote class loader.
22  */

23
24 // package path
25
package com.rift.coad;
26
27 // java imports
28
import java.net.MalformedURLException JavaDoc;
29 import java.rmi.server.RMIClassLoader JavaDoc;
30 import java.rmi.server.RMIClassLoaderSpi JavaDoc;
31
32 /**
33  * This object implements the remote class loader for coadunation.
34  *
35  * @author Brett Chaldecott
36  */

37 public class RemoteClassLoaderSpi extends RMIClassLoaderSpi JavaDoc {
38     
39     // private member variables
40
private RMIClassLoaderSpi JavaDoc delegate =
41             RMIClassLoader.getDefaultProviderInstance();
42     
43     /**
44      * Creates a new instance of RemoteClassLoaderSpi
45      */

46     public RemoteClassLoaderSpi() {
47     }
48     
49     
50     /**
51      * Load a proxy class to be used by RMI.
52      *
53      * @return The reference to the required proxy class.
54      * @param codeBase The code base for this object.
55      * @param interfaces The interface array to be loaded.
56      * @param default The class loader that would have been used by the JVM.
57      * @exception MalformedURLException
58      * @exception ClassNotFoundException
59      */

60     public Class JavaDoc loadProxyClass (String JavaDoc codebase, String JavaDoc[] interfaces,
61             ClassLoader JavaDoc defaultLoader) throws MalformedURLException JavaDoc,
62             ClassNotFoundException JavaDoc {
63         // use the thread context class loader.
64
return delegate.loadProxyClass(codebase,interfaces,
65                 Thread.currentThread().getContextClassLoader());
66     }
67     
68     
69     /**
70      * This method returns a reference to the loaded class using the thread
71      * context class loader.
72      *
73      * @return The class loaded from the appropriate class loader.
74      * @param codebase The code base to load from.
75      * @param name The name of the class to load.
76      * @param defaultLoader The loader that would have been used by the jvm
77      * @exception MalformedURLException
78      * @exception ClassNotFoundException
79      */

80     public Class JavaDoc loadClass(String JavaDoc codebase, String JavaDoc name,
81             ClassLoader JavaDoc defaultLoader) throws MalformedURLException JavaDoc,
82             ClassNotFoundException JavaDoc {
83         // use the thread context class loader.
84
return delegate.loadClass(codebase,name,
85                 Thread.currentThread().getContextClassLoader());
86     }
87     
88     
89     /**
90      * This method returns the appropriate class loader for the specified code
91      * base.
92      *
93      * @return The reference to the required class loader.
94      * @param codebase The code base for the class loader.
95      * @exception MalformedURLException
96      */

97     public ClassLoader JavaDoc getClassLoader(String JavaDoc codebase) throws
98             MalformedURLException JavaDoc {
99         return delegate.getClassLoader(codebase);
100     }
101     
102     
103     /**
104      * This method returns the annotation for the specified class
105      *
106      * @return The string containing the path to the class.
107      * @param cl The class to look up for.
108      */

109     public String JavaDoc getClassAnnotation(Class JavaDoc cl) {
110         String JavaDoc annotation = null;
111         try {
112             annotation = delegate.getClassAnnotation(cl);
113         } catch (Throwable JavaDoc ex) {
114             annotation = System.getProperty("java.rmi.server.codebase");
115         }
116         return annotation;
117     }
118 }
119
Popular Tags