Class CompositeClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- com.thoughtworks.xstream.core.util.CompositeClassLoader
-
public class CompositeClassLoader extends java.lang.ClassLoaderClassLoader 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):
- AnotherClassLoader (and all its parents)
- The classloader for MyClas (and all its parents)
- The thread's context classloader (and all its parents)
- The classloader for XStream (and all its parents)
The added classloaders are kept with weak references to allow an application container to reload classes.
- Since:
- 1.0.3
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ListclassLoadersprivate java.lang.ref.ReferenceQueuequeue
-
Constructor Summary
Constructors Constructor Description CompositeClassLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.ClassLoader classLoader)Add a loader to the nprivate voidaddInternal(java.lang.ClassLoader classLoader)private voidcleanup()java.lang.ClassloadClass(java.lang.String name)-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Method Detail
-
add
public void add(java.lang.ClassLoader classLoader)
Add a loader to the n- Parameters:
classLoader-
-
addInternal
private void addInternal(java.lang.ClassLoader classLoader)
-
loadClass
public java.lang.Class loadClass(java.lang.String name) throws java.lang.ClassNotFoundException- Overrides:
loadClassin classjava.lang.ClassLoader- Throws:
java.lang.ClassNotFoundException
-
cleanup
private void cleanup()
-
-