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      private final PluginEventManager pluginEventManager;
18  
19      public SpringOsgiEventBridge(PluginEventManager pluginEventManager) {
20          this.pluginEventManager = pluginEventManager;
21      }
22  
23      public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent evt) {
24          if (evt instanceof OsgiBundleContextFailedEvent) {
25              OsgiBundleContextFailedEvent e = (OsgiBundleContextFailedEvent) evt;
26              pluginEventManager.broadcast(new PluginContainerFailedEvent(
27                      e.getApplicationContext(),
28                      PluginBundleUtils.getPluginKey(e.getBundle()),
29                      e.getFailureCause()));
30          } else if (evt instanceof OsgiBundleContextRefreshedEvent) {
31              OsgiBundleContextRefreshedEvent e = (OsgiBundleContextRefreshedEvent) evt;
32              pluginEventManager.broadcast(new PluginContainerRefreshedEvent(
33                      e.getApplicationContext(),
34                      PluginBundleUtils.getPluginKey(e.getBundle())));
35          }
36      }
37  }