Top Description Fields Constructors Methods
com.thoughtworks.xstream.core.util

public Class CompositeClassLoader

extends ClassLoader
Class Inheritance
Imports
java.lang.ref.ReferenceQueue, .WeakReference, java.lang.reflect.Method, java.util.ArrayList, .Collection, .Iterator, .List, com.thoughtworks.xstream.core.JVM

ClassLoader that is composed of other classloaders. Each loader will be used to try to load the particular class, until one of them succeeds

Note

The loaders will always be called in the REVERSE order they were added in.

The Composite class loader also has registered the classloader that loaded xstream.jar and (if available) the thread's context classloader.

Example

CompositeClassLoader loader = new CompositeClassLoader();
loader.add(MyClass.class.getClassLoader());
loader.add(new AnotherClassLoader());
 
loader.loadClass("com.blah.ChickenPlucker");

The above code will attempt to load a class from the following classloaders (in order):

The added classloaders are kept with weak references to allow an application container to reload classes.

Authors
Joe Walnes, Jörg Schaible
Since
1.0.3

Field Summary

Modifier and TypeField and Description
private final List<E>
private final ReferenceQueue<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
add(ClassLoader classLoader)

Add a loader to the n

private void
addInternal(ClassLoader classLoader)

private void
public Class<T>
loadClass(String
The binary name of the class
name
)

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name.
Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

classLoadersback to summary
private final List<E> classLoaders
queueback to summary
private final ReferenceQueue<T> queue

Constructor Detail

CompositeClassLoaderback to summary
public CompositeClassLoader()

Method Detail

addback to summary
public synchronized void add(ClassLoader classLoader)

Add a loader to the n

addInternalback to summary
private void addInternal(ClassLoader classLoader)
cleanupback to summary
private void cleanup()
loadClassback to summary
public Class<T> loadClass(String name) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Doc from java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name. This method searches for classes in the same manner as the loadClass(String, boolean) method. It is invoked by the Java virtual machine to resolve class references. Invoking this method is equivalent to invoking loadClass(name, false).

Parameters
name:String

The binary name of the class

Returns:Class<T>

The resulting Class object

Exceptions
ClassNotFoundException:
If the class was not found