View Javadoc

1   package com.atlassian.plugin.module;
2   
3   import com.atlassian.plugin.AutowireCapablePlugin;
4   import com.atlassian.plugin.ModuleDescriptor;
5   import com.atlassian.plugin.PluginParseException;
6   import com.atlassian.plugin.hostcontainer.HostContainer;
7   import org.apache.commons.lang.Validate;
8   
9   /**
10   * Legacy module factory that uses the deprecated {@link AutowireCapablePlugin} interface
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          Validate.notNull(hostContainer, "hostContainer should not be null");
22          this.hostContainer = hostContainer;
23      }
24  
25      public <T> T createModule(String name, ModuleDescriptor<T> moduleDescriptor) throws PluginParseException {
26  
27          // Give the plugin a go first
28          if (moduleDescriptor.getPlugin() instanceof AutowireCapablePlugin)
29          {
30              return ((AutowireCapablePlugin) moduleDescriptor.getPlugin()).autowire(moduleDescriptor.getModuleClass());
31          }
32          else
33          {
34              return hostContainer.create(moduleDescriptor.getModuleClass());
35          }
36      }
37  
38  }