net.jini.loader.pref
Class PreferredClassProvider

java.lang.Object
  extended byjava.rmi.server.RMIClassLoaderSpi
      extended bynet.jini.loader.pref.PreferredClassProvider
Direct Known Subclasses:
RequireDlPermProvider

public class PreferredClassProvider
extends RMIClassLoaderSpi

An RMIClassLoader provider that supports preferred classes.

See the RMIClassLoader specification for information about how to install and configure the RMIClassLoader service provider.

PreferredClassProvider uses instances of PreferredClassLoader to load classes from codebase URL paths supplied to RMIClassLoader.loadClass methods.

PreferredClassProvider does not enforce DownloadPermission by default, but a subclass can configure it to do so by passing true as the argument to the protected constructor.

By overriding the getClassAnnotation method, a subclass can also configure the class annotations to be used for classes defined by the system class loader, its ancestor class loaders, and any class loader that is not an instance of ClassAnnotation or URLClassLoader.

Since:
2.0

Constructor Summary
  PreferredClassProvider()
          Creates a new PreferredClassProvider.
protected PreferredClassProvider(boolean requireDlPerm)
          Creates a new PreferredClassProvider.
 
Method Summary
 String getClassAnnotation(Class cl)
          Provides the implementation for RMIClassLoaderSpi.getClassAnnotation(Class).
protected  String getClassAnnotation(ClassLoader loader)
          Returns the class annotation string to use for classes defined by the specified class loader.
 ClassLoader getClassLoader(String codebase)
          Provides the implementation for RMIClassLoaderSpi.getClassLoader(String).
 Class loadClass(String codebase, String name, ClassLoader defaultLoader)
          Provides the implementation for RMIClassLoaderSpi.loadClass(String,String,ClassLoader).
 Class loadProxyClass(String codebase, String[] interfaces, ClassLoader defaultLoader)
          Provides the implementation of RMIClassLoaderSpi.loadProxyClass(String,String[],ClassLoader).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreferredClassProvider

public PreferredClassProvider()
Creates a new PreferredClassProvider.

This constructor is used by the RMIClassLoader service provider location mechanism when PreferredClassProvider is configured as the RMIClassLoader provider class.

DownloadPermission is not enforced by the created provider.


PreferredClassProvider

protected PreferredClassProvider(boolean requireDlPerm)
Creates a new PreferredClassProvider.

This constructor is used by subclasses to control whether or not DownloadPermission is enforced.

Parameters:
requireDlPerm - if true, the class loaders created by the provider will only define classes with a CodeSource that is granted DownloadPermission
Method Detail

loadClass

public Class loadClass(String codebase,
                       String name,
                       ClassLoader defaultLoader)
                throws MalformedURLException,
                       ClassNotFoundException
Provides the implementation for RMIClassLoaderSpi.loadClass(String,String,ClassLoader). Loads a class from a codebase URL path, only using the supplied loader if the given name is not preferred by the class loader for the codebase path. If the name parameter is marked as preferred in the preferred class loader which is requested to load the named class, that class loader will not delegate to its parent to load the requested class. Instead the class loader will only search its own resources to find the class. If a definition for the class cannot be found, a ClassNotFoundException is thrown, otherwise the class object for the requested class is returned.

If codebase is null, then the value of the system property java.rmi.server.codebase (or possibly an earlier cached value) is used as the codebase URL path.

Parameters:
codebase - the list of URLs (separated by spaces) from which the class should be loaded , or null
name - the name of the class to load
defaultLoader - additional contextual class loader to use, or null
Returns:
the Class object representing the loaded class
Throws:
MalformedURLException - if codebase is non-null and contains an invalid URL, or if codebase is null and the value of java.rmi.server.codebase contains an invalid URL
ClassNotFoundException - if a definition for the class could not be found at the specified location

getClassAnnotation

