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 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  {
17      public static final String DESCRIPTOR_TEXT = "Support for this module is not currently installed.";
18      private final ModuleDescriptorFactory underlying;
19  
20      public UnavailableModuleDescriptorRequiringRestartFallbackFactory(ModuleDescriptorFactory underlying)
21      {
22          this.underlying = underlying;
23      }
24  
25      private boolean requiresRestart(String type)
26      {
27          if (underlying.hasModuleDescriptor(type))
28          {
29              return (underlying.getModuleDescriptorClass(type).getAnnotation(RequiresRestart.class) != null);
30          }
31          else
32          {
33              return false;
34          }
35      }
36  
37      public UnrecognisedModuleDescriptorRequiringRestart getModuleDescriptor(String type) throws PluginParseException, IllegalAccessException,
38              InstantiationException, ClassNotFoundException
39      {
40          if (hasModuleDescriptor(type))
41          {
42              final UnrecognisedModuleDescriptorRequiringRestart descriptor = new UnrecognisedModuleDescriptorRequiringRestart();
43              descriptor.setErrorText(DESCRIPTOR_TEXT);
44              return descriptor;
45          }
46          else
47          {
48              return null;
49          }
50      }
51  
52      public Class<? extends ModuleDescriptor<?>> getModuleDescriptorClass(String type)
53      {
54          if (hasModuleDescriptor(type))
55          {
56              return UnrecognisedModuleDescriptorRequiringRestart.class;
57          }
58          else
59          {
60              return null;
61          }
62      }
63  
64      public boolean hasModuleDescriptor(String type)
65      {
66          return requiresRestart(type);
67      }
68  }