Package org.glassfish.internal.api
Class DelegatingClassLoader
java.lang.Object
java.lang.ClassLoader
org.glassfish.internal.api.DelegatingClassLoader
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:
- Sanjeeb.Sahoo@Sun.COM
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacefindClass method of ClassLoader is usually a protected method. -
Constructor Summary
ConstructorsConstructorDescriptionDelegatingClassLoader(ClassLoader parent) DelegatingClassLoader(ClassLoader parent, List<DelegatingClassLoader.ClassFinder> delegates) -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a ClassFinder to list of delegates.Class<?>protected URLfindResource(String name) protected Enumeration<URL>findResources(String name) getName()booleanRemoves a ClassFinder from list of delegates.voidtoString()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 Details
-
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
-
-
Method Details
-
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
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
- Overrides:
findClassin classClassLoader- Throws:
ClassNotFoundException
-
findResource
- Overrides:
findResourcein classClassLoader
-
findResources
- Overrides:
findResourcesin classClassLoader- Throws:
IOException
-
getName
- Overrides:
getNamein classClassLoader
-
setName
-
getDelegates
-
toString
-