org.eclipse.osgi.internal.baseadaptor
Class DefaultClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader
All Implemented Interfaces:
BaseClassLoader, ParallelClassLoader, BundleClassLoader, BundleReference

public class DefaultClassLoader
extends ClassLoader
implements ParallelClassLoader

The default implementation of BaseClassLoader. This implementation extends ClassLoader.

See Also:
BaseClassLoader, ClasspathManager

Field Summary
protected static PermissionCollection ALLPERMISSIONS
          A PermissionCollection for AllPermissions; shared across all ProtectionDomains when security is disabled
protected  ClassLoaderDelegate delegate
           
protected  ProtectionDomain domain
           
protected  ClasspathManager manager
           
 
Constructor Summary
DefaultClassLoader(ClassLoader parent, ClassLoaderDelegate delegate, ProtectionDomain domain, BaseData bundledata, String[] classpath)
          Constructs a new DefaultClassLoader.
 
Method Summary
 void attachFragment(BundleData sourcedata, ProtectionDomain sourcedomain, String[] sourceclasspath)
          Attaches the BundleData for a fragment to this BundleClassLoader.
 void close()
          Closes this class loader.
 ClasspathEntry createClassPathEntry(BundleFile bundlefile, ProtectionDomain cpDomain)
          Creates a classpath entry with the given bundle file and domain
static ProtectionDomain createProtectionDomain(BundleFile bundlefile, ProtectionDomain baseDomain)
          Creates a ProtectionDomain which uses specified BundleFile and the permissions of the baseDomain
 Class<?> defineClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry)
          Defines a Class.
 List<URL> findEntries(String path, String filePattern, int options)
          Returns resource entries for the bundle associated with this class loader.
protected  String findLibrary(String libname)
          Finds a library for this bundle.
 Class<?> findLocalClass(String classname)
          Finds a local class in the BundleClassLoader without consulting the delegate.
 URL findLocalResource(String resource)
          Finds a local resource in the BundleClassLoader without consulting the delegate.
 Enumeration<URL> findLocalResources(String resource)
          Finds all local resources in the BundleClassLoader with the specified path without consulting the delegate.
protected  Enumeration<URL> findResources(String name)
          Finds all resources with the specified name.
 Bundle getBundle()
          Returns the Bundle object associated with this BundleReference.
 ClasspathManager getClasspathManager()
          Returns the ClasspathManager for this BaseClassLoader
 ClassLoaderDelegate getDelegate()
          Returns the ClassLoaderDelegate used by this BundleClassLoader
 ProtectionDomain getDomain()
          Returns the domain for the host bundle of this class loader
 URL getResource(String name)
          Gets a resource for the bundle.
 void initialize()
          Initializes the ClassLoader.
 boolean isParallelCapable()
          Indicates if this class loader is parallel capable.
 Collection<String> listLocalResources(String path, String filePattern, int options)
          Returns the names of local resources visible to this bundle class loader.
 Collection<String> listResources(String path, String filePattern, int options)
          Returns the names of resources visible to this bundle class loader.
protected  Class<?> loadClass(String name, boolean resolve)
          Loads a class for the bundle.
 Object publicDefinePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)
          A public version of the ClassLoader#definePackage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.net.URL) method.
 Class<?> publicFindLoaded(String classname)
          A public version of the ClassLoader.findLoadedClass(java.lang.String) method.
 Object publicGetPackage(String pkgname)
          A public version of the ClassLoader#getPackage(java.lang.String) method.
 String toString()
           
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLoadedClass, findResource, findSystemClass, getPackage, getPackages, getParent, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.osgi.framework.adaptor.BundleClassLoader
getParent, getResources, loadClass
 

Field Detail

ALLPERMISSIONS

protected static final PermissionCollection ALLPERMISSIONS
A PermissionCollection for AllPermissions; shared across all ProtectionDomains when security is disabled


delegate

protected ClassLoaderDelegate delegate

domain

protected ProtectionDomain domain

manager

protected ClasspathManager manager
Constructor Detail

DefaultClassLoader

public DefaultClassLoader(ClassLoader parent,
                          ClassLoaderDelegate delegate,
                          ProtectionDomain domain,
                          BaseData bundledata,
                          String[] classpath)
Constructs a new DefaultClassLoader.

Parameters:
parent - the parent classloader
delegate - the delegate for this classloader
domain - the domain for this classloader
bundledata - the bundledata for this classloader
classpath - the classpath for this classloader
Method Detail

loadClass

protected Class<?> loadClass(String name,
                             boolean resolve)
                      throws ClassNotFoundException
