View Javadoc

1   package com.atlassian.plugin.osgi.bridge;
2   
3   import com.atlassian.plugin.event.PluginEventManager;
4   import com.atlassian.plugin.event.events.PluginContainerFailedEvent;
5   import com.atlassian.plugin.event.events.PluginContainerRefreshedEvent;
6   import org.eclipse.gemini.blueprint.context.event.OsgiBundleApplicationContextEvent;
7   import org.eclipse.gemini.blueprint.context.event.OsgiBundleApplicationContextListener;
8   import org.eclipse.gemini.blueprint.context.event.OsgiBundleContextFailedEvent;
9   import org.eclipse.gemini.blueprint.context.event.OsgiBundleContextRefreshedEvent;
10  
11  /**
12   * Bridges key Spring DM extender events with the plugin system
13   *
14   * @since 2.2.0
15   */
16  public class SpringOsgiEventBridge implements OsgiBundleApplicationContextListener
17  {
18      private final PluginEventManager pluginEventManager;
19  
20      public SpringOsgiEventBridge(PluginEventManager pluginEventManager)
21      {
22          this.pluginEventManager = pluginEventManager;
23      }
24  
25      public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent evt)
26      {
27          if (evt instanceof OsgiBundleContextFailedEvent)
28          {
29              OsgiBundleContextFailedEvent e = (OsgiBundleContextFailedEvent)evt;
30              pluginEventManager.broadcast(new PluginContainerFailedEvent(
31                      e.getApplicationContext(),
32                      PluginBundleUtils.getPluginKey(e.getBundle()),
33                      e.getFailureCause()));
34          }
35          else if (evt instanceof OsgiBundleContextRefreshedEvent)
36          {
37              OsgiBundleContextRefreshedEvent e = (OsgiBundleContextRefreshedEvent)evt;
38              pluginEventManager.broadcast(new PluginContainerRefreshedEvent(
39                      e.getApplicationContext(),
40                      PluginBundleUtils.getPluginKey(e.getBundle())));
41          }
42      }
43  }