org.eclipse.osgi.internal.loader
Class BundleLoader

java.lang.Object
  extended by org.eclipse.osgi.internal.loader.BundleLoader
All Implemented Interfaces:
ClassLoaderDelegate
Direct Known Subclasses:
SystemBundleLoader

public class BundleLoader
extends java.lang.Object
implements ClassLoaderDelegate

This object is responsible for all classloader delegation for a bundle. It represents the loaded state of the bundle. BundleLoader objects are created lazily; care should be taken not to force the creation of a BundleLoader unless it is necessary.

See Also:
BundleLoaderProxy

Field Summary
static org.eclipse.osgi.internal.loader.BundleLoader.ClassContext CLASS_CONTEXT
           
static java.lang.String DEFAULT_PACKAGE
           
static byte FLAG_CLOSED
           
static byte FLAG_HASDYNAMICEIMPORTALL
           
static byte FLAG_HASDYNAMICIMPORTS
           
static byte FLAG_IMPORTSINIT
           
static byte FLAG_LAZYTRIGGER
           
static java.lang.ClassLoader FW_CLASSLOADER
           
static java.lang.String JAVA_PACKAGE
           
 
Constructor Summary
protected BundleLoader(BundleHost bundle, BundleLoaderProxy proxy)
          BundleLoader runtime constructor.
 
Method Summary
 void addDynamicImportPackage(ManifestElement[] packages)
          Adds a list of DynamicImport-Package manifest elements to the dynamic import tables of this BundleLoader.
 void attachFragment(BundleFragment fragment)
           
static void closeBundleLoader(BundleLoaderProxy proxy)
           
static
<E> java.util.Enumeration<E>
compoundEnumerations(java.util.Enumeration<E> list1, java.util.Enumeration<E> list2)
           
 BundleClassLoader createClassLoader()
           
 java.lang.Class<?> findClass(java.lang.String name)
          Finds the class for a bundle.
 java.lang.String findLibrary(java.lang.String name)
          Returns the absolute path name of a native library.
 java.net.URL findResource(java.lang.String name)
          Finds the resource for a bundle.
 java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
          Finds the resources for a bundle.
 AbstractBundle getBundle()
           
 KeyedHashSet getImportedSources(KeyedHashSet visited)
           
 BundleLoaderProxy getLoaderProxy()
           
 BundleLoaderProxy getLoaderProxy(BundleDescription source)
           
static java.lang.String getPackageName(java.lang.String name)
          Returns the package name from the specified class name.
 PackageSource getPackageSource(java.lang.String pkgName)
           
 java.lang.ClassLoader getParentClassLoader()
           
static java.lang.String getResourcePackageName(java.lang.String name)
          Returns the package name from the specified resource name.
 java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
           
 boolean isLazyTriggerSet()
          Returns true if the lazy trigger has been set for this delegate.
 java.util.Collection<java.lang.String> listResources(java.lang.String path, java.lang.String filePattern, int options)
          Returns the names of resources visible to this delegate.
 java.lang.Class<?> loadClass(java.lang.String name)
          This method loads a class from the bundle.
 void setLazyTrigger()
          Sets the lazy trigger for this delegate.
 java.lang.String toString()
          Return a string representation of this loader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PACKAGE

public static final java.lang.String DEFAULT_PACKAGE
See Also:
Constant Field Values

JAVA_PACKAGE

public static final java.lang.String JAVA_PACKAGE
See Also:
Constant Field Values

FLAG_IMPORTSINIT

public static final byte FLAG_IMPORTSINIT
See Also:
Constant Field Values

FLAG_HASDYNAMICIMPORTS

public static final byte FLAG_HASDYNAMICIMPORTS
See Also:
Constant Field Values

FLAG_HASDYNAMICEIMPORTALL

public static final byte FLAG_HASDYNAMICEIMPORTALL
See Also:
Constant Field Values

FLAG_CLOSED

public static final byte FLAG_CLOSED
See Also:
Constant Field Values

FLAG_LAZYTRIGGER

public static final byte FLAG_LAZYTRIGGER
See Also:
Constant Field Values

CLASS_CONTEXT

public static final org.eclipse.osgi.internal.loader.BundleLoader.ClassContext CLASS_CONTEXT

FW_CLASSLOADER

public static final java.lang.ClassLoader FW_CLASSLOADER
Constructor Detail

BundleLoader

protected BundleLoader(BundleHost bundle,
                       BundleLoaderProxy proxy)
                throws BundleException
BundleLoader runtime constructor. This object is created lazily when the first request for a resource is made to this bundle.

Parameters:
bundle - Bundle object for this loader.
proxy - the BundleLoaderProxy for this loader.
Throws:
BundleException
Method Detail

getPackageName

public static final java.lang.String getPackageName(java.lang.String name)
Returns the package name from the specified class name. The returned package is dot seperated.

