View Javadoc

1   package com.atlassian.plugin.osgi.bridge;
2   
3   import com.atlassian.plugin.Plugin;
4   import com.atlassian.plugin.PluginAccessor;
5   import com.atlassian.plugin.osgi.bridge.external.PluginRetrievalService;
6   import org.osgi.framework.Bundle;
7   import org.osgi.framework.ServiceFactory;
8   import org.osgi.framework.ServiceRegistration;
9   
10  /**
11   * Provides instances of {@link com.atlassian.plugin.osgi.bridge.external.PluginRetrievalService}, tailed for the consumer.
12   *
13   * @since 2.6.0
14   */
15  public class PluginRetrievalServiceFactory implements ServiceFactory
16  {
17      private final PluginAccessor pluginAccessor;
18  
19      public PluginRetrievalServiceFactory(PluginAccessor pluginAccessor)
20      {
21          this.pluginAccessor = pluginAccessor;
22      }
23  
24      public Object getService(Bundle bundle, ServiceRegistration serviceRegistration)
25      {
26          return new PluginRetrievalServiceImpl(pluginAccessor, bundle);
27      }
28  
29      public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object o)
30      {
31      }
32  
33      private static class PluginRetrievalServiceImpl implements PluginRetrievalService
34      {
35          private final Plugin plugin;
36  
37          public PluginRetrievalServiceImpl(PluginAccessor pluginAccessor, Bundle bundle)
38          {
39              String pluginKey = PluginBundleUtils.getPluginKey(bundle);
40              plugin = pluginAccessor.getPlugin(pluginKey);
41          }
42  
43          public Plugin getPlugin()
44          {
45              return plugin;
46          }
47      }
48  }