org.eclipse.osgi.framework.adaptor
Interface BundleClassLoader

All Known Subinterfaces:
BaseClassLoader

public interface BundleClassLoader

The BundleClassLoader interface is used by the Framework to load local classes and resources from a Bundle. Classes that implement this interface must extend java.lang.ClassLoader, either directly or by extending a subclass of java.lang.ClassLoader.

ClassLoaders that implement the BundleClassLoader interface must use a ClassLoaderDelegate to delegate all class, resource and native library lookups.

Clients may implement this interface.

Since:
3.1
See Also:
BundleData.createClassLoader(ClassLoaderDelegate, BundleProtectionDomain, String[])

Method Summary
 void attachFragment(BundleData bundledata, java.security.ProtectionDomain domain, java.lang.String[] classpath)
          Attaches the BundleData for a fragment to this BundleClassLoader.
 void close()
          Closes this class loader.
 java.lang.Class findLocalClass(java.lang.String classname)
          Finds a local class in the BundleClassLoader without consulting the delegate.
 java.net.URL findLocalResource(java.lang.String resource)
          Finds a local resource in the BundleClassLoader without consulting the delegate.
 java.util.Enumeration findLocalResources(java.lang.String resource)
          Finds all local resources in the BundleClassLoader with the specified path without consulting the delegate.
 ClassLoaderDelegate getDelegate()
          Returns the ClassLoaderDelegate used by this BundleClassLoader
 java.lang.ClassLoader getParent()
          Returns the parent classloader used by this BundleClassLoader
 java.net.URL getResource(java.lang.String name)
          This method will first search the parent class loader for the resource; That failing, this method will invoke ClassLoaderDelegate.findResource(String) to find the resource.
 java.util.Enumeration getResources(java.lang.String name)
          This method will first search the parent class loader for the resource; That failing, this method will invoke ClassLoaderDelegate.findResource(String) to find the resource.
 void initialize()
          Initializes the ClassLoader.
 java.lang.Class loadClass(java.lang.String name)
          This method will first search the parent class loader for the class; That failing, this method will invoke ClassLoaderDelegate.findClass(String) to find the resource.
 

Method Detail

initialize

void initialize()
Initializes the ClassLoader. This is called after all currently resolved fragment bundles have been attached to the BundleClassLoader by the Framework.


findLocalResource

java.net.URL findLocalResource(java.lang.String resource)
Finds a local resource in the BundleClassLoader without consulting the delegate.

Parameters:
resource - the resource path to find.
Returns:
a URL to the resource or null if the resource does not exist.

findLocalResources

java.util.Enumeration findLocalResources(java.lang.String resource)
Finds all local resources in the BundleClassLoader with the specified path without consulting the delegate.

Parameters:
resource - the resource path to find.
Returns:
An Enumeration of all resources found or null if the resource. does not exist.

findLocalClass

java.lang.Class findLocalClass(java.lang.String classname)
                               throws java.lang.ClassNotFoundException
Finds a local class in the BundleClassLoader without consulting the delegate.

Parameters:
classname - the classname to find.
Returns:
The class object found.
Throws:
java.lang.ClassNotFoundException - if the classname does not exist locally.

getResource

java.net.URL getResource(java.lang.String name)
This method will first search the parent class loader for the resource; That failing, this method will invoke ClassLoaderDelegate.findResource(String) to find the resource.

Parameters:
name - the resource path to get.
Returns:
a URL for the resource or null if the resource is not found.

getResources

java.util.Enumeration getResources(java.lang.String name)
                                   throws java.io.IOException
This method will first search the parent class loader for the resource; That failing, this method will invoke ClassLoaderDelegate.findResource(String) to find the resource.

Parameters:
name - the resource path to get.
Returns:
an Enumeration of URL objects for the resource or null if the resource is not found.
Throws:
java.io.IOException

loadClass

java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
This method will first search the parent class loader for the class; That failing, this method will invoke ClassLoaderDelegate.findClass(String) to find the resource.

Parameters:
name - the class name to load.
Returns:
the Class.
Throws:
java.lang.ClassNotFoundException

close

void close()
Closes this class loader. After this method is called loadClass will always throw ClassNotFoundException, getResource, getResourceAsStream, getResources and will return null.


attachFragment

void attachFragment(BundleData bundledata,
                    java.security.ProtectionDomain domain,
                    java.lang.String[] classpath)
Attaches the BundleData for a fragment to this BundleClassLoader. The Fragment BundleData resources must be appended to the end of this BundleClassLoader's classpath. Fragment BundleData resources must be searched ordered by Bundle ID's.

Parameters:
bundledata - The BundleData of the fragment.
domain - The ProtectionDomain of the resources of the fragment. Any classes loaded from the fragment's BundleData must belong to this ProtectionDomain.
classpath - An array of Bundle-ClassPath entries to use for loading classes and resources. This is specified by the Bundle-ClassPath manifest entry of the fragment.

getDelegate

ClassLoaderDelegate getDelegate()
Returns the ClassLoaderDelegate used by this BundleClassLoader

Returns:
the ClassLoaderDelegate used by this BundleClassLoader

getParent

java.lang.ClassLoader getParent()
Returns the parent classloader used by this BundleClassLoader

Returns:
the parent classloader used by this BundleClassLoader