Loads a class for the bundle. First delegate.findClass(name) is called. The delegate will query the system class loader, bundle imports, bundle local classes, bundle hosts and fragments. The delegate will call BundleClassLoader.findLocalClass(name) to find a class local to this bundle.

Overrides:
loadClass in class ClassLoader
Parameters:
name - the name of the class to load.
resolve - indicates whether to resolve the loaded class or not.
Returns:
The Class object.
Throws:
ClassNotFoundException - if the class is not found.

getResource

public URL getResource(String name)
Gets a resource for the bundle. First delegate.findResource(name) is called. The delegate will query the system class loader, bundle imports, bundle local resources, bundle hosts and fragments. The delegate will call BundleClassLoader.findLocalResource(name) to find a resource local to this bundle.

Specified by:
getResource in interface BundleClassLoader
Overrides:
getResource in class ClassLoader
Parameters:
name - The resource path to get.
Returns:
The URL of the resource or null if it does not exist.

findResources

protected Enumeration<URL> findResources(String name)
                                  throws IOException
Finds all resources with the specified name. This method must call delegate.findResources(name) to find all the resources.

Overrides:
findResources in class ClassLoader
Parameters:
name - The resource path to find.
Returns:
An Enumeration of all resources found or null if the resource.
Throws:
IOException

findLibrary

protected String findLibrary(String libname)
Finds a library for this bundle. Simply calls manager.findLibrary(libname) to find the library.

Overrides:
findLibrary in class ClassLoader
Parameters:
libname - The library to find.
Returns:
The absolution path to the library or null if not found

getDomain

public ProtectionDomain getDomain()
Description copied from interface: BaseClassLoader
Returns the domain for the host bundle of this class loader

Specified by:
getDomain in interface BaseClassLoader
Returns:
the domain for the host bundle of this class loader

createClassPathEntry

public ClasspathEntry createClassPathEntry(BundleFile bundlefile,
                                           ProtectionDomain cpDomain)
Description copied from interface: BaseClassLoader
Creates a classpath entry with the given bundle file and domain

Specified by:
createClassPathEntry in interface BaseClassLoader
Parameters:
bundlefile - the source bundle file for a classpath entry
cpDomain - the source domain for a classpath entry
Returns:
a classpath entry with the given bundle file and domain

defineClass

public Class<?> defineClass(String name,
                            byte[] classbytes,
                            ClasspathEntry classpathEntry,
                            BundleEntry entry)
Description copied from interface: BaseClassLoader
Defines a Class.

Specified by:
defineClass in interface BaseClassLoader
Parameters:
name - the name of the class to define
classbytes - the bytes of the class to define
classpathEntry - the classpath entry used to load the class bytes
entry - the bundle entry used to load the class bytes
Returns:
a defined Class

publicFindLoaded

public Class<?> publicFindLoaded(String classname)
Description copied from interface: BaseClassLoader
A public version of the ClassLoader.findLoadedClass(java.lang.String) method.

Specified by:
publicFindLoaded in interface BaseClassLoader
Parameters:
classname - the class name to find.
Returns:
a loaded class

publicGetPackage

public Object publicGetPackage(String pkgname)
Description copied from interface: BaseClassLoader
A public version of the ClassLoader#getPackage(java.lang.String) method.

Specified by:
publicGetPackage in interface BaseClassLoader
Parameters:
pkgname - the package name to get.
Returns:
the package or null if it does not exist

publicDefinePackage

public Object publicDefinePackage(String name,
                                  String specTitle,
                                  String specVersion,
                                  String specVendor,
                                  String implTitle,
                                  String implVersion,
                                  String implVendor,
                                  URL sealBase)
Description copied from interface: BaseClassLoader
A public version of the ClassLoader#definePackage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.net.URL) method.

Specified by:
publicDefinePackage in interface BaseClassLoader
Returns:
a defined Package

initialize

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

Specified by:
initialize in interface BundleClassLoader

findLocalResource

public URL findLocalResource(String resource)
Description copied from interface: BundleClassLoader
Finds a local resource in the BundleClassLoader without consulting the delegate.

Specified by:
findLocalResource in interface BundleClassLoader
Parameters:
resource - the resource path to find.
Returns:
a URL to the resource or null if the resource does not exist.

findLocalResources

public Enumeration<URL> findLocalResources(String resource)
Description copied from interface: BundleClassLoader
Finds all local resources in the BundleClassLoader with the specified path without consulting the delegate.

Specified by:
findLocalResources in interface BundleClassLoader
Parameters:
resource - the resource path to find.
Returns:
An Enumeration of all resources found or null if the resource. does not exist.

findLocalClass

public Class<?> findLocalClass(String classname)
                        throws ClassNotFoundException
