org.knopflerfish.framework
Class BundleImpl

java.lang.Object
  extended by org.knopflerfish.framework.BundleImpl
All Implemented Interfaces:
Bundle
Direct Known Subclasses:
SystemBundle

public class BundleImpl
extends java.lang.Object
implements Bundle

Implementation of the Bundle object.

See Also:
Bundle

Field Summary
protected  BundleActivator bactivator
          BundleActivator for bundle.
protected  BundleContextImpl bundleContext
          BundleContext for bundle.
protected  FileTree bundleDir
          Directory for bundle data.
protected  long lastModified
          Time when bundle was last modified.
 
Fields inherited from interface org.osgi.framework.Bundle
ACTIVE, INSTALLED, RESOLVED, STARTING, STOPPING, UNINSTALLED
 
Method Summary
 java.util.Enumeration findEntries(java.lang.String path, java.lang.String filePattern, boolean recurse)
          Get bundle data.
 BundleContext getBundleContext()
          Returns this bundle's BundleContext.
 long getBundleId()
          Get bundle identifier.
 java.security.cert.Certificate[] getCertificates()
          Get protection domain for bundle.
 java.net.URL getEntry(java.lang.String name)
          Returns a URL to the specified entry in this bundle.
 java.util.Enumeration getEntryPaths(java.lang.String path)
          Returns an Enumeration of all the paths (String objects) to entries within the bundle whose longest sub-path matches the supplied path argument.
 java.util.Dictionary getHeaders()
          Get header data.
 java.util.Dictionary getHeaders(java.lang.String locale)
          Returns this bundle's Manifest headers and values localized to the specified locale.
 long getLastModified()
          Returns the time when this bundle was last modified.
 java.lang.String getLocation()
          Get bundle location.
 ServiceReference[] getRegisteredServices()
          Get services that this bundle has registrated.
 java.net.URL getResource(java.lang.String name)
          Find the specified resource from this bundle.
 java.util.Enumeration getResources(java.lang.String name)
          Find the specified resources from this bundle.
 ServiceReference[] getServicesInUse()
          Get services that this bundle uses.
 int getState()
          Get bundle state.
 java.lang.String getSymbolicName()
          Returns the symbolic name of this bundle as specified by its Bundle-SymbolicName manifest header.
 boolean hasPermission(java.lang.Object permission)
          Determine whether the bundle has the requested permission.
 java.lang.Class loadClass(java.lang.String name)
          Loads the specified class using this bundle's classloader.
protected  void readLocalization(java.lang.String locale, java.util.Hashtable localization_entries, java.lang.String baseName)
          Reads all localization entries that affects this bundle (including its host/fragments)
 void start()
          Start this bundle.
 void stop()
          Stop this bundle.
 java.lang.String toString()
          Return a string representing this bundle.
 void uninstall()
          Uninstall this bundle.
 void update()
          Update this bundle.
 void update(java.io.InputStream in)
          Update this bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

bundleDir

protected FileTree bundleDir
Directory for bundle data.


bundleContext

protected BundleContextImpl bundleContext
BundleContext for bundle.


bactivator

protected BundleActivator bactivator
BundleActivator for bundle.


lastModified

protected long lastModified
Time when bundle was last modified.

Method Detail

getState

public int getState()
Get bundle state.

Specified by:
getState in interface Bundle
Returns:
An element of UNINSTALLED,INSTALLED, RESOLVED,STARTING, STOPPING,ACTIVE.
See Also:
Bundle.getState()

start

public void start()
           throws BundleException
Start this bundle.

Specified by:
start in interface Bundle
Throws:
BundleException - If this bundle could not be started. This could be because a code dependency could not be resolved or the specified BundleActivator could not be loaded or threw an exception.
See Also:
Bundle.start()

stop

public void stop()
          throws BundleException
Stop this bundle.

