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