Tutorial:Get Services CyActivator

From OpenTutorials
Jump to: navigation, search

The CyActivator

Each bundle app must have a class extending AbstractCyActivator that is used as the execution entry point. Usually we name this class "CyActivator" to distinguish it from other classes, although any name can be used.

Here is an example of a CyActivator:

public class CyActivator extends AbstractCyActivator {
         public CyActivator() {
            super();
         }

         public void start(BundleContext bc) {
            CySwingApplication cytoscapeDesktopService = getService(bc,CySwingApplication.class);
            AddImageIconAction addImageIconAction = new AddImageIconAction(cytoscapeDesktopService);
            registerService(bc,addImageIconAction,CyAction.class, new Properties());
         }
}

In the bundle app, app developer does not use the CyAppAdaptor service - instead, they get services only as needed. In the above example, the service CySwingApplication is retrieved and passed to the AddImageIconAction class. Then AddImageIconAction is registered as an OSGi service - adding it to the Cytoscape menu hierarchy in the process.

Using the CyAppAdapter service in a bundle app

CyAppAdapter is primarily designed for use in simple apps due to their lack of a CyActivator. However, sInce CyAppAdapter is a core service, it is available for bundle apps to use as well. This can be done by retrieving it in the CyActivator like any other service:

CyAppAdapter adapter = getService(bc,CyAppAdapter.class);

or for CySwingAppAdapter:

CySwingAppAdapter swingAdapter = getService(bc,CySwingAppAdapter.class);