View Javadoc

1   package com.atlassian.plugin.osgi.module;
2   
3   import com.atlassian.plugin.module.ContainerManagedPlugin;
4   import com.atlassian.plugin.ModuleDescriptor;
5   import com.atlassian.plugin.module.PrefixModuleFactory;
6   import com.atlassian.plugin.osgi.spring.SpringContainerAccessor;
7   
8   /**
9    * The SpringBeanModuleFactory creates a java bean for the given module class by resolving the name to spring bean reference.
10   * It returns a reference to this bean.
11   * 
12   * @since 2.5.0
13   */
14  public class BeanPrefixModuleFactory implements PrefixModuleFactory
15  {
16      public <T> T createModule(String name, ModuleDescriptor<T> moduleDescriptor)
17      {
18          if (moduleDescriptor.getPlugin() instanceof ContainerManagedPlugin)
19          {
20              ContainerManagedPlugin containerManagedPlugin = (ContainerManagedPlugin) moduleDescriptor.getPlugin();
21              return (T) ((SpringContainerAccessor) containerManagedPlugin.getContainerAccessor()).getBean(name);
22          }
23          else
24          {
25              throw new IllegalArgumentException("Failed to resolve '" + name + "'. You cannot use 'bean' prefix with non-OSGi plugins");
26          }
27      }
28  
29      public String getPrefix()
30      {
31          return "bean";
32      }
33  }