org.knopflerfish.framework
Class PackageAdminImpl

java.lang.Object
  extended by org.knopflerfish.framework.PackageAdminImpl
All Implemented Interfaces:
PackageAdmin

public class PackageAdminImpl
extends java.lang.Object
implements PackageAdmin

Framework service which allows bundle programmers to inspect the packages exported in the framework and eagerly update or uninstall bundles. If present, there will only be a single instance of this service registered in the framework.

The term exported package (and the corresponding interface ExportedPackage) refers to a package that has actually been exported (as opposed to one that is available for export).

Note that the information about exported packages returned by this service is valid only until the next time refreshPackages(org.osgi.framework.Bundle[]) is called. If an ExportedPackage becomes stale, (that is, the package it references has been updated or removed as a result of calling PackageAdmin.refreshPackages()), its getName() and getSpecificationVersion() continue to return their old values, isRemovalPending() returns true, and getExportingBundle() and getImportingBundles() return null.

See Also:
PackageAdmin

Field Summary
 
Fields inherited from interface org.osgi.service.packageadmin.PackageAdmin
BUNDLE_TYPE_FRAGMENT
 
Method Summary
 Bundle getBundle(java.lang.Class clazz)
          Returns the bundle from which the specified class is loaded.
 Bundle[] getBundles(java.lang.String symbolicName, java.lang.String versionRange)
          Returns the bundles with the specified symbolic name whose bundle version is within the specified version range.
 int getBundleType(Bundle bundle)
          Returns the special type of the specified bundle.
 ExportedPackage getExportedPackage(java.lang.String name)
          Gets the ExportedPackage with the specified package name.
 ExportedPackage[] getExportedPackages(Bundle bundle)
          Gets the packages exported by the specified bundle.
 ExportedPackage[] getExportedPackages(java.lang.String name)
          Gets the exported packages for the specified package name.
 Bundle[] getFragments(Bundle bundle)
          Returns an array of attached fragment bundles for the specified bundle.
 Bundle[] getHosts(Bundle bundle)
          Returns an array containing the host bundle to which the specified fragment bundle is attached or null if the specified bundle is not attached to a host or is not a fragment bundle.
 RequiredBundle[] getRequiredBundles(java.lang.String symbolicName)
          Returns an array of required bundles having the specified symbolic name.
 void refreshPackages(Bundle[] bundles)
          Forces the update (replacement) or removal of packages exported by the specified bundles.
 boolean resolveBundles(Bundle[] bundles)
          Resolve the specified bundles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getExportedPackages

public ExportedPackage[] getExportedPackages(Bundle bundle)
Gets the packages exported by the specified bundle.

Specified by:
getExportedPackages in interface PackageAdmin
Parameters:
bundle - The bundle whose exported packages are to be returned, or null if all the packages currently exported in the framework are to be returned. If the specified bundle is the system bundle (that is, the bundle with id 0), this method returns all the packages on the system classpath whose name does not start with "java.". In an environment where the exhaustive list of packages on the system classpath is not known in advance, this method will return all currently known packages on the system classpath, that is, all packages on the system classpath that contains one or more classes that have been loaded.
Returns:
The array of packages exported by the specified bundle, or null if the specified bundle has not exported any packages.

getExportedPackages

public ExportedPackage[] getExportedPackages(java.lang.String name)
Gets the exported packages for the specified package name.

Specified by:
getExportedPackages in interface PackageAdmin
Parameters:
name - The name of the exported packages to be returned.
Returns:
An array of the exported packages, or null if no exported packages with the specified name exists.

getExportedPackage

public ExportedPackage getExportedPackage(java.lang.String name)
Gets the ExportedPackage with the specified package name. All exported packages will be checked for the specified name. In an environment where the exhaustive list of packages on the system classpath is not known in advance, this method attempts to see if the named package is on the system classpath. This means that this method may discover an ExportedPackage that was not present in the list returned by getExportedPackages().

Specified by:
getExportedPackage in interface PackageAdmin
Parameters:
name - The name of the exported package to be returned.
Returns:
The exported package with the specified name, or null if no expored package with that name exists.
See Also:
PackageAdmin.getExportedPackages(String)

refreshPackages

public void refreshPackages(Bundle[] bundles)
Forces the update (replacement) or removal of packages exported by the specified bundles.

