001: /*
002: * CoadunationBase: The base for a Coadunation instance.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * RemoteClassLoaderSpi.java
020: *
021: * This object implements the remote class loader.
022: */
023:
024: // package path
025: package com.rift.coad;
026:
027: // java imports
028: import java.net.MalformedURLException;
029: import java.rmi.server.RMIClassLoader;
030: import java.rmi.server.RMIClassLoaderSpi;
031:
032: /**
033: * This object implements the remote class loader for coadunation.
034: *
035: * @author Brett Chaldecott
036: */
037: public class RemoteClassLoaderSpi extends RMIClassLoaderSpi {
038:
039: // private member variables
040: private RMIClassLoaderSpi delegate = RMIClassLoader
041: .getDefaultProviderInstance();
042:
043: /**
044: * Creates a new instance of RemoteClassLoaderSpi
045: */
046: public RemoteClassLoaderSpi() {
047: }
048:
049: /**
050: * Load a proxy class to be used by RMI.
051: *
052: * @return The reference to the required proxy class.
053: * @param codeBase The code base for this object.
054: * @param interfaces The interface array to be loaded.
055: * @param default The class loader that would have been used by the JVM.
056: * @exception MalformedURLException
057: * @exception ClassNotFoundException
058: */
059: public Class loadProxyClass(String codebase, String[] interfaces,
060: ClassLoader defaultLoader) throws MalformedURLException,
061: ClassNotFoundException {
062: // use the thread context class loader.
063: return delegate.loadProxyClass(codebase, interfaces, Thread
064: .currentThread().getContextClassLoader());
065: }
066:
067: /**
068: * This method returns a reference to the loaded class using the thread
069: * context class loader.
070: *
071: * @return The class loaded from the appropriate class loader.
072: * @param codebase The code base to load from.
073: * @param name The name of the class to load.
074: * @param defaultLoader The loader that would have been used by the jvm
075: * @exception MalformedURLException
076: * @exception ClassNotFoundException
077: */
078: public Class loadClass(String codebase, String name,
079: ClassLoader defaultLoader) throws MalformedURLException,
080: ClassNotFoundException {
081: // use the thread context class loader.
082: return delegate.loadClass(codebase, name, Thread
083: .currentThread().getContextClassLoader());
084: }
085:
086: /**
087: * This method returns the appropriate class loader for the specified code
088: * base.
089: *
090: * @return The reference to the required class loader.
091: * @param codebase The code base for the class loader.
092: * @exception MalformedURLException
093: */
094: public ClassLoader getClassLoader(String codebase)
095: throws MalformedURLException {
096: return delegate.getClassLoader(codebase);
097: }
098:
099: /**
100: * This method returns the annotation for the specified class
101: *
102: * @return The string containing the path to the class.
103: * @param cl The class to look up for.
104: */
105: public String getClassAnnotation(Class cl) {
106: String annotation = null;
107: try {
108: annotation = delegate.getClassAnnotation(cl);
109: } catch (Throwable ex) {
110: annotation = System.getProperty("java.rmi.server.codebase");
111: }
112: return annotation;
113: }
114: }
|