View Javadoc
1   package org.codehaus.plexus.components.secdispatcher;
2   
3   import java.util.Collection;
4   import java.util.List;
5   import java.util.Optional;
6   
7   import static java.util.Objects.requireNonNull;
8   
9   /**
10   * Meta description of dispatcher.
11   */
12  public interface DispatcherMeta {
13      final class Field {
14          private final String key;
15          private final boolean optional;
16          private final String defaultValue;
17          private final String description;
18          private final List<Field> options;
19  
20          private Field(String key, boolean optional, String defaultValue, String description, List<Field> options) {
21              this.key = requireNonNull(key);
22              this.optional = optional;
23              this.defaultValue = defaultValue;
24              this.description = requireNonNull(description);
25              this.options = options;
26          }
27  
28          /**
29           * The key to be used in configuration map for field.
30           */
31          public String getKey() {
32              return key;
33          }
34  
35          /**
36           * Is configuration optional?
37           */
38          public boolean isOptional() {
39              return optional;
40          }
41  
42          /**
43           * Optional default value of the configuration.
44           */
45          public Optional<String> getDefaultValue() {
46              return Optional.ofNullable(defaultValue);
47          }
48  
49          /**
50           * The human description of the configuration.
51           */
52          public String getDescription() {
53              return description;
54          }
55  
56          /**
57           * Optional list of options, if this configuration accepts limited values. Each option is represented
58           * as field, where {@link #getKey()} represents the value to be used, and {@link #displayName()} represents
59           * the description of option. The {@link #getDefaultValue()}, if present represents the value to be used
60           * instead of {@link #getKey()}.
61           */
62          public Optional<List<Field>> getOptions() {
63              return Optional.ofNullable(options);
64          }
65  
66          public static Builder builder(String key) {
67              return new Builder(key);
68          }
69  
70          public static final class Builder {
71              private final String key;
72              private boolean optional;
73              private String defaultValue;
74              private String description;
75              private List<Field> options;
76  
77              private Builder(String key) {
78                  this.key = requireNonNull(key);
79              }
80  
81              public Builder optional(boolean optional) {
82                  this.optional = optional;
83                  return this;
84              }
85  
86              public Builder defaultValue(String defaultValue) {
87                  this.defaultValue = defaultValue;
88                  return this;
89              }
90  
91              public Builder description(String description) {
92                  this.description = requireNonNull(description);
93                  return this;
94              }
95  
96              public Builder options(List<Field> options) {
97                  this.options = requireNonNull(options);
98                  return this;
99              }
100 
101             public Field build() {
102                 return new Field(key, optional, defaultValue, description, options);
103             }
104         }
105     }
106 
107     /**
108      * Option to hide this instance from users, like for migration or legacy purposes.
109      */
110     default boolean isHidden() {
111         return false;
112     }
113 
114     /**
115      * The name of the dispatcher.
116      */
117     String name();
118 
119     /**
120      * Returns the display (human) name of the dispatcher.
121      */
122     String displayName();
123 
124     /**
125      * Returns the configuration fields of the dispatcher.
126      */
127     Collection<Field> fields();
128 }