Package de.xima.fc.classloader
Class ChainedClassLoader
java.lang.Object
java.lang.ClassLoader
de.xima.fc.classloader.ChainedClassLoader
- All Implemented Interfaces:
AutoCloseable
A class loader that combines several other class loaders.
- When
searching for a class
, it tries each class loader in order, and returns the class of the first class loader that can provide the class. - When
searching for a resources
, it tries each class loader in order, and returns the resource of the first class loader that can provide the resource. - When searching
for multiple resources
, it returns the resources of all class loaders.
AutoCloseable
. Afterwards,
classes cannot be loaded anymore.- Since:
- 7.0.11
- Author:
- XIMA MEDIA GmbH
-
Constructor Summary
ConstructorsConstructorDescriptionChainedClassLoader
(ClassLoader[] classLoaders) Creates a new chained class loader that combines the given loaders.ChainedClassLoader
(Iterable<ClassLoader> classLoaders) Creates a new chained class loader that combines the given loaders. -
Method Summary
Modifier and TypeMethodDescriptionstatic ClassLoader
chain
(ClassLoader[] classLoaders) Creates a new class loader that combines the given loaders.static ClassLoader
chain
(Iterable<ClassLoader> classLoaders) Creates a new class loader that combines the given loaders.void
close()
Closes all chained loaders if they implementAutoCloseable
.Returns all class loaders which this class loader combines.getResource
(String name) getResources
(String name) Class<?>
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, getResourceAsStream, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
ChainedClassLoader
Creates a new chained class loader that combines the given loaders.- Parameters:
classLoaders
- Loaders to chain.
-
ChainedClassLoader
Creates a new chained class loader that combines the given loaders.- Parameters:
classLoaders
- Loaders to chain.
-
-
Method Details
-
close
Closes all chained loaders if they implementAutoCloseable
. Afterwards, classes cannot be loaded anymore.The method makes a best effort attempt to close all opened files, by catching
Exception
s internally. Unchecked exceptions and errors are not caught. Calling close on an already closed loader has no effect.- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
- If closing any file opened by this class loader resulted in anException
. Any such exceptions are caught internally. If only one is caught, then it is re-thrown. If more than one exception is caught, then the second and following exceptions are added as suppressed exceptions of the first one caught, which is then re-thrown.
-
getClassLoaders
Returns all class loaders which this class loader combines. Note: the returned list is unmodifiable.- Returns:
- The class loaders that are chained by this class loader.
-
getResource
- Overrides:
getResource
in classClassLoader
-
getResources
- Overrides:
getResources
in classClassLoader
- Throws:
IOException
-
loadClass
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
chain
Creates a new class loader that combines the given loaders. This method makes no guarantess regarding which sub class ofClassLoader
is returned.- Parameters:
classLoaders
- Loaders to chain.- Returns:
- A class loader that combines the given loaders.
-
chain
Creates a new class loader that combines the given loaders. This method makes no guarantess regarding which sub class ofClassLoader
is returned.- Parameters:
classLoaders
- Loaders to chain.- Returns:
- A class loader that combines the given loaders.
-