Source for java.rmi.server.RMIClassLoader

   1: /* RMIClassLoader.java --
   2:    Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003, 2004
   3:    Free Software Foundation, Inc.
   4: 
   5: This file is part of GNU Classpath.
   6: 
   7: GNU Classpath is free software; you can redistribute it and/or modify
   8: it under the terms of the GNU General Public License as published by
   9: the Free Software Foundation; either version 2, or (at your option)
  10: any later version.
  11: 
  12: GNU Classpath is distributed in the hope that it will be useful, but
  13: WITHOUT ANY WARRANTY; without even the implied warranty of
  14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15: General Public License for more details.
  16: 
  17: You should have received a copy of the GNU General Public License
  18: along with GNU Classpath; see the file COPYING.  If not, write to the
  19: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20: 02110-1301 USA.
  21: 
  22: Linking this library statically or dynamically with other modules is
  23: making a combined work based on this library.  Thus, the terms and
  24: conditions of the GNU General Public License cover the whole
  25: combination.
  26: 
  27: As a special exception, the copyright holders of this library give you
  28: permission to link this library with independent modules to produce an
  29: executable, regardless of the license terms of these independent
  30: modules, and to copy and distribute the resulting executable under
  31: terms of your choice, provided that you also meet, for each linked
  32: independent module, the terms and conditions of the license of that
  33: module.  An independent module is a module which is not derived from
  34: or based on this library.  If you modify this library, you may extend
  35: this exception to your version of the library, but you are not
  36: obligated to do so.  If you do not wish to do so, delete this
  37: exception statement from your version. */
  38: 
  39: package java.rmi.server;
  40: 
  41: import gnu.java.rmi.server.RMIClassLoaderImpl;
  42: 
  43: import java.net.MalformedURLException;
  44: import java.net.URL;
  45: 
  46: /**
  47:  * This class provides a set of public static utility methods for supporting
  48:  * network-based class loading in RMI. These methods are called by RMI's
  49:  * internal marshal streams to implement the dynamic class loading of types for
  50:  * RMI parameters and return values.
  51:  */
  52: public class RMIClassLoader
  53: {
  54:   /**
  55:    * This class isn't intended to be instantiated.
  56:    */
  57:   private RMIClassLoader() {}
  58: 
  59:   /**
  60:    * @deprecated
  61:    */
  62:   public static Class loadClass(String name)
  63:     throws MalformedURLException, ClassNotFoundException
  64:   {
  65:     return loadClass("", name);
  66:   }
  67: 
  68:   public static Class loadClass(String codebase, String name)
  69:     throws MalformedURLException, ClassNotFoundException
  70:   {
  71:     RMIClassLoaderSpi spi = getProviderInstance();
  72:     if (spi == null)
  73:       spi = getDefaultProviderInstance(); 
  74:     return spi.loadClass(codebase, name, null);
  75:   }
  76: 
  77:   public static Class loadClass(String codebase, String name,
  78:                                 ClassLoader defaultLoader)
  79:     throws MalformedURLException, ClassNotFoundException
  80:   {
  81:     RMIClassLoaderSpi spi = getProviderInstance();
  82:     if (spi == null)
  83:       spi = getDefaultProviderInstance(); 
  84:     return spi.loadClass(codebase, name, defaultLoader);
  85:   }
  86: 
  87:   /**
  88:    * Loads a class from <code>codeBase</code>.
  89:    *
  90:    * This method delegates to
  91:    * {@link RMIClassLoaderSpi#loadClass(String, String, ClassLoader)} and
  92:    * passes <code>codeBase.toString()</code> as first argument,
  93:    * <code>name</code> as second argument and <code>null</code> as third
  94:    * argument.
  95:    *
  96:    * @param codeBase the code base from which to load the class
  97:    * @param name the name of the class
  98:    *
  99:    * @return the loaded class
 100:    *
 101:    * @throws MalformedURLException if the URL is not well formed
 102:    * @throws ClassNotFoundException if the requested class cannot be found
 103:    */
 104:   public static Class loadClass(URL codeBase, String name)
 105:     throws MalformedURLException, ClassNotFoundException
 106:   {
 107:     RMIClassLoaderSpi spi = getProviderInstance();
 108:     if (spi == null)
 109:       spi = getDefaultProviderInstance(); 
 110:     return spi.loadClass(codeBase.toString(), name, null);
 111:   }
 112: 
 113:   /**
 114:    * Gets a classloader for the given codebase and with the current
 115:    * context classloader as parent.
 116:    * 
 117:    * @param codebase
 118:    * 
 119:    * @return a classloader for the given codebase
 120:    * 
 121:    * @throws MalformedURLException if the codebase contains a malformed URL
 122:    */
 123:   public static ClassLoader getClassLoader(String codebase) 
 124:     throws MalformedURLException
 125:   {
 126:     RMIClassLoaderSpi spi = getProviderInstance();
 127:     if (spi == null)
 128:       spi = getDefaultProviderInstance(); 
 129:     return spi.getClassLoader(codebase);
 130:   }
 131:  
 132:   /**
 133:    * Returns a string representation of the network location where a remote
 134:    * endpoint can get the class-definition of the given class.
 135:    *
 136:    * @param cl
 137:    *
 138:    * @return a space seperated list of URLs where the class-definition
 139:    * of cl may be found
 140:    */
 141:   public static String getClassAnnotation(Class cl)
 142:   {
 143:     RMIClassLoaderSpi spi = getProviderInstance();
 144:     if (spi == null)
 145:       spi = getDefaultProviderInstance(); 
 146:     return spi.getClassAnnotation(cl);
 147:   }
 148: 
 149:   /**
 150:    * @deprecated
 151:    */
 152:   public static Object getSecurityContext (ClassLoader loader)
 153:   {
 154:     throw new Error ("Not implemented");
 155:   }
 156: 
 157:   /**
 158:    * Returns the default service provider for <code>RMIClassLoader</code>.
 159:    *
 160:    * @return the default provider for <code>RMIClassLoader</code>
 161:    */
 162:   public static RMIClassLoaderSpi getDefaultProviderInstance()
 163:   {
 164:     return RMIClassLoaderImpl.getInstance();
 165:   }
 166: 
 167:   /**
 168:    * Chooses, instantiates and returns a service provider.
 169:    *
 170:    * @return a service provider
 171:    */
 172:   private static RMIClassLoaderSpi getProviderInstance()
 173:   {
 174:     // TODO: Do something more useful here.
 175:     return null;
 176:   }
 177: }