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 java.lang.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-27 03:53:06 +0200 (Tue, 27 Apr 2010) $
Method Summary |
boolean |
equals(java.lang.Object other)
|
org.osgi.framework.Bundle |
getBundle()
Return the bundle associated with this classloader. |
org.osgi.framework.Bundle |
getBundle(boolean unwrap)
Return the bundle associated with this classloader. |
java.net.URL |
getResource(java.lang.String name)
|
java.util.Enumeration<java.net.URL> |
getResources(java.lang.String name)
|
boolean |
getSearchWiredBundles()
|
int |
hashCode()
|
java.lang.Class<?> |
loadClass(java.lang.String name)
|
protected java.lang.Class<?> |
loadClass(java.lang.String name,
boolean resolve)
|
void |
setSearchWiredBundles(boolean search)
|
java.lang.String |
toString()
|
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 |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
BundleClassLoader
public BundleClassLoader(org.osgi.framework.Bundle bundle)
BundleClassLoader
public BundleClassLoader(org.osgi.framework.Bundle bundle,
boolean searchWiredBundles)
loadClass
public java.lang.Class<?> loadClass(java.lang.String name)
throws java.lang.ClassNotFoundException
- Overrides:
loadClass
in class java.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
loadClass
protected java.lang.Class<?> loadClass(java.lang.String name,
boolean resolve)
throws java.lang.ClassNotFoundException
- Overrides:
loadClass
in class java.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
getResource
public java.net.URL getResource(java.lang.String name)
- Overrides:
getResource
in class java.lang.ClassLoader
getResources
public java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
throws java.io.IOException
- Overrides:
getResources
in class java.lang.ClassLoader
- Throws:
java.io.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 java.lang.Object
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in class java.lang.Object
Copyright © 2005-2011. All Rights Reserved.