Interface ComponentContext
A component instance may obtain its Component Context object through its activate, modified, and deactivate methods.
- "ThreadSafe"
-
Method Summary
Modifier and TypeMethodDescriptionvoid
disableComponent
(String name) Disables the specified component name.void
enableComponent
(String name) Enables the specified component name.Returns theBundleContext
of the bundle which declares this component.<S> ComponentInstance<S>
Returns the Component Instance object for the component instance associated with this Component Context.Returns the component properties for this Component Context.If the component instance is registered as a service using theservice
element, then this method returns the service reference of the service provided by this component instance.If the component instance is registered as a service using theservicescope="bundle"
orservicescope="prototype"
attribute, then this method returns the bundle using the service provided by the component instance.<S> S
locateService
(String name) Returns the service object for the specified reference name.<S> S
locateService
(String name, ServiceReference<S> reference) Returns the service object for the specified reference name andServiceReference
.Object[]
locateServices
(String name) Returns the service objects for the specified reference name.
-
Method Details
-
getProperties
Dictionary<String,Object> 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
Returns the service object for the specified reference name.If the cardinality of the reference is
0..n
or1..n
and multiple services are bound to the reference, the service whoseServiceReference
is first in the ranking order is returned. SeeServiceReference.compareTo(Object)
.- Parameters:
name
- The name of a reference as specified in areference
element in this component's description.- Returns:
- A service object for the referenced service or
null
if the reference cardinality is0..1
or0..n
and no bound service is available. - Throws:
ComponentException
- If Service Component Runtime catches an exception while activating the bound service.
-
locateService
Returns the service object for the specified reference name andServiceReference
.- Type Parameters:
S
- Type of Service.- Parameters:
name
- The name of a reference as specified in areference
element in this component's description.reference
- TheServiceReference
to a bound service. This must be aServiceReference
provided to the component via the bind or unbind method for the specified reference name.- Returns:
- A service object for the referenced service or
null
if the specifiedServiceReference
is not a bound service for the specified reference name. - Throws:
ComponentException
- If Service Component Runtime catches an exception while activating the bound service.
-
locateServices
Returns the service objects for the specified reference name.- Parameters:
name
- The name of a reference as specified in areference
element in this component's description.- Returns:
- An array of service objects for the referenced service or
null
if the reference cardinality is0..1
or0..n
and no bound service is available. If the reference cardinality is0..1
or1..1
and a bound service is available, the array will have exactly one element. There is no guarantee that the service objects in the array will be in any specific order. - Throws:
ComponentException
- If Service Component Runtime catches an exception while activating a bound service.
-
getBundleContext
BundleContext getBundleContext()Returns theBundleContext
of the bundle which declares this component.- Returns:
- The
BundleContext
of the bundle declares this component.
-
getUsingBundle
Bundle getUsingBundle()If the component instance is registered as a service using theservicescope="bundle"
orservicescope="prototype"
attribute, then this method returns the bundle using the service provided by the component instance.This method will return
null
if:- 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
servicescope="bundle"
orservicescope="prototype"
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
Returns the Component Instance object for the component instance associated with this Component Context.- Returns:
- The Component Instance object for the component instance.
-
enableComponent
Enables the specified component name. The specified component name must be in the same bundle as this component.This method must return after changing the enabled state of the specified component name. Any actions that result from this, such as activating or deactivating a component configuration, must occur asynchronously to this method call.
- Parameters:
name
- The name of a component ornull
to indicate all components in the bundle.
-
disableComponent
Disables the specified component name. The specified component name must be in the same bundle as this component.This method must return after changing the enabled state of the specified component name. Any actions that result from this, such as activating or deactivating a component configuration, must occur asynchronously to this method call.
- Parameters:
name
- The name of a component.
-
getServiceReference
ServiceReference<?> getServiceReference()If the component instance is registered as a service using theservice
element, then this method returns the service reference of the service provided by this component instance.This method will return
null
if the component instance is not registered as a service.- Returns:
- The
ServiceReference
object for the component instance ornull
if the component instance is not registered as a service.
-