Top Description Inners Fields Constructors Methods
sun.rmi.server

public final Class LoaderHandler

extends Object
Class Inheritance
Annotations
@SuppressWarnings:deprecation
Imports
java.io.File, .FilePermission, .IOException, java.lang.ref.ReferenceQueue, .SoftReference, .WeakReference, java.lang.reflect.Modifier, .Proxy, java.net.JarURLConnection, .MalformedURLException, .SocketPermission, .URL, .URLClassLoader, .URLConnection, java.security.AccessControlContext, .CodeSource, .Permission, .Permissions, .PermissionCollection, .Policy, .ProtectionDomain, .PrivilegedAction, java.rmi.server.LogStream, java.util.Arrays, .Collections, .Enumeration, .HashMap, .IdentityHashMap, .Map, .StringTokenizer, .WeakHashMap, sun.reflect.misc.ReflectUtil, sun.rmi.runtime.Log

LoaderHandler provides the implementation of the static methods of the java.rmi.server.RMIClassLoader class.
Authors
Ann Wollrath, Peter Jones, Laird Dornin

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
LoaderHandler.Loader

Loader is the actual class of the RMI class loaders created by the RMIClassLoader static methods.

private static class
LoaderHandler.LoaderEntry

LoaderEntry contains a weak reference to an RMIClassLoader.

private static class
LoaderHandler.LoaderKey

LoaderKey holds a codebase URL path and parent class loader pair used to look up RMI class loader instances in its class loader cache.

Field Summary

Modifier and TypeField and Description
private static final Map<ClassLoader, Void>
codebaseLoaders

table of class loaders that use codebase property for annotation

private static String
codebaseProperty

value of "java.rmi.server.codebase" property, as cached at class initialization time.

private static URL[]
codebaseURLs

list of URLs represented by the codebase property, if valid

pack-priv static final Log
private static final HashMap<LoaderHandler.LoaderKey, LoaderHandler.LoaderEntry>
loaderTable

table mapping codebase URL path and context class loader pairs to class loader instances.

pack-priv static final int
logLevel

RMI class loader log level

private static final Map<String, Object[]>
pathToURLsCache

map from weak(key=string) to [URL[], soft(key)]

private static final ReferenceQueue<LoaderHandler.Loader>
refQueue

reference queue for cleared class loader entries

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
addPermissionsForURLs(URL[] urls, PermissionCollection perms, boolean forLoader)

Adds to the specified permission collection the permissions necessary to load classes from a loader with the specified URL path; if "forLoader" is true, also adds URL-specific permissions necessary for the security context that such a loader operates within, such as permissions necessary for granting automatic permissions to classes defined by the loader.

public static String
getClassAnnotation(Class<?> cl)

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.

public static ClassLoader
getClassLoader(String codebase)

Returns a classloader that loads classes from the given codebase URL path.

private static synchronized URL[]
getDefaultCodebaseURLs()

Returns an array of URLs initialized with the value of the java.rmi.server.codebase property as the URL path.

private static AccessControlContext
getLoaderAccessControlContext(URL[] urls)
References Deprecated AccessControlContext is deprecated or references (maybe indirectly) at least one deprecated element.

Return the access control context that a loader for the given codebase URL path should execute with.

private static ClassLoader
getRMIContextClassLoader()

Return the class loader to be used as the parent for an RMI class loader used in the current execution context.

public static Object
getSecurityContext(ClassLoader loader)

Return the security context of the given class loader.

public static Class<?>
loadClass(String codebase, String name, ClassLoader defaultLoader)

Load a class from a network location (one or more URLs), but first try to resolve the named class through the given "default loader".

private static Class<?>
loadClass(URL[] urls, String name)

Load a class from the RMI class loader corresponding to the given codebase URL path in the current execution context.

private static Class<?>
loadClassForName(String name, boolean initialize, ClassLoader loader)

public static Class<?>
loadProxyClass(String codebase, String[] interfaces, ClassLoader defaultLoader)

Define and return a dynamic proxy class in a class loader with URLs supplied in the given location.

private static Class<?>
loadProxyClass(String[] interfaceNames, ClassLoader defaultLoader, ClassLoader codebaseLoader, boolean preferCodebase)

Define a proxy class in the default loader if appropriate.

private static Class<?>
loadProxyClass(ClassLoader loader, Class<?>[] interfaces)

Define a proxy class in the given class loader.

private static ClassLoader
loadProxyInterfaces(String[] interfaces, ClassLoader loader, Class<?>[] classObjs, boolean[] nonpublic)

private static LoaderHandler.Loader
lookupLoader(final URL[] urls, final ClassLoader parent)

Look up the RMI class loader for the given codebase URL path and the given parent class loader.

private static URL[]
pathToURLs(String path)

Convert a string containing a space-separated list of URLs into a corresponding array of URL objects, throwing a MalformedURLException if any of the URLs are invalid.

public static void
registerCodebaseLoader(ClassLoader loader)

Register a class loader as one whose classes should always be annotated with the value of the "java.rmi.server.codebase" property.

private static String
urlsToPath(URL[] urls)

Convert an array of URL objects into a corresponding string containing a space-separated list of URLs.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