Specified by:
refreshPackages in interface PackageAdmin
Parameters:
bundles - The bundles whose exported packages are to be updated or removed, or null for all bundles updated or uninstalled since the last call to this method.
See Also:
PackageAdmin.refreshPackages(org.osgi.framework.Bundle[])

resolveBundles

public boolean resolveBundles(Bundle[] bundles)
Description copied from interface: PackageAdmin
Resolve the specified bundles. The Framework must attempt to resolve the specified bundles that are unresolved. Additional bundles that are not included in the specified bundles may be resolved as a result of calling this method. A permissible implementation of this method is to attempt to resolve all unresolved bundles installed in the framework.

If null is specified then the Framework will attempt to resolve all unresolved bundles. This method must not cause any bundle to be refreshed, stopped, or started. This method will not return until the operation has completed.

Specified by:
resolveBundles in interface PackageAdmin
Parameters:
bundles - The bundles to resolve or null to resolve all unresolved bundles installed in the Framework.
Returns:
true if all specified bundles are resolved;

getRequiredBundles

public RequiredBundle[] getRequiredBundles(java.lang.String symbolicName)
Description copied from interface: PackageAdmin
Returns an array of required bundles having the specified symbolic name.

If null is specified, then all required bundles will be returned.

Specified by:
getRequiredBundles in interface PackageAdmin
Parameters:
symbolicName - The bundle symbolic name or null for all required bundles.
Returns:
An array of required bundles or null if no required bundles exist for the specified symbolic name.

getBundles

public Bundle[] getBundles(java.lang.String symbolicName,
                           java.lang.String versionRange)
Description copied from interface: PackageAdmin
Returns the bundles with the specified symbolic name whose bundle version is within the specified version range. If no bundles are installed that have the specified symbolic name, then null is returned. If a version range is specified, then only the bundles that have the specified symbolic name and whose bundle versions belong to the specified version range are returned. The returned bundles are ordered by version in descending version order so that the first element of the array contains the bundle with the highest version.

Specified by:
getBundles in interface PackageAdmin
Parameters:
symbolicName - The symbolic name of the desired bundles.
versionRange - The version range of the desired bundles, or null if all versions are desired.
Returns:
An array of bundles with the specified name belonging to the specified version range ordered in descending version order, or null if no bundles are found.
See Also:
Constants.BUNDLE_VERSION_ATTRIBUTE

getFragments

public Bundle[] getFragments(Bundle bundle)
Description copied from interface: PackageAdmin
Returns an array of attached fragment bundles for the specified bundle. If the specified bundle is a fragment then null is returned. If no fragments are attached to the specified bundle then null is returned.

This method does not attempt to resolve the specified bundle. If the specified bundle is not resolved then null is returned.

Specified by:
getFragments in interface PackageAdmin
Parameters:
bundle - The bundle whose attached fragment bundles are to be returned.
Returns:
An array of fragment bundles or null if the bundle does not have any attached fragment bundles or the bundle is not resolved.

getHosts

public Bundle[] getHosts(Bundle bundle)
Description copied from interface: PackageAdmin
Returns an array containing the host bundle to which the specified fragment bundle is attached or null if the specified bundle is not attached to a host or is not a fragment bundle. A fragment may only be attached to a single host bundle.

Specified by:
getHosts in interface PackageAdmin
Parameters:
bundle - The bundle whose host bundle is to be returned.
Returns:
An array containing the host bundle or null if the bundle does not have a host bundle.

getBundle

public Bundle getBundle(java.lang.Class clazz)
Description copied from interface: PackageAdmin
Returns the bundle from which the specified class is loaded. The class loader of the returned bundle must have been used to load the specified class. If the class was not loaded by a bundle class loader then null is returned.

Specified by:
getBundle in interface PackageAdmin
Parameters:
clazz - The class object from which to locate the bundle.
Returns:
The bundle from which the specified class is loaded or null if the class was not loaded by a bundle class loader.

getBundleType

public int getBundleType(Bundle bundle)
Description copied from interface: PackageAdmin
Returns the special type of the specified bundle. The bundle type values are: A bundle may be more than one type at a time. A type code is used to identify the bundle type for future extendability.

If a bundle is not one or more of the defined types then 0x00000000 is returned.

Specified by:
getBundleType in interface PackageAdmin
Parameters:
bundle - The bundle for which to return the special type.
Returns:
The special type of the bundle.