View Javadoc

1   package com.atlassian.plugin.module;
2   
3   import com.atlassian.plugin.ModuleDescriptor;
4   import com.atlassian.plugin.PluginParseException;
5   import com.atlassian.plugin.hostcontainer.HostContainer;
6   
7   import static com.google.common.base.Preconditions.checkNotNull;
8   
9   /**
10   * Legacy module factory that uses the {@link ContainerManagedPlugin} to create beans
11   *
12   * @since 2.5.0
13   */
14  public class HostContainerLegacyAdaptor extends LegacyModuleFactory
15  {
16  
17      private final HostContainer hostContainer;
18  
19      public HostContainerLegacyAdaptor(HostContainer hostContainer)
20      {
21          this.hostContainer = checkNotNull(hostContainer);
22      }
23  
24      public <T> T createModule(String name, ModuleDescriptor<T> moduleDescriptor) throws PluginParseException {
25  
26          // Give the plugin a go first
27          if (moduleDescriptor.getPlugin() instanceof ContainerManagedPlugin)
28          {
29              return ((ContainerManagedPlugin) moduleDescriptor.getPlugin()).getContainerAccessor().createBean(moduleDescriptor.getModuleClass());
30          }
31          else
32          {
33              return hostContainer.create(moduleDescriptor.getModuleClass());
34          }
35      }
36  
37  }