1   package com.atlassian.plugins.rest.module;
2   
3   import com.atlassian.plugin.ModuleDescriptor;
4   import com.atlassian.plugin.PluginParseException;
5   import com.atlassian.plugin.hostcontainer.HostContainer;
6   import com.atlassian.plugin.osgi.external.SingleModuleDescriptorFactory;
7   import com.atlassian.plugins.rest.module.servlet.RestServletModuleManager;
8   import com.google.common.base.Preconditions;
9   
10  /**
11   * Module descriptor factory for REST module descriptors.
12   */
13  public class RestModuleDescriptorFactory extends SingleModuleDescriptorFactory<RestModuleDescriptor>
14  {
15      private final RestServletModuleManager servletModuleManager;
16  
17      private final HostContainer hostContainer;
18      private final String restContextPath;
19  
20      public RestModuleDescriptorFactory(HostContainer hostContainer, RestServletModuleManager servletModuleManager, String restContextPath)
21      {
22          super(Preconditions.checkNotNull(hostContainer), "rest", RestModuleDescriptor.class);
23          this.hostContainer = hostContainer;
24          this.servletModuleManager = Preconditions.checkNotNull(servletModuleManager);
25          this.restContextPath = Preconditions.checkNotNull(restContextPath);
26      }
27  
28      @Override
29      public ModuleDescriptor getModuleDescriptor(String type) throws PluginParseException, IllegalAccessException, InstantiationException, ClassNotFoundException
30      {
31          return hasModuleDescriptor(type) ? new RestModuleDescriptor(hostContainer, servletModuleManager, restContextPath) : null;
32      }
33  }