codebaseLoadersback to summary
private static final Map<ClassLoader, Void> codebaseLoaders

table of class loaders that use codebase property for annotation

codebasePropertyback to summary
private static String codebaseProperty

value of "java.rmi.server.codebase" property, as cached at class initialization time. It may contain malformed URLs.

codebaseURLsback to summary
private static URL[] codebaseURLs

list of URLs represented by the codebase property, if valid

loaderLogback to summary
pack-priv static final Log loaderLog
loaderTableback to summary
private static final HashMap<LoaderHandler.LoaderKey, LoaderHandler.LoaderEntry> loaderTable

table mapping codebase URL path and context class loader pairs to class loader instances. Entries hold class loaders with weak references, so this table does not prevent loaders from being garbage collected.

logLevelback to summary
pack-priv static final int logLevel

RMI class loader log level

Annotations
@SuppressWarnings:removal
pathToURLsCacheback to summary
private static final Map<String, Object[]> pathToURLsCache

map from weak(key=string) to [URL[], soft(key)]

refQueueback to summary
private static final ReferenceQueue<LoaderHandler.Loader> refQueue

reference queue for cleared class loader entries

Constructor Detail

LoaderHandlerback to summary
private LoaderHandler()

Method Detail

addPermissionsForURLsback to summary
private static void addPermissionsForURLs(URL[] urls, PermissionCollection perms, boolean forLoader)

Adds to the specified permission collection the permissions necessary to load classes from a loader with the specified URL path; if "forLoader" is true, also adds URL-specific permissions necessary for the security context that such a loader operates within, such as permissions necessary for granting automatic permissions to classes defined by the loader. A given permission is only added to the collection if it is not already implied by the collection.

getClassAnnotationback to summary
public static String getClassAnnotation(Class<?> cl)

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.

getClassLoaderback to summary
public static ClassLoader getClassLoader(String codebase) throws MalformedURLException

Returns a classloader that loads classes from the given codebase URL path. The parent classloader of the returned classloader is the context class loader.

getDefaultCodebaseURLsback to summary
private static synchronized URL[] getDefaultCodebaseURLs() throws MalformedURLException

Returns an array of URLs initialized with the value of the java.rmi.server.codebase property as the URL path.

getLoaderAccessControlContextback to summary
private static AccessControlContext getLoaderAccessControlContext(URL[] urls)

References Deprecated

AccessControlContext is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Return the access control context that a loader for the given codebase URL path should execute with.

Annotations
@SuppressWarnings:removal
getRMIContextClassLoaderback to summary
private static ClassLoader getRMIContextClassLoader()

Return the class loader to be used as the parent for an RMI class loader used in the current execution context.

getSecurityContextback to summary
public static Object getSecurityContext(ClassLoader loader)

Return the security context of the given class loader.

loadClassback to summary
public static Class<?> loadClass(String codebase, String name, ClassLoader defaultLoader) throws MalformedURLException, ClassNotFoundException

Load a class from a network location (one or more URLs), but first try to resolve the named class through the given "default loader".

loadClassback to summary
private static Class<?> loadClass(URL[] urls, String name) throws ClassNotFoundException

Load a class from the RMI class loader corresponding to the given codebase URL path in the current execution context.

loadClassForNameback to summary
private static Class<?> loadClassForName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException
loadProxyClassback to summary
public static Class<?> loadProxyClass(String codebase, String[] interfaces, ClassLoader defaultLoader) throws MalformedURLException, ClassNotFoundException

Define and return 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.

loadProxyClassback to summary
private static Class<?> loadProxyClass(String[] interfaceNames, ClassLoader defaultLoader, ClassLoader codebaseLoader, boolean preferCodebase) throws ClassNotFoundException

Define a proxy class in the default loader if appropriate. Define the class in an RMI class loader otherwise. The proxy class will implement classes which are named in the supplied interfaceNames.

loadProxyClassback to summary
private static Class<?> loadProxyClass(ClassLoader loader, Class<?>[] interfaces) throws ClassNotFoundException

Define a proxy class in the given class loader. The proxy class will implement the given interfaces Classes.

loadProxyInterfacesback to summary
private static ClassLoader loadProxyInterfaces(String[] interfaces, ClassLoader loader, Class<?>[] classObjs, boolean[] nonpublic) throws ClassNotFoundException
lookupLoaderback to summary
private static LoaderHandler.Loader lookupLoader(final URL[] urls, final ClassLoader parent)

Look up the RMI class loader for the given codebase URL path and the given parent class loader. A new class loader instance will be created and returned if no match is found.

Annotations
@SuppressWarnings:removal
pathToURLsback to summary
private static URL[] pathToURLs(String path) throws MalformedURLException

Convert a string containing a space-separated list of URLs into a corresponding array of URL objects, throwing a MalformedURLException if any of the URLs are invalid.

registerCodebaseLoaderback to summary
public static void registerCodebaseLoader(ClassLoader loader)

Register a class loader as one whose classes should always be annotated with the value of the "java.rmi.server.codebase" property.

urlsToPathback to summary
private static String urlsToPath(URL[] urls)

