Package org.glassfish.internal.api
Class DelegatingClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- org.glassfish.internal.api.DelegatingClassLoader
-
public class DelegatingClassLoader extends ClassLoader
This classloader has a list of classloaders called as delegates that it uses to find classes. All those delegates must have the same parent as this classloader in order to have a consistent class space. By consistent class space, I mean a class space where no two loaded class have same name. An inconsistent class space can lead to ClassCastException. This classloader does not define any class, classes are always loaded either by its parent or by one of the delegates.- Author:
- [email protected]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DelegatingClassLoader.ClassFinder
findClass method of ClassLoader is usually a protected method.
-
Constructor Summary
Constructors Constructor Description DelegatingClassLoader(ClassLoader parent)
DelegatingClassLoader(ClassLoader parent, List<DelegatingClassLoader.ClassFinder> delegates)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addDelegate(DelegatingClassLoader.ClassFinder d)
Adds a ClassFinder to list of delegates.Class<?>
findClass(String name)
protected URL
findResource(String name)
protected Enumeration<URL>
findResources(String name)
List<DelegatingClassLoader.ClassFinder>
getDelegates()
String
getName()
boolean
removeDelegate(DelegatingClassLoader.ClassFinder d)
Removes a ClassFinder from list of delegates.void
setName(String name)
String
toString()
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
DelegatingClassLoader
public DelegatingClassLoader(ClassLoader parent, List<DelegatingClassLoader.ClassFinder> delegates) throws IllegalArgumentException
- Throws:
IllegalArgumentException
- when the delegate does not have same parent as this classloader.
-
DelegatingClassLoader
public DelegatingClassLoader(ClassLoader parent)
-
-
Method Detail
-
addDelegate
public boolean addDelegate(DelegatingClassLoader.ClassFinder d) throws IllegalStateException, IllegalArgumentException
Adds a ClassFinder to list of delegates. To have a consistent class space (by consistent class space, I mean a classpace where there does not exist two class with same name), this method does not allow a delegate to be added that has a different parent.- Parameters:
d
- ClassFinder to add to the list of delegates- Returns:
- true if the delegate is added, false otherwise.
- Throws:
IllegalStateException
- when this method is called after the classloader has been used to load any class.IllegalArgumentException
- when the delegate does not have same parent as this classloader.
-
removeDelegate
public boolean removeDelegate(DelegatingClassLoader.ClassFinder d)
Removes a ClassFinder from list of delegates. This method must not be used once this classloader has beed used to load any class. If attempted to do so, this method throws IllegalStateException- Parameters:
d
- ClassFinder to remove from the list of delegates- Returns:
- true if the delegate was removed, false otherwise.
- Throws:
IllegalStateException
- when this method is called after the classloader has been used to load any class.
-
findClass
public Class<?> findClass(String name) throws ClassNotFoundException
- Overrides:
findClass
in classClassLoader
- Throws:
ClassNotFoundException
-
findResource
protected URL findResource(String name)
- Overrides:
findResource
in classClassLoader
-
findResources
protected Enumeration<URL> findResources(String name) throws IOException
- Overrides:
findResources
in classClassLoader
- Throws:
IOException
-
getName
public String getName()
- Overrides:
getName
in classClassLoader
-
setName
public void setName(String name)
-
getDelegates
public List<DelegatingClassLoader.ClassFinder> getDelegates()
-
-