org.apache.xbean.osgi.bundle.util
Class BundleClassLoader
java.lang.Object
java.lang.ClassLoader
org.apache.xbean.osgi.bundle.util.BundleClassLoader
- All Implemented Interfaces:
- org.osgi.framework.BundleReference
public class BundleClassLoader
- extends ClassLoader
- implements org.osgi.framework.BundleReference
ClassLoader for a Bundle
.
In OSGi, resource lookup on resources in the META-INF directory using Bundle.getResource(String)
or
Bundle.getResources(String)
does not return the resources found in the wired bundles of the bundle
(wired via Import-Package or DynamicImport-Package). This class loader implementation provides
#getResource(String) and {@link #getResources(String)} methods that do delegate such resource lookups to
the wired bundles.
- Version:
- $Rev: 938291 $ $Date: 2010-04-26 21:53:06 -0400 (Mon, 26 Apr 2010) $
Methods inherited from class java.lang.ClassLoader |
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResourceAsStream, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
BundleClassLoader
public BundleClassLoader(org.osgi.framework.Bundle bundle)
BundleClassLoader
public BundleClassLoader(org.osgi.framework.Bundle bundle,
boolean searchWiredBundles)
loadClass
public Class<?> loadClass(String name)
throws ClassNotFoundException
- Overrides:
loadClass
in class ClassLoader
- Throws:
ClassNotFoundException
loadClass
protected Class<?> loadClass(String name,
boolean resolve)
throws ClassNotFoundException
- Overrides:
loadClass
in class ClassLoader
- Throws:
ClassNotFoundException
toString
public String toString()
- Overrides:
toString
in class Object
getResource
public URL getResource(String name)
- Overrides:
getResource
in class ClassLoader
getResources
public Enumeration<URL> getResources(String name)
throws IOException
- Overrides:
getResources
in class ClassLoader
- Throws:
IOException
setSearchWiredBundles
public void setSearchWiredBundles(boolean search)
getSearchWiredBundles
public boolean getSearchWiredBundles()
getBundle
public org.osgi.framework.Bundle getBundle(boolean unwrap)
- Return the bundle associated with this classloader.
In most cases the bundle associated with the classloader is a regular framework bundle.
However, in some cases the bundle associated with the classloader is a
DelegatingBundle
.
In such cases, the unwrap parameter controls whether this function returns the
DelegatingBundle
instance or the main application bundle backing with the DelegatingBundle
.
- Parameters:
unwrap
- If true and if the bundle associated with this classloader is a DelegatingBundle
,
this function will return the main application bundle backing with the DelegatingBundle
.
Otherwise, the bundle associated with this classloader is returned as is.
- Returns:
- The bundle associated with this classloader.
getBundle
public org.osgi.framework.Bundle getBundle()
- Return the bundle associated with this classloader.
This method calls
getBundle(true)
and therefore always returns a regular
framework bundle.
Note: Some libraries use BundleReference.getBundle()
to obtain a bundle for the given
classloader and expect the returned bundle instance to be work with any OSGi API. Some of these API might
not work if DelegatingBundle
is returned. That is why this function will always return
a regular framework bundle. See getBundle(boolean)
for more information.
- Specified by:
getBundle
in interface org.osgi.framework.BundleReference
- Returns:
- The bundle associated with this classloader.
hashCode
public int hashCode()
- Overrides:
hashCode
in class Object
equals
public boolean equals(Object other)
- Overrides:
equals
in class Object
Copyright © 2005-2013. All Rights Reserved.