View Javadoc
1   package com.atlassian.plugin.osgi.factory;
2   
3   import com.atlassian.plugin.ModuleDescriptor;
4   import com.atlassian.plugin.ModuleDescriptorFactory;
5   import com.atlassian.plugin.PluginParseException;
6   import com.atlassian.plugin.descriptors.RequiresRestart;
7   import com.atlassian.plugin.descriptors.UnrecognisedModuleDescriptorRequiringRestart;
8   
9   /**
10   * Return placeholder {@link com.atlassian.plugin.descriptors.UnrecognisedModuleDescriptor} instances marked with @RequiresRestart
11   * for any descriptors in the underlying {@link ModuleDescriptorFactory} that have that annotation. This
12   * is for module descriptors that won't be used yet but where we need to report the RequresRestart status
13   * back.
14   */
15  public class UnavailableModuleDescriptorRequiringRestartFallbackFactory implements ModuleDescriptorFactory {
16      public static final String DESCRIPTOR_TEXT = "Support for this module is not currently installed.";
17      private final ModuleDescriptorFactory underlying;
18  
19      public UnavailableModuleDescriptorRequiringRestartFallbackFactory(ModuleDescriptorFactory underlying) {
20          this.underlying = underlying;
21      }
22  
23      private boolean requiresRestart(String type) {
24          if (underlying.hasModuleDescriptor(type)) {
25              return (underlying.getModuleDescriptorClass(type).getAnnotation(RequiresRestart.class) != null);
26          } else {
27              return false;
28          }
29      }
30  
31      public UnrecognisedModuleDescriptorRequiringRestart getModuleDescriptor(String type) throws PluginParseException {
32          if (hasModuleDescriptor(type)) {
33              final UnrecognisedModuleDescriptorRequiringRestart descriptor = new UnrecognisedModuleDescriptorRequiringRestart();
34              descriptor.setErrorText(DESCRIPTOR_TEXT);
35              return descriptor;
36          } else {
37              return null;
38          }
39      }
40  
41      public Class<? extends ModuleDescriptor<?>> getModuleDescriptorClass(String type) {
42          if (hasModuleDescriptor(type)) {
43              return UnrecognisedModuleDescriptorRequiringRestart.class;
44          } else {
45              return null;
46          }
47      }
48  
49      public boolean hasModuleDescriptor(String type) {
50          return requiresRestart(type);
51      }
52  }