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 java.lang.ClassLoader
implements ParallelClassLoader

The default implementation of BaseClassLoader. This implementation extends ClassLoader.

See Also:
BaseClassLoader, ClasspathManager

Field Summary
protected static java.security.PermissionCollection ALLPERMISSIONS
          A PermissionCollection for AllPermissions; shared across all ProtectionDomains when security is disabled
protected  ClassLoaderDelegate delegate
           
protected  java.security.ProtectionDomain domain
           
protected  ClasspathManager manager
           
 
Constructor Summary
DefaultClassLoader(java.lang.ClassLoader parent, ClassLoaderDelegate delegate, java.security.ProtectionDomain domain, BaseData bundledata, java.lang.String[] classpath)
          Constructs a new DefaultClassLoader.
 
Method Summary
 void attachFragment(BundleData sourcedata, java.security.ProtectionDomain sourcedomain, java.lang.String[] sourceclasspath)
          Attaches the BundleData for a fragment to this BundleClassLoader.
 void close()
          Closes this class loader.
 ClasspathEntry createClassPathEntry(BundleFile bundlefile, java.security.ProtectionDomain cpDomain)
          Creates a classpath entry with the given bundle file and domain
static java.security.ProtectionDomain createProtectionDomain(BundleFile bundlefile, java.security.ProtectionDomain baseDomain)
          Creates a ProtectionDomain which uses specified BundleFile and the permissions of the baseDomain
 java.lang.Class defineClass(java.lang.String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry)
          Defines a Class.
protected  java.lang.String findLibrary(java.lang.String libname)
          Finds a library for this bundle.
 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.
protected  java.util.Enumeration findResources(java.lang.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
 java.security.ProtectionDomain getDomain()
          Returns the domain for the host bundle of this class loader
 java.net.URL getResource(java.lang.String name)
          Gets a resource for the bundle.
 void initialize()
          Initializes the ClassLoader.
 boolean isParallelCapable()
          Indicates if this class loader is parallel capable.
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Loads a class for the bundle.
 java.lang.Object publicDefinePackage(java.lang.String name, java.lang.String specTitle, java.lang.String specVersion, java.lang.String specVendor, java.lang.String implTitle, java.lang.String implVersion, java.lang.String implVendor, java.net.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.
 java.lang.Class publicFindLoaded(java.lang.String classname)
          A public version of the ClassLoader.findLoadedClass(java.lang.String) method.
 java.lang.Object publicGetPackage(java.lang.String pkgname)
          A public version of the ClassLoader#getPackage(java.lang.String) method.
 
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, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.osgi.framework.adaptor.BundleClassLoader
getParent, getResources, loadClass
 

Field Detail

ALLPERMISSIONS

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


delegate

protected ClassLoaderDelegate delegate

domain

protected java.security.ProtectionDomain domain

manager

protected ClasspathManager manager
Constructor Detail

DefaultClassLoader

public DefaultClassLoader(java.lang.ClassLoader parent,
                          ClassLoaderDelegate delegate,
                          java.security.ProtectionDomain domain,
                          BaseData bundledata,
                          java.lang.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 java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.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 java.lang.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:
java.lang.ClassNotFoundException - if the class is not found.

getResource

public java.net.URL getResource(java.lang.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 java.lang.ClassLoader
Parameters:
name - The resource path to get.
Returns:
The URL of the resource or null if it does not exist.

findResources

protected java.util.Enumeration findResources(java.lang.String name)
                                       throws java.io.IOException
Finds all resources with the specified name. This method must call delegate.findResources(name) to find all the resources.

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

findLibrary

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

Overrides:
findLibrary in class java.lang.ClassLoader
Parameters:
libname - The library to find.
Returns:
The URL of the resource or null if it does not exist.

getDomain

public java.security.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,
                                           java.security.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 java.lang.Class defineClass(java.lang.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 java.lang.Class publicFindLoaded(java.lang.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 java.lang.Object publicGetPackage(java.lang.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 java.lang.Object publicDefinePackage(java.lang.String name,
                                            java.lang.String specTitle,
                                            java.lang.String specVersion,
                                            java.lang.String specVendor,
                                            java.lang.String implTitle,
                                            java.lang.String implVersion,
                                            java.lang.String implVendor,
                                            java.net.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 java.net.URL findLocalResource(java.lang.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 java.util.Enumeration findLocalResources(java.lang.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 java.lang.Class findLocalClass(java.lang.String classname)
                               throws java.lang.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:
java.lang.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,
                           java.security.ProtectionDomain sourcedomain,
                           java.lang.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 java.security.ProtectionDomain createProtectionDomain(BundleFile bundlefile,
                                                                    java.security.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.


Copyright © 2007-2012 FuseSource, Corp.. All Rights Reserved.