Description copied from interface: BundleClassLoader
Finds a local class in the BundleClassLoader without consulting the delegate.

Specified by:
findLocalClass in interface BundleClassLoader
Parameters:
classname - the classname to find.
Returns:
The class object found.
Throws:
ClassNotFoundException - if the classname does not exist locally.

close

public void close()
Description copied from interface: BundleClassLoader
Closes this class loader. After this method is called loadClass will always throw ClassNotFoundException, getResource, getResourceAsStream, getResources and will return null.

Specified by:
close in interface BundleClassLoader

attachFragment

public void attachFragment(BundleData sourcedata,
                           ProtectionDomain sourcedomain,
                           String[] sourceclasspath)
Description copied from interface: BundleClassLoader
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.

Specified by:
attachFragment in interface BundleClassLoader
Parameters:
sourcedata - The BundleData of the fragment.
sourcedomain - The ProtectionDomain of the resources of the fragment. Any classes loaded from the fragment's BundleData must belong to this ProtectionDomain.
sourceclasspath - 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

public ClassLoaderDelegate getDelegate()
Description copied from interface: BundleClassLoader
Returns the ClassLoaderDelegate used by this BundleClassLoader

Specified by:
getDelegate in interface BundleClassLoader
Returns:
the ClassLoaderDelegate used by this BundleClassLoader

createProtectionDomain

public static ProtectionDomain createProtectionDomain(BundleFile bundlefile,
                                                      ProtectionDomain baseDomain)
Creates a ProtectionDomain which uses specified BundleFile and the permissions of the baseDomain

Parameters:
bundlefile - The source bundlefile the domain is for.
baseDomain - The source domain.
Returns:
a ProtectionDomain which uses specified BundleFile and the permissions of the baseDomain

getClasspathManager

public ClasspathManager getClasspathManager()
Description copied from interface: BaseClassLoader
Returns the ClasspathManager for this BaseClassLoader

Specified by:
getClasspathManager in interface BaseClassLoader
Returns:
the ClasspathManager

getBundle

public Bundle getBundle()
Description copied from interface: BundleReference
Returns the Bundle object associated with this BundleReference.

Specified by:
getBundle in interface BundleReference
Returns:
The Bundle object associated with this BundleReference.

isParallelCapable

public boolean isParallelCapable()
Description copied from interface: ParallelClassLoader
Indicates if this class loader is parallel capable. Even if a class loader is able to be parallel capable there are some restrictions imposed by the VM which may prevent a class loader from being parallel capable. For example, some VMs may lock the class loader natively before delegating to a class loader. This type of locking will prevent a class loader from being parallel capable.

Specified by:
isParallelCapable in interface ParallelClassLoader
Returns:
true if this class loader is parallel capable; false otherwise.

findEntries

public List<URL> findEntries(String path,
                             String filePattern,
                             int options)
Description copied from interface: BundleClassLoader
Returns resource entries for the bundle associated with this class loader. This is used to answer a call to the BundleWiring.findEntries(String, String, int) method.

Specified by:
findEntries in interface BundleClassLoader
Parameters:
path - The path name in which to look.
filePattern - The file name pattern for selecting resource names in the specified path.
options - The options for listing resource names.
Returns:
a list of resource URLs. If no resources are found then the empty list is returned.
See Also:
BundleWiring#findEntries(String, String, int)}

listResources

public Collection<String> listResources(String path,
                                        String filePattern,
                                        int options)
Description copied from interface: BundleClassLoader
Returns the names of resources visible to this bundle class loader. This is used to answer a call to the BundleWiring.listResources(String, String, int) method. This method should simply return the result of calling ClassLoaderDelegate.listResources(String, String, int)

Specified by:
listResources in interface BundleClassLoader
Parameters:
path - The path name in which to look.
filePattern - The file name pattern for selecting resource names in the specified path.
options - The options for listing resource names.
Returns:
a collection of resource names. If no resources are found then the empty collection is returned.
See Also:
BundleWiring#listResources(String, String, int)}, ClassLoaderDelegate#listResources(String, String, int)}

listLocalResources

public Collection<String> listLocalResources(String path,
                                             String filePattern,
                                             int options)
Description copied from interface: BundleClassLoader
Returns the names of local resources visible to this bundle class loader. Only the resources available on the local class path of this bundle class loader are searched.

Specified by:
listLocalResources in interface BundleClassLoader
Parameters:
path - The path name in which to look.
filePattern - The file name pattern for selecting resource names in the specified path.
options - The options for listing resource names.
Returns:
a collection of resource names. If no resources are found then the empty collection is returned.
See Also:
ClassLoaderDelegate#listResources(String, String, int)}

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2007–2014 The Apache Software Foundation. All rights reserved.