4a101fd474f6362bc25dc5ce6eb3bbe2710a2081
[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.Collection;
6 import java.util.List;
7 import jalview.ws.params.ParamDatastoreI;
8 import jalview.ws2.actions.api.ActionI;
9
10 import static java.util.Objects.requireNonNull;
11
12 public class WebService<A extends ActionI<?>>
13 {
14   public static class Builder<A extends ActionI<?>>
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 Class<A> actionClass;
31
32     public Builder<A> url(URL val)
33     {
34       url = val;
35       return this;
36     }
37
38     public Builder<A> clientName(String val)
39     {
40       clientName = val;
41       return this;
42     }
43
44     public Builder<A> category(String val)
45     {
46       category = val;
47       return this;
48     }
49
50     public Builder<A> name(String val)
51     {
52       name = val;
53       return this;
54     }
55
56     public Builder<A> description(String val)
57     {
58       description = val;
59       return this;
60     }
61
62     public Builder<A> interactive(boolean val)
63     {
64       interactive = val;
65       return this;
66     }
67
68     public Builder<A> paramDatastore(ParamDatastoreI val)
69     {
70       paramDatastore = val;
71       return this;
72     }
73
74     public Builder<A> actionClass(Class<A> val)
75     {
76       actionClass = val;
77       return this;
78     }
79
80     public WebService<A> build()
81     {
82       return new WebService<A>(this);
83     }
84   }
85
86   private final URL url;
87
88   private final String clientName;
89
90   private final String category;
91
92   private final String name;
93
94   private final String description;
95
96   private final boolean interactive;
97
98   private final ParamDatastoreI paramDatastore;
99
100   private final List<A> actions;
101
102   private final Class<A> actionClass;
103
104   protected WebService(Builder<A> builder)
105   {
106     requireNonNull(builder.url);
107     requireNonNull(builder.clientName);
108     requireNonNull(builder.category);
109     requireNonNull(builder.name);
110     requireNonNull(builder.paramDatastore);
111     requireNonNull(builder.actionClass);
112     this.url = builder.url;
113     this.clientName = builder.clientName;
114     this.category = builder.category;
115     this.name = builder.name;
116     this.description = builder.description;
117     this.interactive = builder.interactive;
118     this.paramDatastore = builder.paramDatastore;
119     this.actions = new ArrayList<>();
120     this.actionClass = builder.actionClass;
121   }
122
123   public static <A extends ActionI<?>> Builder<A> newBuilder()
124   {
125     return new Builder<A>();
126   }
127
128   public void addAction(A action)
129   {
130     this.actions.add(action);
131   }
132
133   public void addActions(Collection<? extends A> actions)
134   {
135     this.actions.addAll(actions);
136   }
137
138   public URL getUrl()
139   {
140     return url;
141   }
142
143   public String getClientName()
144   {
145     return clientName;
146   }
147
148   public String getCategory()
149   {
150     return category;
151   }
152
153   public String getName()
154   {
155     return name;
156   }
157
158   public String getDescription()
159   {
160     return description;
161   }
162
163   public boolean isInteractive()
164   {
165     return interactive;
166   }
167
168   public ParamDatastoreI getParamDatastore()
169   {
170     return paramDatastore;
171   }
172
173   public List<A> getActions()
174   {
175     return actions;
176   }
177
178   public Class<A> getActionClass()
179   {
180     return actionClass;
181   }
182 }