CONTENTS | PREV | NEXT Java Remote Method Invocation


5.6 The RMIClassLoader Class

The java.rmi.server.RMIClassLoader is a utility class that can be used by applications to load classes via a URL.

package java.rmi.server;

public class RMIClassLoader {

    public static Class loadClass(String name)
	    throws MalformedURLException, ClassNotFoundException;

    	public static Class loadClass(URL codebase, String name) 
		throws MalformedURLException, ClassNotFoundException;

	public static Class loadClass(String codebase, String name)
	    throws MalformedURLException, ClassNotFoundException;

	public static String getClassAnnotation(Class cl);

	public static Object getSecurityContext(ClassLoader loader);
}


The first loadClass method loads the specified class, name, via the URL defined by the java.rmi.server.codebase property. The class is loaded, defined, and returned.

The second form of the loadClass method loads the specified class, name, via the URL parameter codebase.

The third form of the loadClass method loads the specified class, name, from a codebase URL path. Each URL in the codebase path must be separated by a space.

The getClassAnnotation method returns the class annotation (representing the location for a class) that RMI will use to annotate the call stream when marshalling objects of the given class, cl.

The getSecurityContext method returns the security context of the given class loader, loader. The security context is obtained by querying the LoaderHandler's getSecurityContext method.


Note - The RMI runtime uses its own class loader to load stubs, skeletons, and other classes needed by the stubs and skeletons. These classes, and the way they are used, support the safety properties of the Java RMI runtime. This class loader always loads locally-available classes first. Only if a security manager is in force will stubs be loaded from either the local machine or from a network source. The class loader keeps a cache of loaders for individual Uniform Resource Locators (URLs) and the classes that have been loaded from them. When a stub or skeleton has been loaded, any class references that occur as parameters or returns will be loaded (from their originating codebase host) and are subject to the same security restrictions. Server processes must declare to the RMI runtime the location of the classes (stubs and parameters/returns) that will be available to its clients. The java.rmi.server.codebase property should be a URL from which stub classes and classes used by stubs will be loaded, using the normal protocols, such as http and ftp.


CONTENTS | PREV | NEXT
Copyright © 1997-1998 Sun Microsystems, Inc. All Rights Reserved.