View Javadoc

1   package com.atlassian.plugin;
2   
3   import com.atlassian.fugue.Option;
4   import com.google.common.base.Objects;
5   
6   import static com.atlassian.fugue.Option.some;
7   import static com.google.common.base.Preconditions.checkNotNull;
8   
9   /**
10   * <p>Represents a plugin permission as parsed from the plugin descriptor.
11   * <p>A plugin permission here is:
12   * <ul>
13   * <li>A <strong>name</strong> which denotes the permission itself.</li>
14   * <li>An <strong>{@link InstallationMode installation mode}</strong> which tells whether the permission is required
15   * for a given type of installation of the plugin. No installation mode defined means that the permission is always
16   * required.</li>
17   * </ul>
18   *
19   * @since 3.0
20   */
21  public final class PluginPermission
22  {
23      public final static PluginPermission ALL = new PluginPermission(Permissions.ALL_PERMISSIONS);
24      public final static PluginPermission EXECUTE_JAVA = new PluginPermission(Permissions.EXECUTE_JAVA);
25  
26      private final String name;
27      private final Option<InstallationMode> installationMode;
28  
29      public PluginPermission(String name)
30      {
31          this(checkNotNull(name), Option.<InstallationMode>none());
32      }
33  
34      public PluginPermission(String name, InstallationMode installationMode)
35      {
36          this(checkNotNull(name), some(checkNotNull(installationMode)));
37      }
38  
39      public PluginPermission(String name, Option<InstallationMode> installationMode)
40      {
41          this.name = checkNotNull(name);
42          this.installationMode = checkNotNull(installationMode);
43      }
44  
45      public String getName()
46      {
47          return name;
48      }
49  
50      /**
51       * The installation mode for that permission.
52       *
53       * @return the installation mode as an {@link Option}. If the option is {@link Option#none()}
54       *         then this means this permission is always valid, however when it is {@link Option#defined() defined}
55       *         it will only be valid for the given installation mode.
56       */
57      public Option<InstallationMode> getInstallationMode()
58      {
59          return installationMode;
60      }
61  
62      @Override
63      public boolean equals(Object o)
64      {
65          if (this == o)
66          {
67              return true;
68          }
69  
70          if (o == null || getClass() != o.getClass())
71          {
72              return false;
73          }
74  
75          final PluginPermission that = (PluginPermission) o;
76          return Objects.equal(this.name, that.name);
77      }
78  
79      @Override
80      public int hashCode()
81      {
82          return Objects.hashCode(this.name);
83      }
84  }