JAL-3878 Add interactive flag to WebService class
[jalview.git] / src / jalview / ws2 / api / WebService.java
1 package jalview.ws2.api;
2
3 import java.net.URL;
4 import java.util.ArrayList;
5 import java.util.Collections;
6 import java.util.List;
7 import jalview.ws.params.ParamDatastoreI;
8 import jalview.ws2.actions.Action;
9
10 import static java.util.Objects.requireNonNull;
11
12 public class WebService<T extends Action>
13 {
14   public static class Builder<T extends Action>
15   {
16     private URL url;
17
18     private String clientName;
19
20     private String category;
21
22     private String name;
23
24     private String description = "";
25
26     private boolean interactive = false;
27
28     private ParamDatastoreI paramDatastore;
29
30     private List<T> actions = new ArrayList<>();
31
32     private Class<T> actionClass;
33
34     public Builder<T> url(URL val)
35     {
36       url = val;
37       return this;
38     }
39
40     public Builder<T> clientName(String val)
41     {
42       clientName = val;
43       return this;
44     }
45
46     public Builder<T> category(String val)
47     {
48       category = val;
49       return this;
50     }
51
52     public Builder<T> name(String val)
53     {
54       name = val;
55       return this;
56     }
57
58     public Builder<T> description(String val)
59     {
60       description = val;
61       return this;
62     }
63
64     public Builder<T> interactive(boolean val)
65     {
66       interactive = val;
67       return this;
68     }
69
70     public Builder<T> paramDatastore(ParamDatastoreI val)
71     {
72       paramDatastore = val;
73       return this;
74     }
75
76     public Builder<T> actions(List<T> val)
77     {
78       actions = val;
79       return this;
80     }
81
82     public Builder<T> action(T val)
83     {
84       actions.add(val);
85       return this;
86     }
87
88     public Builder<T> actionClass(Class<T> val)
89     {
90       actionClass = val;
91       return this;
92     }
93
94     public WebService<T> build()
95     {
96       requireNonNull(url);
97       requireNonNull(clientName);
98       requireNonNull(category);
99       requireNonNull(name);
100       requireNonNull(paramDatastore);
101       requireNonNull(actions);
102       if (actions.size() == 0)
103         throw new IllegalArgumentException("Empty actions list");
104       requireNonNull(actionClass);
105       return new WebService<T>(this);
106     }
107   }
108
109   private final URL url;
110
111   private final String clientName;
112
113   private final String category;
114
115   private final String name;
116
117   private final String description;
118
119   private final boolean interactive;
120
121   private final ParamDatastoreI paramDatastore;
122
123   private final List<T> actions;
124
125   private final Class<T> actionClass;
126
127   WebService(Builder<T> builder)
128   {
129     this.url = builder.url;
130     this.clientName = builder.clientName;
131     this.category = builder.category;
132     this.name = builder.name;
133     this.description = builder.description;
134     this.interactive = builder.interactive;
135     this.paramDatastore = builder.paramDatastore;
136     this.actions = Collections.unmodifiableList(builder.actions);
137     this.actionClass = builder.actionClass;
138   }
139   
140   public static <T extends Action> Builder<T> newBuilder()
141   {
142     return new Builder<T>();
143   }
144
145   URL getUrl()
146   {
147     return url;
148   }
149
150   String getClientName()
151   {
152     return clientName;
153   }
154
155   String getCategory()
156   {
157     return category;
158   }
159
160   String getName()
161   {
162     return name;
163   }
164
165   String getDescription()
166   {
167     return description;
168   }
169
170   boolean isInteractive()
171   {
172     return interactive;
173   }
174
175   ParamDatastoreI getParamDatastore()
176   {
177     return paramDatastore;
178   }
179
180   List<T> getActions()
181   {
182     return actions;
183   }
184
185   Class<T> getActionClass()
186   {
187     return actionClass;
188   }
189 }