Parameters:
name - Name of a class.
Returns:
Dot separated package name or null if the class has no package name.

getResourcePackageName

public static final java.lang.String getResourcePackageName(java.lang.String name)
Returns the package name from the specified resource name. The returned package is dot seperated.

Parameters:
name - Name of a resource.
Returns:
Dot separated package name or null if the resource has no package name.

getImportedSources

public KeyedHashSet getImportedSources(KeyedHashSet visited)

isLazyTriggerSet

public boolean isLazyTriggerSet()
Description copied from interface: ClassLoaderDelegate
Returns true if the lazy trigger has been set for this delegate. The lazy trigger is set when a bundle has been marked for lazy activation due to a successful class load.

Specified by:
isLazyTriggerSet in interface ClassLoaderDelegate
Returns:
true if the lazy trigger has been set

setLazyTrigger

public void setLazyTrigger()
                    throws BundleException
Description copied from interface: ClassLoaderDelegate
Sets the lazy trigger for this delegate. This will activate the bundle if the bundle has been started with the activation policy and the bundle's start level is met.

Specified by:
setLazyTrigger in interface ClassLoaderDelegate
Throws:
BundleException - if an error occurred while activating the bundle
See Also:
ClassLoaderDelegate.isLazyTriggerSet()

getLoaderProxy

public final BundleLoaderProxy getLoaderProxy(BundleDescription source)

getLoaderProxy

public BundleLoaderProxy getLoaderProxy()

loadClass

public final java.lang.Class<?> loadClass(java.lang.String name)
                                   throws java.lang.ClassNotFoundException
This method loads a class from the bundle. The class is searched for in the same manner as it would if it was being loaded from a bundle (i.e. all hosts, fragments, import, required bundles and local resources are searched.

Parameters:
name - the name of the desired Class.
Returns:
the resulting Class
Throws:
java.lang.ClassNotFoundException - if the class definition was not found.

getParentClassLoader

public final java.lang.ClassLoader getParentClassLoader()

createClassLoader

public final BundleClassLoader createClassLoader()

findClass

public java.lang.Class<?> findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Finds the class for a bundle. This method is used for delegation by the bundle's classloader.

Specified by:
findClass in interface ClassLoaderDelegate
Parameters:
name - the class to find.
Returns:
the Class.
Throws:
java.lang.ClassNotFoundException - if the class is not found.

findResource

public java.net.URL findResource(java.lang.String name)
Finds the resource for a bundle. This method is used for delegation by the bundle's classloader.

Specified by:
findResource in interface ClassLoaderDelegate
Parameters:
name - the resource to load.
Returns:
the resource or null if resource is not found.

findResources

public java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
                                                  throws java.io.IOException
Finds the resources for a bundle. This method is used for delegation by the bundle's classloader.

Specified by:
findResources in interface ClassLoaderDelegate
Parameters:
name - the resource to find.
Returns:
the enumeration of resources found or null if the resource does not exist.
Throws:
java.io.IOException

listResources

public java.util.Collection<java.lang.String> listResources(java.lang.String path,
                                                            java.lang.String filePattern,
                                                            int options)
Description copied from interface: ClassLoaderDelegate
Returns the names of resources visible to this delegate. This is used to answer a call to the BundleWiring.listResources(String, String, int) method. First a search is done on the packages imported by the bundle associated with this delegate. Next a search is done on the the bundles required by the bundle associated with this delegate. Finally a local search of the bundle associated with this delegate is done by calling BundleClassLoader.listLocalResources(String, String, int). Note that for imported packages the search stops at the source for the import.

Specified by:
listResources in interface ClassLoaderDelegate
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)

getResources

public java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
                                                 throws java.io.IOException
Throws:
java.io.IOException

compoundEnumerations

public static <E> java.util.Enumeration<E> compoundEnumerations(java.util.Enumeration<E> list1,
                                                                java.util.Enumeration<E> list2)

findLibrary

public java.lang.String findLibrary(java.lang.String name)
Returns the absolute path name of a native library.

Specified by:
findLibrary in interface ClassLoaderDelegate
Parameters:
name - the library name
Returns:
the absolute path of the native library or null if not found

getBundle

public final AbstractBundle getBundle()

toString

public final java.lang.String toString()
Return a string representation of this loader.

Overrides:
toString in class java.lang.Object
Returns:
String

addDynamicImportPackage

public final void addDynamicImportPackage(ManifestElement[] packages)
Adds a list of DynamicImport-Package manifest elements to the dynamic import tables of this BundleLoader. Duplicate packages are checked and not added again.

Parameters:
packages - the DynamicImport-Package elements to add.

attachFragment

public void attachFragment(BundleFragment fragment)
                    throws BundleException
Throws:
BundleException

getPackageSource

public final PackageSource getPackageSource(java.lang.String pkgName)

closeBundleLoader

public static void closeBundleLoader(BundleLoaderProxy proxy)


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