1. /*
  2. * @(#)RMIClassLoader.java 1.22 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.rmi.server;
  11. import java.net.MalformedURLException;
  12. import java.net.URL;
  13. /**
  14. * <code>RMIClassLoader</code> provides static methods for loading classes
  15. * from a network location (one or more URLs) and obtaining the location
  16. * from which an existing class can be loaded. These methods are used by
  17. * the RMI runtime when marshalling and unmarshalling classes of parameters
  18. * and return values.
  19. *
  20. * @version 1.22, 02/02/00
  21. * @author Ann Wollrath
  22. * @author Peter Jones
  23. * @since JDK1.1
  24. */
  25. public class RMIClassLoader {
  26. /*
  27. * Disallow anyone from creating one of these.
  28. */
  29. private RMIClassLoader() {}
  30. /**
  31. * Loads a class from the codebase URL path specified by the
  32. * <code>java.rmi.server.codebase</code> property.
  33. *
  34. * @param name the name of the class to load
  35. * @return the <code>Class</code> object representing the loaded class
  36. * @exception MalformedURLException
  37. * if the system property <b>java.rmi.server.codebase</b>
  38. * contains an invalid URL
  39. * @exception ClassNotFoundException
  40. * if a definition for the class could not
  41. * be found at the codebase location
  42. * @since JDK1.1
  43. * @deprecated replaced by <code>loadClass(String,String)</code> method
  44. * @see #loadClass(String,String)
  45. */
  46. public static Class loadClass(String name)
  47. throws MalformedURLException, ClassNotFoundException
  48. {
  49. return sun.rmi.server.LoaderHandler.loadClass(name);
  50. }
  51. /**
  52. * Loads a class from a codebase URL. If the given codebase is
  53. * <code>null</code>, then the <code>Class</code> object returned is
  54. * equivalent to the <code>Class</code> object returned by
  55. * <code>RMIClassLoader.loadClass(name)</code>.
  56. *
  57. * @param codebase the URL to load the class from
  58. * @param name the name of the class to load
  59. * @return the <code>Class</code> object representing the loaded class
  60. * @exception MalformedURLException
  61. * if the <code>codebase</code> paramater
  62. * contains an invalid non-null URL
  63. * @exception ClassNotFoundException
  64. * if a definition for the class could not
  65. * be found at the specified URL
  66. * @since JDK1.1
  67. */
  68. public static Class loadClass(URL codebase, String name)
  69. throws MalformedURLException, ClassNotFoundException
  70. {
  71. return sun.rmi.server.LoaderHandler.loadClass(codebase, name);
  72. }
  73. /**
  74. * Loads a class from a codebase URL path. If the given codebase is
  75. * <code>null</code>, then the <code>Class</code> object returned is
  76. * equivalent to the <code>Class</code> object returned by
  77. * <code>RMIClassLoader.loadClass(name)</code>.
  78. *
  79. * @param codebase the list of space-separated URLs to load the class from
  80. * @param name the name of the class to load
  81. * @return the <code>Class</code> object representing the loaded class
  82. * @exception MalformedURLException
  83. * if the <code>codebase</code> paramater
  84. * contains an invalid non-null URL
  85. * @exception ClassNotFoundException
  86. * if a definition for the class could not
  87. * be found at the specified location
  88. * @since 1.2
  89. */
  90. public static Class loadClass(String codebase, String name)
  91. throws MalformedURLException, ClassNotFoundException
  92. {
  93. return sun.rmi.server.LoaderHandler.loadClass(codebase, name);
  94. }
  95. /**
  96. * Returns a class loader that loads classes from the given codebase URL
  97. * path. The class loader returned is the class loader that the
  98. * <code>#loadClass(String,String)</code> method would use to load classes
  99. * from the given codebase. If a class loader with the same codebase URL
  100. * path already exists for RMI runtime, it will be returned; otherwise, a
  101. * new class loader will be created. If the given codebase is null, it
  102. * returns the class loader used to load classes via the
  103. * <code>#loadClass(String)</code> method.
  104. *
  105. * @param codebase the list of space-separated URLs which the
  106. * the class loader will load classes from
  107. * @return a class loader that loads classes from the given codebase URL
  108. * path
  109. * @exception MalformedURLException
  110. * if the <code>codebase</code> paramater
  111. * contains an invalid non-null URL
  112. * @exception SecurityException
  113. * if the caller does not have permission to
  114. * connect to all of the URLs in <code>codebase</code> URL path
  115. * @since 1.3
  116. */
  117. public static ClassLoader getClassLoader(String codebase)
  118. throws MalformedURLException, SecurityException
  119. {
  120. return sun.rmi.server.LoaderHandler.getClassLoader(codebase);
  121. }
  122. /**
  123. * Returns the class annotation (representing the location for
  124. * a class) that RMI will use to annotate the call stream when
  125. * marshalling objects of the given class.
  126. *
  127. * @param cl the class to obtain the annotation for
  128. * @return a string to be used to annotate the class when marshalled
  129. * @since 1.2
  130. */
  131. public static String getClassAnnotation(Class cl) {
  132. return sun.rmi.server.LoaderHandler.getClassAnnotation(cl);
  133. }
  134. /**
  135. * Returns the security context of the given class loader.
  136. *
  137. * @param loader a class loader from which to get the security context
  138. * @return the security context
  139. * @since JDK1.1
  140. * @deprecated no replacement. As of the Java 2 platform v1.2, RMI no
  141. * longer uses this method to obtain a class loader's security context.
  142. * @see java.lang.SecurityManager#getSecurityContext()
  143. */
  144. public static Object getSecurityContext(ClassLoader loader)
  145. {
  146. return sun.rmi.server.LoaderHandler.getSecurityContext(loader);
  147. }
  148. }