Java Reference
In-Depth Information
int or Integer —Receives the reason why the component is being deactivated,
where the value is one of the following reasons:
0—Unspecified.
1—The component was disabled.
2—A reference became unsatisfied.
3—A configuration was changed.
4—A configuration was deleted.
5—The component was disposed.
6—The bundle was stopped.
Of these arguments, you know little yet about ComponentContext . What is its purpose?
USING THE COMPONENTCONTEXT
The Declarative Services framework creates a unique ComponentContext object for
each component it activates. This object plays a role for components similar to the
role the BundleContext object plays for bundles—it provides access to execution envi-
ronment facilities. The ComponentContext interface is as follows:
public interface ComponentContext {
public Dictionary getProperties();
public Object locateService(String name);
public Object locateService(String name, ServiceReference reference);
public Object[] locateServices(String name);
public BundleContext getBundleContext();
public Bundle getUsingBundle();
public ComponentInstance getComponentInstance();
public void enableComponent(String name);
public void disableComponent(String name);
public ServiceReference getServiceReference();
}
The getProperties() method allows a component to access its configuration proper-
ties. The methods for locating services provide an alternative approach to service
injection for using services; this alternative strategy is discussed in the “Lookup strat-
egy” sidebar. The getBundleContext() method provides access to the containing bun-
dle's BundleContext object. The getUsingBundle() method is related to component
factories, which we'll discuss later.
The getComponentInstance() , enableComponent() , and disableComponent()
methods provide a component with a way to programmatically control the compo-
nent lifecycle; we'll discuss them further in the next section. Finally, the getService-
Reference() method allows a component to access the ServiceReference of this
component if it provides a service.
In the general case, whether or not a component is satisfied is dictated by whether
or not its service dependencies are satisfied. But this isn't the only type of dependency
considered by Declarative Services; another situation is where a component is depen-
dent on its configuration properties.
Search WWH ::




Custom Search