public class BundleContextImpl extends java.lang.Object implements BundleContext
BundleContext| Constructor and Description |
|---|
BundleContextImpl(BundleImpl bundle)
Create a BundleContext for specified bundle.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBundleListener(BundleListener listener)
Add a bundle listener.
|
void |
addFrameworkListener(FrameworkListener listener)
Add a framework listener.
|
void |
addServiceListener(ServiceListener listener)
Add a service listener.
|
void |
addServiceListener(ServiceListener listener,
java.lang.String filter)
Add a service listener with a filter.
|
Filter |
createFilter(java.lang.String filter)
Constructs a Filter object.
|
ServiceReference[] |
getAllServiceReferences(java.lang.String clazz,
java.lang.String filter)
Get a list of service references.
|
Bundle |
getBundle()
Retrieve the Bundle object for the calling bundle.
|
Bundle |
getBundle(long id)
Retrieve the bundle that has the given unique identifier.
|
Bundle[] |
getBundles()
Retrieve a list of all installed bundles.
|
java.io.File |
getDataFile(java.lang.String filename)
Creates a File object for a file in the persistent storage
area provided for the bundle.
|
java.lang.String |
getProperty(java.lang.String key)
Retrieve the value of the named environment property.
|
java.lang.Object |
getService(ServiceReference reference)
Get the service object.
|
ServiceReference |
getServiceReference(java.lang.String clazz)
Get a service reference.
|
ServiceReference[] |
getServiceReferences(java.lang.String clazz,
java.lang.String filter)
Get a list of service references.
|
Bundle |
installBundle(java.lang.String location)
Install a bundle from location.
|
Bundle |
installBundle(java.lang.String location,
java.io.InputStream in)
Install a bundle from an InputStream.
|
ServiceRegistration |
registerService(java.lang.String[] clazzes,
java.lang.Object service,
java.util.Dictionary properties)
Register a service with multiple names.
|
ServiceRegistration |
registerService(java.lang.String clazz,
java.lang.Object service,
java.util.Dictionary properties)
Register a service with a single name.
|
void |
removeBundleListener(BundleListener listener)
Remove a bundle listener.
|
void |
removeFrameworkListener(FrameworkListener listener)
Remove a framework listener.
|
void |
removeServiceListener(ServiceListener listener)
Remove a service listener.
|
boolean |
ungetService(ServiceReference reference)
Unget the service object.
|
public BundleContextImpl(BundleImpl bundle)
public java.lang.String getProperty(java.lang.String key)
getProperty in interface BundleContextkey - The name of the requested property.null if
the property is undefined.BundleContext.getProperty(java.lang.String)public Bundle installBundle(java.lang.String location) throws BundleException
installBundle in interface BundleContextlocation - The location identifier of the bundle to install.Bundle object of the installed bundle.BundleException - If the installation failed.BundleContext.installBundle(java.lang.String)public Bundle installBundle(java.lang.String location, java.io.InputStream in) throws BundleException
installBundle in interface BundleContextlocation - The location identifier of the bundle to install.in - The InputStream object from which this bundle
will be read.Bundle object of the installed bundle.BundleException - If the provided stream cannot be read or the
installation failed.BundleContext.installBundle(java.lang.String)public Bundle getBundle()
getBundle in interface BundleContextBundle object associated with this
BundleContext.BundleContext.getBundle()public Bundle getBundle(long id)
getBundle in interface BundleContextid - The identifier of the bundle to retrieve.Bundle object or null if the
identifier does not match any installed bundle.BundleContext.getBundle()public Bundle[] getBundles()
getBundles in interface BundleContextBundle objects, one object per
installed bundle.BundleContext.getBundles()public void addServiceListener(ServiceListener listener, java.lang.String filter) throws InvalidSyntaxException
addServiceListener in interface BundleContextlistener - The ServiceListener object to be added.filter - The filter criteria.InvalidSyntaxException - If filter contains an
invalid filter string that cannot be parsed.BundleContext.addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)public void addServiceListener(ServiceListener listener)
addServiceListener in interface BundleContextlistener - The ServiceListener object to be added.BundleContext.addServiceListener(org.osgi.framework.ServiceListener, java.lang.String)public void removeServiceListener(ServiceListener listener)
removeServiceListener in interface BundleContextlistener - The ServiceListener to be removed.BundleContext.removeServiceListener(org.osgi.framework.ServiceListener)public void addBundleListener(BundleListener listener)
addBundleListener in interface BundleContextlistener - The BundleListener to be added.BundleContext.addBundleListener(org.osgi.framework.BundleListener)public void removeBundleListener(BundleListener listener)
removeBundleListener in interface BundleContextlistener - The BundleListener object to be removed.BundleContext.removeBundleListener(org.osgi.framework.BundleListener)public void addFrameworkListener(FrameworkListener listener)
addFrameworkListener in interface BundleContextlistener - The FrameworkListener object to be added.BundleContext.addFrameworkListener(org.osgi.framework.FrameworkListener)public void removeFrameworkListener(FrameworkListener listener)
removeFrameworkListener in interface BundleContextlistener - The FrameworkListener object to be
removed.BundleContext.removeFrameworkListener(org.osgi.framework.FrameworkListener)public ServiceRegistration registerService(java.lang.String[] clazzes, java.lang.Object service, java.util.Dictionary properties)
registerService in interface BundleContextclazzes - The class names under which the service can be located.
The class names in this array will be stored in the service's
properties under the key Constants.OBJECTCLASS.service - The service object or a ServiceFactory
object.properties - The properties for this service. The keys in the
properties object must all be String objects. See
Constants for a list of standard service property keys.
Changes should not be made to this object after calling this
method. To update the service's properties the
ServiceRegistration.setProperties(java.util.Dictionary) method must be called.
The set of properties may be null if the service
has no properties.ServiceRegistration object for use by the bundle
registering the service to update the service's properties or to
unregister the service.BundleContext.registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)public ServiceRegistration registerService(java.lang.String clazz, java.lang.Object service, java.util.Dictionary properties)
registerService in interface BundleContextclazz - The class name under which the service can be located.service - The service object or a ServiceFactory
object.properties - The properties for this service.ServiceRegistration object for use by the bundle
registering the service to update the service's properties or to
unregister the service.BundleContext.registerService(java.lang.String[], java.lang.Object, java.util.Dictionary)public ServiceReference[] getServiceReferences(java.lang.String clazz, java.lang.String filter) throws InvalidSyntaxException
getServiceReferences in interface BundleContextclazz - The class name with which the service was registered or
null for all services.filter - The filter criteria.ServiceReference objects or
null if no services are registered which satisfy
the search.InvalidSyntaxException - If filter contains an
invalid filter string that cannot be parsed.BundleContext.getServiceReferences(java.lang.String, java.lang.String)public ServiceReference[] getAllServiceReferences(java.lang.String clazz, java.lang.String filter) throws InvalidSyntaxException
getAllServiceReferences in interface BundleContextclazz - The class name with which the service was registered or
null for all services.filter - The filter criteria.ServiceReference objects or
null if no services are registered which satisfy
the search.InvalidSyntaxException - If filter contains an
invalid filter string that cannot be parsed.BundleContext.getAllServiceReferences(java.lang.String, java.lang.String)public ServiceReference getServiceReference(java.lang.String clazz)
getServiceReference in interface BundleContextclazz - The class name with which the service was registered.ServiceReference object, or null
if no services are registered which implement the named class.BundleContext.getServiceReference(java.lang.String)public java.lang.Object getService(ServiceReference reference)
getService in interface BundleContextreference - A reference to the service.reference or null if the service is
not registered or does not implement the classes under which it
was registered in the case of a ServiceFactory.BundleContext.getService(org.osgi.framework.ServiceReference)public boolean ungetService(ServiceReference reference)
ungetService in interface BundleContextreference - A reference to the service to be released.false if the context bundle's use count for the
service is zero or if the service has been unregistered;
true otherwise.BundleContext.ungetService(org.osgi.framework.ServiceReference)public java.io.File getDataFile(java.lang.String filename)
getDataFile in interface BundleContextfilename - A relative name to the file to be accessed.File object that represents the requested file
or null if the platform does not have file system
support.BundleContext.getDataFile(java.lang.String)public Filter createFilter(java.lang.String filter) throws InvalidSyntaxException
ServiceReference or a Dictionary.createFilter in interface BundleContextfilter - the filter string.InvalidSyntaxException - If the filter parameter contains
an invalid filter string which cannot be parsed.FrameworkUtil.createFilter(String)