View Javadoc

1   package com.atlassian.plugin.osgi.bridge;
2   
3   import com.atlassian.plugin.event.PluginEventManager;
4   import org.osgi.framework.BundleActivator;
5   import org.osgi.framework.BundleContext;
6   import org.osgi.framework.ServiceReference;
7   import org.springframework.osgi.context.event.OsgiBundleApplicationContextListener;
8   
9   import java.util.Dictionary;
10  import java.util.Hashtable;
11  
12  /**
13   * Registers services for bridging Spring events with the plugin event system
14   *
15   * @since 2.2.0
16   */
17  public class BridgeActivator implements BundleActivator
18  {
19      public void start(BundleContext bundleContext) throws Exception
20      {
21          // We can do this because the plugin event manager is a host component
22          ServiceReference ref = bundleContext.getServiceReference(PluginEventManager.class.getName());
23          if (ref == null)
24          {
25              throw new IllegalStateException("The PluginEventManager service must be exported from the application");
26          }
27          PluginEventManager pluginEventManager = (PluginEventManager) bundleContext.getService(ref);
28  
29          // Register the listener for context refreshed and failed events
30          bundleContext.registerService(
31                  OsgiBundleApplicationContextListener.class.getName(),
32                  new SpringOsgiEventBridge(pluginEventManager),
33                  null);
34  
35          // Register the listener for internal application context events like waiting for dependencies
36          Dictionary<String, String> dict = new Hashtable<String, String>();
37          dict.put("plugin-bridge", "true");
38          bundleContext.registerService(
39                  OsgiBundleApplicationContextListener.class.getName(),
40                  new SpringContextEventBridge(pluginEventManager),
41                  dict);
42      }
43  
44      public void stop(BundleContext bundleContext) throws Exception
45      {
46      }
47  }