1. /*
  2. * @(#)RMIClassLoaderSpi.java 1.11 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.rmi.server;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. /**
  11. * <code>RMIClassLoaderSpi</code> is the service provider interface for
  12. * <code>RMIClassLoader</code>.
  13. *
  14. * In particular, an <code>RMIClassLoaderSpi</code> instance provides an
  15. * implementation of the following static methods of
  16. * <code>RMIClassLoader</code>:
  17. *
  18. * <ul>
  19. *
  20. * <li>{@link RMIClassLoader#loadClass(URL,String)}
  21. * <li>{@link RMIClassLoader#loadClass(String,String)}
  22. * <li>{@link RMIClassLoader#loadClass(String,String,ClassLoader)}
  23. * <li>{@link RMIClassLoader#loadProxyClass(String,String[],ClassLoader)}
  24. * <li>{@link RMIClassLoader#getClassLoader(String)}
  25. * <li>{@link RMIClassLoader#getClassAnnotation(Class)}
  26. *
  27. * </ul>
  28. *
  29. * When one of those methods is invoked, its behavior is to delegate
  30. * to a corresponding method on an instance of this class.
  31. * The details of how each method delegates to the provider instance is
  32. * described in the documentation for each particular method.
  33. * See the documentation for {@link RMIClassLoader} for a description
  34. * of how a provider instance is chosen.
  35. *
  36. * @version 1.11, 03/01/23
  37. * @author Peter Jones
  38. * @author Laird Dornin
  39. * @see RMIClassLoader
  40. * @since JDK1.4
  41. */
  42. public abstract class RMIClassLoaderSpi {
  43. /**
  44. * Provides the implementation for
  45. * {@link RMIClassLoader#loadClass(URL,String)},
  46. * {@link RMIClassLoader#loadClass(String,String)}, and
  47. * {@link RMIClassLoader#loadClass(String,String,ClassLoader)}.
  48. *
  49. * Loads a class from a codebase URL path, optionally using the
  50. * supplied loader.
  51. *
  52. * Typically, a provider implementation will attempt to
  53. * resolve the named class using the given <code>defaultLoader</code>,
  54. * if specified, before attempting to resolve the class from the
  55. * codebase URL path.
  56. *
  57. * <p>An implementation of this method must either return a class
  58. * with the given name or throw an exception.
  59. *
  60. * @param codebase the list of URLs (separated by spaces) to load
  61. * the class from, or <code>null</code>
  62. *
  63. * @param name the name of the class to load
  64. *
  65. * @param defaultLoader additional contextual class loader
  66. * to use, or <code>null</code>
  67. *
  68. * @return the <code>Class</code> object representing the loaded class
  69. *
  70. * @throws MalformedURLException if <code>codebase</code> is
  71. * non-<code>null</code> and contains an invalid URL, or
  72. * if <code>codebase</code> is <code>null</code> and the system
  73. * property <code>java.rmi.server.codebase</code> contains an
  74. * invalid URL
  75. *
  76. * @throws ClassNotFoundException if a definition for the class
  77. * could not be found at the specified location
  78. */
  79. public abstract Class loadClass(String codebase, String name,
  80. ClassLoader defaultLoader)
  81. throws MalformedURLException, ClassNotFoundException;
  82. /**
  83. * Provides the implementation for
  84. * {@link RMIClassLoader#loadProxyClass(String,String[],ClassLoader)}.
  85. *
  86. * Loads a dynamic proxy class (see {@link java.lang.reflect.Proxy}
  87. * that implements a set of interfaces with the given names
  88. * from a codebase URL path, optionally using the supplied loader.
  89. *
  90. * <p>An implementation of this method must either return a proxy
  91. * class that implements the named interfaces or throw an exception.
  92. *
  93. * @param codebase the list of URLs (space-separated) to load
  94. * classes from, or <code>null</code>
  95. *
  96. * @param interfaces the names of the interfaces for the proxy class
  97. * to implement
  98. *
  99. * @return a dynamic proxy class that implements the named interfaces
  100. *
  101. * @param defaultLoader additional contextual class loader
  102. * to use, or <code>null</code>
  103. *
  104. * @throws MalformedURLException if <code>codebase</code> is
  105. * non-<code>null</code> and contains an invalid URL, or
  106. * if <code>codebase</code> is <code>null</code> and the system
  107. * property <code>java.rmi.server.codebase</code> contains an
  108. * invalid URL
  109. *
  110. * @throws ClassNotFoundException if a definition for one of
  111. * the named interfaces could not be found at the specified location,
  112. * or if creation of the dynamic proxy class failed (such as if
  113. * {@link java.lang.reflect.Proxy#getProxyClass(ClassLoader,Class[])}
  114. * would throw an <code>IllegalArgumentException</code> for the given
  115. * interface list)
  116. */
  117. public abstract Class loadProxyClass(String codebase, String[] interfaces,
  118. ClassLoader defaultLoader)
  119. throws MalformedURLException, ClassNotFoundException;
  120. /**
  121. * Provides the implementation for
  122. * {@link RMIClassLoader#getClassLoader(String)}.
  123. *
  124. * Returns a class loader that loads classes from the given codebase
  125. * URL path.
  126. *
  127. * <p>If there is a security manger, its <code>checkPermission</code>
  128. * method will be invoked with a
  129. * <code>RuntimePermission("getClassLoader")</code> permission;
  130. * this could result in a <code>SecurityException</code>.
  131. * The implementation of this method may also perform further security
  132. * checks to verify that the calling context has permission to connect
  133. * to all of the URLs in the codebase URL path.
  134. *
  135. * @param codebase the list of URLs (space-separated) from which
  136. * the returned class loader will load classes from, or <code>null</code>
  137. *
  138. * @return a class loader that loads classes from the given codebase URL
  139. * path
  140. *
  141. * @throws MalformedURLException if <code>codebase</code> is
  142. * non-<code>null</code> and contains an invalid URL, or
  143. * if <code>codebase</code> is <code>null</code> and the system
  144. * property <code>java.rmi.server.codebase</code> contains an
  145. * invalid URL
  146. *
  147. * @throws SecurityException if there is a security manager and the
  148. * invocation of its <code>checkPermission</code> method fails, or
  149. * if the caller does not have permission to connect to all of the
  150. * URLs in the codebase URL path
  151. */
  152. public abstract ClassLoader getClassLoader(String codebase)
  153. throws MalformedURLException; // SecurityException
  154. /**
  155. * Provides the implementation for
  156. * {@link RMIClassLoader#getClassAnnotation(Class)}.
  157. *
  158. * Returns the annotation string (representing a location for
  159. * the class definition) that RMI will use to annotate the class
  160. * descriptor when marshalling objects of the given class.
  161. *
  162. * @param cl the class to obtain the annotation for
  163. *
  164. * @return a string to be used to annotate the given class when
  165. * it gets marshalled, or <code>null</code>
  166. *
  167. * @throws NullPointerException if <code>cl</code> is <code>null</code>
  168. */
  169. public abstract String getClassAnnotation(Class cl);
  170. }