View Javadoc
1   package com.atlassian.plugin.osgi.module;
2   
3   import com.atlassian.plugin.ModuleDescriptor;
4   import com.atlassian.plugin.module.ContainerManagedPlugin;
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      public <T> T createModule(String name, ModuleDescriptor<T> moduleDescriptor) {
15          if (moduleDescriptor.getPlugin() instanceof ContainerManagedPlugin) {
16              ContainerManagedPlugin containerManagedPlugin = (ContainerManagedPlugin) moduleDescriptor.getPlugin();
17              return containerManagedPlugin.getContainerAccessor().getBean(name);
18          } else {
19              throw new IllegalArgumentException("Failed to resolve '" + name + "'. You cannot use 'bean' prefix with non spring plugins");
20          }
21      }
22  
23      public String getPrefix() {
24          return "bean";
25      }
26  }