From eb349b848556f0d8537755d5d869366479364d45 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Wed, 16 Feb 2022 18:15:34 +0100 Subject: [PATCH] JAL-3878 Create web service class - container for service metadata and actions --- src/jalview/ws2/api/WebService.java | 173 +++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/jalview/ws2/api/WebService.java diff --git a/src/jalview/ws2/api/WebService.java b/src/jalview/ws2/api/WebService.java new file mode 100644 index 0000000..39aef4a --- /dev/null +++ b/src/jalview/ws2/api/WebService.java @@ -0,0 +1,173 @@ +package jalview.ws2.api; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import jalview.ws.params.ParamDatastoreI; +import jalview.ws2.actions.Action; + +import static java.util.Objects.requireNonNull; + +public class WebService +{ + public static class Builder + { + private URL url; + + private String clientName; + + private String category; + + private String name; + + private String description = ""; + + private ParamDatastoreI paramDatastore; + + private List actions = new ArrayList<>(); + + private Class actionClass; + + public Builder url(URL val) + { + url = val; + return this; + } + + public Builder clientName(String val) + { + clientName = val; + return this; + } + + public Builder category(String val) + { + category = val; + return this; + } + + public Builder name(String val) + { + name = val; + return this; + } + + public Builder description(String val) + { + description = val; + return this; + } + + public Builder paramDatastore(ParamDatastoreI val) + { + paramDatastore = val; + return this; + } + + public Builder actions(List val) + { + actions = val; + return this; + } + + public Builder action(T val) + { + actions.add(val); + return this; + } + + public Builder actionClass(Class val) + { + actionClass = val; + return this; + } + + public WebService build() + { + requireNonNull(url); + requireNonNull(clientName); + requireNonNull(category); + requireNonNull(name); + requireNonNull(paramDatastore); + requireNonNull(actions); + if (actions.size() == 0) + throw new IllegalArgumentException("Empty actions list"); + requireNonNull(actionClass); + return new WebService(this); + } + } + + private final URL url; + + private final String clientName; + + private final String category; + + private final String name; + + private final String description; + + private final ParamDatastoreI paramDatastore; + + private final List actions; + + private final Class actionClass; + + WebService(Builder builder) + { + this.url = builder.url; + this.clientName = builder.clientName; + this.category = builder.category; + this.name = builder.name; + this.description = builder.description; + this.paramDatastore = builder.paramDatastore; + this.actions = Collections.unmodifiableList(builder.actions); + this.actionClass = builder.actionClass; + } + + public static Builder newBuilder() + { + return new Builder(); + } + + URL getUrl() + { + return url; + } + + String getClientName() + { + return clientName; + } + + String getCategory() + { + return category; + } + + String getName() + { + return name; + } + + String getDescription() + { + return description; + } + + ParamDatastoreI getParamDatastore() + { + return paramDatastore; + } + + List getActions() + { + return actions; + } + + Class getActionClass() + { + return actionClass; + } +} -- 1.7.10.2