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, IllegalAccessException,
32              InstantiationException, ClassNotFoundException {
33          if (hasModuleDescriptor(type)) {
34              final UnrecognisedModuleDescriptorRequiringRestart descriptor = new UnrecognisedModuleDescriptorRequiringRestart();
35              descriptor.setErrorText(DESCRIPTOR_TEXT);
36              return descriptor;
37          } else {
38              return null;
39          }
40      }
41  
42      public Class<? extends ModuleDescriptor<?>> getModuleDescriptorClass(String type) {
43          if (hasModuleDescriptor(type)) {
44              return UnrecognisedModuleDescriptorRequiringRestart.class;
45          } else {
46              return null;
47          }
48      }
49  
50      public boolean hasModuleDescriptor(String type) {
51          return requiresRestart(type);
52      }
53  }