/*
* @(#)RMIClassLoader.java 1.34 01/12/03
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package java.rmi.server;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import sun.misc.Service;
/**
* <code>RMIClassLoader</code> comprises static methods to support
* dynamic class loading with RMI. Included are methods for loading
* classes from a network location (one or more URLs) and obtaining
* the location from which an existing class should be loaded by
* remote parties. These methods are used by the RMI runtime when
* marshalling and unmarshalling classes contained in the arguments
* and return values of remote method calls, and they also may be
* invoked directly by applications in order to mimic RMI's dynamic
* class loading behavior.
*
* <p>The implementation of the following static methods
*
* <ul>
*
* <li>{@link #loadClass(URL,String)}
* <li>{@link #loadClass(String,String)}
* <li>{@link #loadClass(String,String,ClassLoader)}
* <li>{@link #loadProxyClass(String,String[],ClassLoader)}
* <li>{@link #getClassLoader(String)}
* <li>{@link #getClassAnnotation(Class)}
*
* </ul>
*
* is provided by an instance of {@link RMIClassLoaderSpi}, the
* service provider interface for those methods. When one of the
* methods is invoked, its behavior is to delegate to a corresponding
* method on the service provider instance. The details of how each
* method delegates to the provider instance is described in the
* documentation for each particular method.
*
* <p>The service provider instance is chosen as follows:
*
* <ul>
*
* <li>If the system property
* <code>java.rmi.server.RMIClassLoaderSpi</code> is defined, then if
* its value equals the string <code>"default"</code>, the provider
* instance will be the value returned by an invocation of the {@link
* #getDefaultProviderInstance()} method, and for any other value, if
* a class named with the value of the property can be loaded by the
* system class loader (see {@link ClassLoader#getSystemClassLoader})
* and that class is assignable to {@link RMIClassLoaderSpi} and has a
* public no-argument constructor, then that constructor will be
* invoked to create the provider instance. If the property is
* defined but any other of those conditions are not true, then an
* unspecified <code>Error</code> will be thrown to code that attempts
* to use <code>RMIClassLoader</code>, indicating the failure to
* obtain a provider instance.
*
* <li>If a resource named
* <code>META-INF/services/java.rmi.server.RMIClassLoaderSpi</code> is
* visible to the system class loader, then the contents of that
* resource are interpreted as a provider-configuration file, and the
* first class name specified in that file is used as the provider
* class name. If a class with that name can be loaded by the system
* class loader and that class is assignable to {@link
* RMIClassLoaderSpi} and has a public no-argument constructor, then
* that constructor will be invoked to create the provider instance.
* If the resource is found but a provider cannot be instantiated as
* described, then an unspecified <code>Error</code> will be thrown to
* code that attempts to use <code>RMIClassLoader</code>, indicating
* the failure to obtain a provider instance.
*
* <li>Otherwise, the provider instance will be the value returned by
* an invocation of the {@link #getDefaultProviderInstance()} method.
*
* </ul>
*
* @version 1.34, 01/12/03
* @author Ann Wollrath
* @author Peter Jones
* @author Laird Dornin
* @see RMIClassLoaderSpi
* @since JDK1.1
*/
public class RMIClassLoader {
/** "default" provider instance */
private static final RMIClassLoaderSpi defaultProvider =
newDefaultProviderInstance();
/** provider instance */
private static final RMIClassLoaderSpi provider =
(RMIClassLoaderSpi) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() { return initializeProvider(); }
});
/*
* Disallow anyone from creating one of these.
*/
private RMIClassLoader() {}
/**
* Loads a class from the codebase URL path specified by the
* <code>java.rmi.server.codebase</code> property.
*
* <p>This method delegates to {@link #loadClass(String,String)},
* passing <code>null</code> as the first argument and
* <code>name</code> as the second argument.
*
* @param name the name of the class to load
*
* @return the <code>Class</code> object representing the loaded class
*
* @throws MalformedURLException if the system property
* <code>java.rmi.server.codebase</code> contains an invalid URL
*
* @throws ClassNotFoundException if a definition for the class
* could not be found at the codebase location
*
* @deprecated replaced by <code>loadClass(String,String)</code> method
* @see #loadClass(String,String)
*/
public static Class loadClass(String name)
throws MalformedURLException, ClassNotFoundException
{
return loadClass((String) null, name);
}
/**
* Loads a class from a codebase URL.
*
* If <code>codebase</code> is <code>null</code>, then this method
* will behave the same as {@link #loadClass(String,String)} with a
* <code>null</code> <code>codebase</code> and the given class name.
*
* <p>This method delegates to the
* {@link RMIClassLoaderSpi#loadClass(String,String,ClassLoader)}
* method of the provider instance, passing the result of invoking
* {@link URL#toString} on the given URL (or <code>null</code> if
* <code>codebase</code> is null) as the first argument,
* <code>name</code> as the second argument,
* and <code>null</code> as the third argument.
*
* @param codebase the URL to load the class from, or <code>null</code>
*
* @param name the name of the class to load
*
* @return the <code>Class</code> object representing the loaded class
*
* @throws MalformedURLException if <code>codebase</code> is
* <code>null</code> and the system property
* <code>java.rmi.server.codebase</code> contains an invalid URL
*
* @throws ClassNotFoundException if a definition for the class
* could not be found at the specified URL
*/
public static Class loadClass(URL codebase, String name)
throws MalformedURLException, ClassNotFoundException
{
return provider.loadClass(
codebase != null ? codebase.toString() : null, name, null);
}
/**
* Loads a class from a codebase URL path.
*
* If <code>codebase</code> is <code>null</code>, then the value of
* the system property <code>java.rmi.server.codebase</code> is used
* as the URL path.
*
* <p>This method delegates to the
* {@link RMIClassLoaderSpi#loadClass(String,String,ClassLoader)}
* method of the provider instance, passing <code>codebase</code>
* as the first argument, <code>name</code> as the second argument,
* and <code>null</code> as the third argument.
*
* @param codebase the list of URLs (separated by spaces) to load
* the class from, or <code>null</code>
*
* @param name the name of the class to load
*
* @return the <code>Class</code> object representing the loaded class
*
* @throws MalformedURLException if <code>codebase</code> is
* non-<code>null</code> and contains an invalid URL, or
* if <code>codebase</code> is <code>null</code> and the system
* property <code>java.rmi.server.codebase</code> contains an
* invalid URL
*
* @throws ClassNotFoundException if a definition for the class
* could not be found at the specified location
*
* @since 1.2
*/
public static Class loadClass(String codebase, String name)
throws Malfor
java-rmi.zip_RMI java_rmi
版权申诉
197 浏览量
2022-09-14
14:37:22
上传
评论
收藏 97KB ZIP 举报
寒泊
- 粉丝: 75
- 资源: 1万+
最新资源
- 2001~2022年上市公司数字赋能指数.dta
- 2001~2022年上市公司数字赋能指数.xlsx
- 信息办公石大在线财务管理系统(含源码)-shidacaiwu.rar
- 信息办公电信计费系统完整代码-netctossconformity.rar
- matlab实现TD-SCDMA中初始同步捕捉DwPTS下行同步导频时隙的仿真.zip
- 信息办公玉玺学生信息管理系统-webapps.rar
- 信息办公基于struts的图书管理系统-struts-ts.rar
- 管家婆分销ERP V1 V3 A8II TOP V10.0.2最新全版本通用
- 信息办公基于Ajax+J2EE的MicroERP源码下载-microerp-0.1.rar
- 信息办公双鱼林jsp人事工资系统-wagesmanagesystem.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