Interface ComponentContext
-
public interface ComponentContextA Component Context object is used by a component instance to interact with its execution context including locating services by reference name. Each component instance has a unique Component Context.A component instance may have an activate method. If a component instance has a suitable and accessible activate method, this method will be called when a component configuration is activated. If the activate method takes a
ComponentContextargument, it will be passed the component instance's Component Context object. If the activate method takes aBundleContextargument, it will be passed the component instance's Bundle Context object. If the activate method takes aMapargument, it will be passed an unmodifiable Map containing the component properties.A component instance may have a deactivate method. If a component instance has a suitable and accessible deactivate method, this method will be called when the component configuration is deactivated. If the deactivate method takes a
ComponentContextargument, it will be passed the component instance's Component Context object. If the deactivate method takes aBundleContextargument, it will be passed the component instance's Bundle Context object. If the deactivate method takes aMapargument, it will be passed an unmodifiable Map containing the component properties. If the deactivate method takes anintorIntegerargument, it will be passed the reason code for the component instance's deactivation.- Version:
- $Revision: 6462 $
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddisableComponent(java.lang.String name)Disables the specified component name.voidenableComponent(java.lang.String name)Enables the specified component name.org.osgi.framework.BundleContextgetBundleContext()Returns theBundleContextof the bundle which contains this component.ComponentInstancegetComponentInstance()Returns the Component Instance object for the component instance associated with this Component Context.java.util.DictionarygetProperties()Returns the component properties for this Component Context.org.osgi.framework.ServiceReferencegetServiceReference()If the component instance is registered as a service using theserviceelement, then this method returns the service reference of the service provided by this component instance.org.osgi.framework.BundlegetUsingBundle()If the component instance is registered as a service using theservicefactory="true"attribute, then this method returns the bundle using the service provided by the component instance.java.lang.ObjectlocateService(java.lang.String name)Returns the service object for the specified reference name.java.lang.ObjectlocateService(java.lang.String name, org.osgi.framework.ServiceReference reference)Returns the service object for the specified reference name andServiceReference.java.lang.Object[]locateServices(java.lang.String name)Returns the service objects for the specified reference name.
-
-
-
Method Detail
-
getProperties
java.util.Dictionary getProperties()
Returns the component properties for this Component Context.- Returns:
- The properties for this Component Context. The Dictionary is read only and cannot be modified.
-
locateService
java.lang.Object locateService(java.lang.String name)
Returns the service object for the specified reference name.If the cardinality of the reference is
0..nor1..nand multiple services are bound to the reference, the service with the highest ranking (as specified in itsConstants.SERVICE_RANKINGproperty) is returned. If there is a tie in ranking, the service with the lowest service ID (as specified in itsConstants.SERVICE_IDproperty); that is, the service that was registered first is returned.- Parameters:
name- The name of a reference as specified in areferenceelement in this component's description.- Returns:
- A service object for the referenced service or
nullif the reference cardinality is0..1or0..nand no bound service is available. - Throws:
ComponentException- If the Service Component Runtime catches an exception while activating the bound service.
-
locateService
java.lang.Object locateService(java.lang.String name, org.osgi.framework.ServiceReference reference)Returns the service object for the specified reference name andServiceReference.- Parameters:
name- The name of a reference as specified in areferenceelement in this component's description.reference- TheServiceReferenceto a bound service. This must be aServiceReferenceprovided to the component via the bind or unbind method for the specified reference name.- Returns:
- A service object for the referenced service or
nullif the specifiedServiceReferenceis not a bound service for the specified reference name. - Throws:
ComponentException- If the Service Component Runtime catches an exception while activating the bound service.
-
locateServices
java.lang.Object[] locateServices(java.lang.String name)
Returns the service objects for the specified reference name.- Parameters:
name- The name of a reference as specified in areferenceelement in this component's description.- Returns:
- An array of service objects for the referenced service or
nullif the reference cardinality is0..1or0..nand no bound service is available. If the reference cardinality is0..1or1..1and a bound service is available, the array will have exactly one element. - Throws:
ComponentException- If the Service Component Runtime catches an exception while activating a bound service.
-
getBundleContext
org.osgi.framework.BundleContext getBundleContext()
Returns theBundleContextof the bundle which contains this component.- Returns:
- The
BundleContextof the bundle containing this component.
-
getUsingBundle
org.osgi.framework.Bundle getUsingBundle()
If the component instance is registered as a service using theservicefactory="true"attribute, then this method returns the bundle using the service provided by the component instance.This method will return
nullif:- The component instance is not a service, then no bundle can be using it as a service.
- The component instance is a service but did not specify the
servicefactory="true"attribute, then all bundles using the service provided by the component instance will share the same component instance. - The service provided by the component instance is not currently being used by any bundle.
- Returns:
- The bundle using the component instance as a service or
null.
-
getComponentInstance
ComponentInstance getComponentInstance()
Returns the Component Instance object for the component instance associated with this Component Context.- Returns:
- The Component Instance object for the component instance.
-
enableComponent
void enableComponent(java.lang.String name)
Enables the specified component name. The specified component name must be in the same bundle as this component.- Parameters:
name- The name of a component ornullto indicate all components in the bundle.
-
disableComponent
void disableComponent(java.lang.String name)
Disables the specified component name. The specified component name must be in the same bundle as this component.- Parameters:
name- The name of a component.
-
getServiceReference
org.osgi.framework.ServiceReference getServiceReference()
If the component instance is registered as a service using theserviceelement, then this method returns the service reference of the service provided by this component instance.This method will return
nullif the component instance is not registered as a service.- Returns:
- The
ServiceReferenceobject for the component instance ornullif the component instance is not registered as a service.
-
-