public String getClassAnnotation(Class cl)
Provides the implementation for RMIClassLoaderSpi.getClassAnnotation(Class).

PreferredClassProvider implements this method as follows:

If cl is an array class (of one or more dimensions) with a primitive component type, then this method returns null.

If the defining class loader of cl is the system class loader or an ancestor of the system class loader, then this method invokes getClassAnnotation with the loader and returns the result.

If the defining class loader of cl is an instance of ClassAnnotation, then this method invokes getClassAnnotation on that loader and returns the result.

If the defining class loader of cl is an instance of URLClassLoader and the current security context has the permissions necessary to connect to all of the URLs returned by an invocation of getURLs on the loader, then this method returns a space-separated list of those URLs.

Otherwise, this method invokes getClassAnnotation with the defining class loader of cl and returns the result.

Parameters:
cl - the class to obtain the annotation for
Returns:
the annotation string for the class, or null

getClassAnnotation

protected String getClassAnnotation(ClassLoader loader)
Returns the class annotation string to use for classes defined by the specified class loader.

This method is invoked by PreferredClassProvider.getClassAnnotation(Class) when it is passed a class defined by the system class loader, an ancestor of the system class loader, any class loader that is not an instance of ClassAnnotation or URLClassLoader, or a URLClassLoader for which the current security context does not have permission to connect to all of its URLs.

PreferredClassProvider implements this method as follows:

This method returns the value of the system property java.rmi.server.codebase (or possibly an earlier cached value).

Parameters:
loader - the defining class loader of the class to obtain the annotation for
Returns:
the class annotation string for classes defined by the loader, or null

getClassLoader

public ClassLoader getClassLoader(String codebase)
                           throws MalformedURLException
Provides the implementation for RMIClassLoaderSpi.getClassLoader(String). Returns a class loader that loads classes from the given codebase URL path.

If codebase is null, then the value of the system property java.rmi.server.codebase (or possibly an earlier cached value) is used as the codebase URL path.

If there is a security manager, its checkPermission method will be invoked with a RuntimePermission("getClassLoader") permission; this could result in a SecurityException. This method also verifies that the current security context has all of the security permissions necessary to connect to all of the URLs in the codebase URL path.

Parameters:
codebase - the list of URLs (space-separated) that the returned class loader will load classes from, or null
Returns:
a class loader that loads classes from the given codebase URL path
Throws:
MalformedURLException - if codebase is non-null and contains an invalid URL, or if codebase is null and the value of java.rmi.server.codebase contains an invalid URL
SecurityException - if there is a security manager and the invocation of its checkPermission method fails, or if the current security context does not have the permissions necessary to connect to all of the URLs in the codebase URL path

loadProxyClass

public Class loadProxyClass(String codebase,
                            String[] interfaces,
                            ClassLoader defaultLoader)
                     throws MalformedURLException,
                            ClassNotFoundException
Provides the implementation of RMIClassLoaderSpi.loadProxyClass(String,String[],ClassLoader). Defines and returns a dynamic proxy class in a class loader with URLs supplied in the given location. The proxy class will implement interface classes named by the given array of interface names.

If codebase is null, then the value of the system property java.rmi.server.codebase (or possibly an earlier cached value) is used as the codebase URL path.

Parameters:
codebase - the list of URLs (space-separated) to load classes from, or null
interfaces - the names of the interfaces for the proxy class to implement
defaultLoader - additional contextual class loader to use, or null
Returns:
a dynamic proxy class that implements the named interfaces
Throws:
MalformedURLException - if codebase is non-null and contains an invalid URL, or if codebase is null and the value of java.rmi.server.codebase contains an invalid URL
ClassNotFoundException - if a definition for one of the named interfaces could not be found at the specified location, or if creation of the dynamic proxy class failed (such as if Proxy.getProxyClass would throw an IllegalArgumentException for the given interface list)


Copyright © 2004 Sun Microsystems, Inc. All rights reserved