Convert an array of URL objects into a corresponding string containing a space-separated list of URLs. Note that if the array has zero elements, the return value is null, not the empty string.

sun.rmi.server back to summary

private Class LoaderHandler.Loader

extends URLClassLoader
Class Inheritance

Loader is the actual class of the RMI class loaders created by the RMIClassLoader static methods.

Field Summary

Modifier and TypeField and Description
private String
annotation

string form of loader's codebase URL path, also an optimization

private ClassLoader
parent

Hides java.lang.ClassLoader.parent.

parent class loader, kept here as an optimization
private Permissions
permissions

permissions required to access loader through public API

Constructor Summary

AccessConstructor and Description
private
Loader(URL[] urls, ClassLoader parent)

Method Summary

Modifier and TypeMethod and Description
private void
checkPermissions()

Check that the current access control context has all of the permissions necessary to load classes from this loader.

public String
getClassAnnotation()

Return the string to be annotated with all classes loaded from this class loader.

protected PermissionCollection
getPermissions(CodeSource
the codesource
codesource
)

Overrides java.net.URLClassLoader.getPermissions.

Return the permissions to be granted to code loaded from the given code source.

protected Class<?>
loadClass(String
The binary name of the class
name
,
boolean
If true then resolve the class
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name.

public String
toString()

Overrides java.lang.Object.toString.

Return a string representation of this loader (useful for debugging).

Inherited from java.net.URLClassLoader:
addURLclosedefinePackagefindClassfindResourcefindResourcesgetResourceAsStreamgetURLsnewInstancenewInstance

Field Detail

annotationback to summary
private String annotation

string form of loader's codebase URL path, also an optimization

parentback to summary
private ClassLoader parent

Hides java.lang.ClassLoader.parent.

parent class loader, kept here as an optimization

permissionsback to summary
private Permissions permissions

permissions required to access loader through public API

Constructor Detail

Loaderback to summary
private Loader(URL[] urls, ClassLoader parent)

Method Detail

checkPermissionsback to summary
private void checkPermissions()

Check that the current access control context has all of the permissions necessary to load classes from this loader.

getClassAnnotationback to summary
public String getClassAnnotation()

Return the string to be annotated with all classes loaded from this class loader.

getPermissionsback to summary
protected PermissionCollection getPermissions(CodeSource codesource)

Overrides java.net.URLClassLoader.getPermissions.

Return the permissions to be granted to code loaded from the given code source.

Parameters
codesource:CodeSource

Doc from java.net.URLClassLoader.getPermissions.

the codesource

Returns:PermissionCollection

Doc from java.net.URLClassLoader.getPermissions.

the permissions granted to the codesource

loadClassback to summary
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Doc from java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name. The default implementation of this method searches for classes in the following order:

  1. Invoke findLoadedClass(String) to check if the class has already been loaded.

  2. Invoke the loadClass method on the parent class loader. If the parent is null the class loader built into the virtual machine is used, instead.

  3. Invoke the findClass(String) method to find the class.

If the class was found using the above steps, and the resolve flag is true, this method will then invoke the resolveClass(Class) method on the resulting Class object.

Subclasses of ClassLoader are encouraged to override findClass(String), rather than this method.

Unless overridden, this method synchronizes on the result of getClassLoadingLock method during the entire class loading process.

Parameters
name:String

The binary name of the class

resolve:boolean

If true then resolve the class

Returns:Class<?>

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:
If the class could not be found
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return a string representation of this loader (useful for debugging).

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

sun.rmi.server back to summary

private Class LoaderHandler.LoaderEntry

extends WeakReference<LoaderHandler.Loader>
Class Inheritance

LoaderEntry contains a weak reference to an RMIClassLoader. The weak reference is registered with the private static "refQueue" queue. The entry contains the codebase URL path and parent class loader key for the loader so that the mapping can be removed from the table efficiently when the weak reference is cleared.

Field Summary

Modifier and TypeField and Description
public LoaderHandler.LoaderKey
public boolean
removed

set to true if the entry has been removed from the table because it has been replaced, so it should not be attempted to be removed again

Constructor Summary

AccessConstructor and Description
public

Field Detail

keyback to summary
public LoaderHandler.LoaderKey key
removedback to summary
public boolean removed

set to true if the entry has been removed from the table because it has been replaced, so it should not be attempted to be removed again

Constructor Detail

LoaderEntryback to summary
public LoaderEntry(LoaderHandler.LoaderKey key, LoaderHandler.Loader loader)
sun.rmi.server back to summary

private Class LoaderHandler.LoaderKey

extends Object
Class Inheritance

LoaderKey holds a codebase URL path and parent class loader pair used to look up RMI class loader instances in its class loader cache.

Field Summary

Modifier and TypeField and Description
private int
private ClassLoader
private URL[]

Constructor Summary

AccessConstructor and Description
public
LoaderKey(URL[] urls, ClassLoader parent)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

hashValueback to summary
private int hashValue
parentback to summary
private ClassLoader parent
urlsback to summary
private URL[] urls

Constructor Detail

LoaderKeyback to summary
public LoaderKey(URL[] urls, ClassLoader parent)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object