Package org.eclipse.jetty.osgi.util
Class BundleDelegatingClassLoader
java.lang.Object
java.lang.ClassLoader
org.eclipse.jetty.osgi.util.BundleDelegatingClassLoader
- All Implemented Interfaces:
org.osgi.framework.BundleReference
public class BundleDelegatingClassLoader
extends ClassLoader
implements org.osgi.framework.BundleReference
BundleDelegatingClassLoader
A ClassLoader that delegates to an OSGi Bundle using the standard OSGi specification API methods (Bundle.loadClass, Bundle.getResource, Bundle.getResources) instead of using reflection to access internal container-specific classloaders.
When the first class is loaded, this classloader obtains the real bundle classloader from that class and delegates to it for subsequent operations, providing better compatibility and performance for classloader-specific operations.
-
Constructor Summary
ConstructorsConstructorDescriptionBundleDelegatingClassLoader(org.osgi.framework.Bundle bundle) Creates a new BundleDelegatingClassLoader for the given bundle. -
Method Summary
Modifier and TypeMethodDescriptionorg.osgi.framework.BundleGets the underlying bundle classloader if one has been resolved, or null if no class has been loaded yet.getResource(String name) getResourceAsStream(String name) getResources(String name) Class<?>protected Class<?>toString()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, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
BundleDelegatingClassLoader
public BundleDelegatingClassLoader(org.osgi.framework.Bundle bundle) Creates a new BundleDelegatingClassLoader for the given bundle.- Parameters:
bundle- the OSGi bundle to delegate class and resource loading to
-
-
Method Details
-
getBundle
public org.osgi.framework.Bundle getBundle()- Specified by:
getBundlein interfaceorg.osgi.framework.BundleReference
-
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
getResource
- Overrides:
getResourcein classClassLoader
-
getResources
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
getResourceAsStream
- Overrides:
getResourceAsStreamin classClassLoader
-
getBundleClassLoader
Gets the underlying bundle classloader if one has been resolved, or null if no class has been loaded yet.- Returns:
- the resolved bundle classloader, or null
-
toString
-