View Javadoc

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