Specified by:
stop in interface Bundle
Throws:
BundleException - If this bundle's BundleActivator could not be loaded or threw an exception.
See Also:
Bundle.stop()

update

public void update()
            throws BundleException
Update this bundle.

Specified by:
update in interface Bundle
Throws:
BundleException - If the update fails.
See Also:
Bundle.update()

update

public void update(java.io.InputStream in)
            throws BundleException
Update this bundle.

Specified by:
update in interface Bundle
Parameters:
in - The InputStream from which to read the new bundle.
Throws:
BundleException - If the provided stream cannot be read or the update fails.
See Also:
Bundle.update()

uninstall

public void uninstall()
               throws BundleException
Uninstall this bundle.

Specified by:
uninstall in interface Bundle
Throws:
BundleException - If the uninstall failed. This can occur if another thread is attempting to change the bundle's state and does not complete in a timely manner.
See Also:
Bundle.uninstall()

getHeaders

public java.util.Dictionary getHeaders()
Get header data. This is all entries in the bundles MANIFEST file.

Specified by:
getHeaders in interface Bundle
Returns:
A Dictionary object containing this bundle's Manifest headers and values.
See Also:
Bundle.getHeaders()

getBundleId

public long getBundleId()
Get bundle identifier.

Specified by:
getBundleId in interface Bundle
Returns:
The unique identifier of this bundle.
See Also:
Bundle.getBundleId()

getLocation

public java.lang.String getLocation()
Get bundle location.

Specified by:
getLocation in interface Bundle
Returns:
The string representation of this bundle's location identifier.
See Also:
Bundle.getLocation()

getRegisteredServices

public ServiceReference[] getRegisteredServices()
Get services that this bundle has registrated.

Specified by:
getRegisteredServices in interface Bundle
Returns:
An array of ServiceReference objects or null.
See Also:
Bundle.getRegisteredServices()

getServicesInUse

public ServiceReference[] getServicesInUse()
Get services that this bundle uses.

Specified by:
getServicesInUse in interface Bundle
Returns:
An array of ServiceReference objects or null.
See Also:
Bundle.getServicesInUse()

hasPermission

public boolean hasPermission(java.lang.Object permission)
Determine whether the bundle has the requested permission.

Specified by:
hasPermission in interface Bundle
Parameters:
permission - The permission to verify.
Returns:
true if this bundle has the specified permission or the permissions possessed by this bundle imply the specified permission; false if this bundle does not have the specified permission or permission is not an instanceof java.security.Permission.
See Also:
Bundle.hasPermission(java.lang.Object)

getBundleContext

public BundleContext getBundleContext()
Returns this bundle's BundleContext. This method will be introduced in OSGi R4.1 but included here as a migration step.

Specified by:
getBundleContext in interface Bundle
Returns:
A BundleContext for this bundle or null if this bundle has no valid BundleContext.
Since:
1.4
See Also:
Bundle.getBundleContext()

getResource

public java.net.URL getResource(java.lang.String name)
Description copied from interface: Bundle
Find the specified resource from this bundle. This bundle's class loader is called to search for the specified resource. If this bundle's state is INSTALLED, this method must attempt to resolve the bundle before attempting to get the specified resource. If this bundle cannot be resolved, then only this bundle must be searched for the specified resource. Imported packages cannot be searched when a bundle has not been resolved. If this bundle is a fragment bundle then null is returned.

Specified by:
getResource in interface Bundle
Parameters:
name - The name of the resource. See java.lang.ClassLoader.getResource for a description of the format of a resource name.
Returns:
A URL to the named resource, or null if the resource could not be found or if this bundle is a fragment bundle or if the caller does not have the appropriate AdminPermission[this,RESOURCE], and the Java Runtime Environment supports permissions.
See Also:
Bundle.getResource(String name)

getSymbolicName

