1. /*
  2. * @(#)RMIClassLoaderSpi.java 1.14 04/05/05
  3. *
  4. * Copyright 2004 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.14, 04/05/05
  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 a provider-specific
  73. * URL used to load classes is invalid
  74. *
  75. * @throws ClassNotFoundException if a definition for the class
  76. * could not be found at the specified location
  77. */
  78. public abstract Class<?> loadClass(String codebase, String name,
  79. ClassLoader defaultLoader)
  80. throws MalformedURLException, ClassNotFoundException;
  81. /**
  82. * Provides the implementation for
  83. * {@link RMIClassLoader#loadProxyClass(String,String[],ClassLoader)}.
  84. *
  85. * Loads a dynamic proxy class (see {@link java.lang.reflect.Proxy}
  86. * that implements a set of interfaces with the given names
  87. * from a codebase URL path, optionally using the supplied loader.
  88. *
  89. * <p>An implementation of this method must either return a proxy
  90. * class that implements the named interfaces or throw an exception.
  91. *
  92. * @param codebase the list of URLs (space-separated) to load
  93. * classes from, or <code>null</code>
  94. *
  95. * @param interfaces the names of the interfaces for the proxy class
  96. * to implement
  97. *
  98. * @return a dynamic proxy class that implements the named interfaces
  99. *
  100. * @param defaultLoader additional contextual class loader
  101. * to use, or <code>null</code>
  102. *
  103. * @throws MalformedURLException if <code>codebase</code> is
  104. * non-<code>null</code> and contains an invalid URL, or
  105. * if <code>codebase</code> is <code>null</code> and a provider-specific
  106. * URL used to load classes is invalid
  107. *
  108. * @throws ClassNotFoundException if a definition for one of
  109. * the named interfaces could not be found at the specified location,
  110. * or if creation of the dynamic proxy class failed (such as if
  111. * {@link java.lang.reflect.Proxy#getProxyClass(ClassLoader,Class[])}
  112. * would throw an <code>IllegalArgumentException</code> for the given
  113. * interface list)
  114. */
  115. public abstract Class<?> loadProxyClass(String codebase,
  116. String[] interfaces,
  117. ClassLoader defaultLoader)
  118. throws MalformedURLException, ClassNotFoundException;
  119. /**
  120. * Provides the implementation for
  121. * {@link RMIClassLoader#getClassLoader(String)}.
  122. *
  123. * Returns a class loader that loads classes from the given codebase
  124. * URL path.
  125. *
  126. * <p>If there is a security manger, its <code>checkPermission</code>
  127. * method will be invoked with a
  128. * <code>RuntimePermission("getClassLoader")</code> permission;
  129. * this could result in a <code>SecurityException</code>.
  130. * The implementation of this method may also perform further security
  131. * checks to verify that the calling context has permission to connect
  132. * to all of the URLs in the codebase URL path.
  133. *
  134. * @param codebase the list of URLs (space-separated) from which
  135. * the returned class loader will load classes from, or <code>null</code>
  136. *
  137. * @return a class loader that loads classes from the given codebase URL
  138. * path
  139. *
  140. * @throws MalformedURLException if <code>codebase</code> is
  141. * non-<code>null</code> and contains an invalid URL, or
  142. * if <code>codebase</code> is <code>null</code> and a provider-specific
  143. * URL used to identify the class loader is invalid
  144. *
  145. * @throws SecurityException if there is a security manager and the
  146. * invocation of its <code>checkPermission</code> method fails, or
  147. * if the caller does not have permission to connect to all of the
  148. * URLs in the codebase URL path
  149. */
  150. public abstract ClassLoader getClassLoader(String codebase)
  151. throws MalformedURLException; // SecurityException
  152. /**
  153. * Provides the implementation for
  154. * {@link RMIClassLoader#getClassAnnotation(Class)}.
  155. *
  156. * Returns the annotation string (representing a location for
  157. * the class definition) that RMI will use to annotate the class
  158. * descriptor when marshalling objects of the given class.
  159. *
  160. * @param cl the class to obtain the annotation for
  161. *
  162. * @return a string to be used to annotate the given class when
  163. * it gets marshalled, or <code>null</code>
  164. *
  165. * @throws NullPointerException if <code>cl</code> is <code>null</code>
  166. */
  167. public abstract String getClassAnnotation(Class<?> cl);
  168. }