public java.lang.String getSymbolicName()
Description copied from interface: Bundle
Returns the symbolic name of this bundle as specified by its Bundle-SymbolicName manifest header. The name must be unique, it is recommended to use a reverse domain name naming convention like that used for java packages. If the bundle does not have a specified symbolic name then null is returned.

This method must continue to return this bundle's symbolic name while this bundle is in the UNINSTALLED state.

Specified by:
getSymbolicName in interface Bundle
Returns:
The symbolic name of this bundle.
See Also:
Bundle.getSymbolicName()

getCertificates

public java.security.cert.Certificate[] getCertificates()
Get protection domain for bundle. Used by BundleSignerCondition.


toString

public java.lang.String toString()
Return a string representing this bundle. Only return identifier, since it requires AdminPermisson to get the location.

Overrides:
toString in class java.lang.Object
Returns:
a String representing this bundle.

findEntries

public java.util.Enumeration findEntries(java.lang.String path,
                                         java.lang.String filePattern,
                                         boolean recurse)
Get bundle data. Get resources from bundle or fragment jars.

Specified by:
findEntries in interface Bundle
Parameters:
path - The path name in which to look. A specified path of "/" indicates the root of the bundle. Path is relative to the root of the bundle and must not be null.
filePattern - The file name pattern for selecting entries in the specified path. The pattern is only matched against the last element of the entry path and it supports substring matching, as specified in the Filter specification, using the wildcard character ("*"). If null is specified, this is equivalent to "*" and matches all files.
recurse - If true, recurse into subdirectories. Otherwise only return entries from the given directory.
Returns:
An enumeration of URL objects for each matching entry, or null if an entry could not be found or if the caller does not have the appropriate AdminPermission[this,RESOURCE], and the Java Runtime Environment supports permissions. The URLs are sorted such that entries from this bundle are returned first followed by the entries from attached fragments in ascending bundle id order. If this bundle is a fragment, then only matching entries in this fragment are returned.
See Also:
Bundle.findEntries(java.lang.String, java.lang.String, boolean)

getEntry

public java.net.URL getEntry(java.lang.String name)
Description copied from interface: Bundle
Returns a URL to the specified entry in this bundle. The bundle's classloader is not used to search for the specified entry. Only the contents of the bundle is searched for the specified entry. A specified path of "/" indicates the root of the bundle.

Specified by:
getEntry in interface Bundle
Parameters:
name - The name of the entry. See java.lang.ClassLoader.getResource for a description of the format of a resource name.
Returns:
A URL to the specified entry, or null if no entry could be found or if the caller does not have the appropriate AdminPermission[this,RESOURCE] and the Java Runtime Environment supports permissions.

getEntryPaths

public java.util.Enumeration getEntryPaths(java.lang.String path)
Description copied from interface: Bundle
Returns an Enumeration of all the paths (String objects) to entries within the bundle whose longest sub-path matches the supplied path argument. The bundle's classloader is not used to search for entries. Only the contents of the bundle is searched. A specified path of "/" indicates the root of the bundle.

Returned paths indicating subdirectory paths end with a "/". The returned paths are all relative to the root of the bundle.

Specified by:
getEntryPaths in interface Bundle
Parameters:
path - The path name for which to return entry paths.
Returns:
An Enumeration of the entry paths (String objects) or null if no entry could be found or if the caller does not have the appropriate AdminPermission[this,RESOURCE] and the Java Runtime Environment supports permissions.

readLocalization

protected void readLocalization(java.lang.String locale,
                                java.util.Hashtable localization_entries,
                                java.lang.String baseName)
Reads all localization entries that affects this bundle (including its host/fragments)

Parameters:
locale - locale == "" the bundle.properties will be read o/w it will read the files as described in the spec.
localization_entries - will append the new entries to this dictionary
baseName - the basename for localization properties, null will choose OSGi default

getHeaders

public java.util.Dictionary getHeaders(java.lang.String locale)
Description copied from interface: Bundle
Returns this bundle's Manifest headers and values localized to the specified locale.

This method performs the same function as Bundle.getHeaders() except the manifest header values are localized to the specified locale.

If a Manifest header value starts with "%", it must be localized according to the specified locale. If a locale is specified and cannot be found, then the header values must be returned using the default locale. Localizations are searched for in the following order:

   bn + "_" + Ls + "_" + Cs + "_" + Vs
   bn + "_" + Ls + "_" + Cs
   bn + "_" + Ls
   bn + "_" + Ld + "_" + Cd + "_" + Vd
   bn + "_" + Ld + "_" + Cd
   bn + "_" + Ld
   bn
 
Where bn is the bundle localization basename, Ls, Cs and Vs are the specified locale (language, country, variant) and Ld, Cd and Vd are the default locale (language, country, variant). If null is specified as the locale string, the header values must be localized using the default locale. If the empty string ("") is specified as the locale string, the header values must not be localized and the raw (unlocalized) header values, including any leading "%", must be returned.

This method must continue to return Manifest header information while this bundle is in the UNINSTALLED state, however the header values must only be available in the raw and default locale values.

Specified by:
getHeaders in interface Bundle
Parameters:
locale - The locale name into which the header values are to be localized. If the specified locale is null then the locale returned by java.util.Locale.getDefault is used. If the specified locale is the empty string, this method will return the raw (unlocalized) manifest headers including any leading "%".
Returns:
A Dictionary object containing this bundle's Manifest headers and values.
See Also:
Bundle.getHeaders(String locale)

getLastModified

public long getLastModified()
Description copied from interface: Bundle
Returns the time when this bundle was last modified. A bundle is considered to be modified when it is installed, updated or uninstalled.

The time value is the number of milliseconds since January 1, 1970, 00:00:00 GMT.

Specified by:
getLastModified in interface Bundle
Returns:
The time when this bundle was last modified.
See Also:
Bundle.getLastModified()

getResources

public java.util.Enumeration getResources(java.lang.String name)
                                   throws java.io.IOException
Description copied from interface: Bundle
Find the specified resources from this bundle. This bundle's class loader is called to search for the specified resources. If this bundle's state is INSTALLED, this method must attempt to resolve the bundle before attempting to get the specified resources. If this bundle cannot be resolved, then only this bundle must be searched for the specified resources. Imported packages cannot be searched when a bundle has not been resolved. If this bundle is a fragment bundle then null is returned.

Specified by:
getResources in interface Bundle
Parameters:
name - The name of the resource. See java.lang.ClassLoader.getResources for a description of the format of a resource name.
Returns:
An enumeration of URLs to the named resources, or null if the resource could not be found or if this bundle is a fragment bundle or if the caller does not have the appropriate AdminPermission[this,RESOURCE], and the Java Runtime Environment supports permissions.
Throws:
java.io.IOException - If there is an I/O error.
See Also:
Bundle.getResources(String name)

loadClass

public java.lang.Class loadClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Description copied from interface: Bundle
Loads the specified class using this bundle's classloader.

If the bundle is a fragment bundle then this method must throw a ClassNotFoundException.

If this bundle's state is INSTALLED, this method must attempt to resolve the bundle before attempting to load the class.

If the bundle cannot be resolved, a Framework event of type FrameworkEvent.ERROR is fired containing a BundleException with details of the reason the bundle could not be resolved. This method must then throw a ClassNotFoundException.

If this bundle's state is UNINSTALLED, then an IllegalStateException is thrown.

Specified by:
loadClass in interface Bundle
Parameters:
name - The name of the class to load.
Returns:
The Class object for the requested class.
Throws:
java.lang.ClassNotFoundException - If no such class can be found or if this bundle is a fragment bundle or if the caller does not have the appropriate AdminPermission[this,CLASS], and the Java Runtime Environment supports permissions.
See Also:
org.osgi.framework.Bundle#loadClass()