Merge branch 'JAL-3878_ws-overhaul-3' into mmw/Release_2_12_ws_merge
[jalview.git] / 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 (file)
index 0000000..4a101fd
--- /dev/null
@@ -0,0 +1,182 @@
+package jalview.ws2.api;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws2.actions.api.ActionI;
+
+import static java.util.Objects.requireNonNull;
+
+public class WebService<A extends ActionI<?>>
+{
+  public static class Builder<A extends ActionI<?>>
+  {
+    private URL url;
+
+    private String clientName;
+
+    private String category;
+
+    private String name;
+
+    private String description = "";
+
+    private boolean interactive = false;
+
+    private ParamDatastoreI paramDatastore;
+
+    private Class<A> actionClass;
+
+    public Builder<A> url(URL val)
+    {
+      url = val;
+      return this;
+    }
+
+    public Builder<A> clientName(String val)
+    {
+      clientName = val;
+      return this;
+    }
+
+    public Builder<A> category(String val)
+    {
+      category = val;
+      return this;
+    }
+
+    public Builder<A> name(String val)
+    {
+      name = val;
+      return this;
+    }
+
+    public Builder<A> description(String val)
+    {
+      description = val;
+      return this;
+    }
+
+    public Builder<A> interactive(boolean val)
+    {
+      interactive = val;
+      return this;
+    }
+
+    public Builder<A> paramDatastore(ParamDatastoreI val)
+    {
+      paramDatastore = val;
+      return this;
+    }
+
+    public Builder<A> actionClass(Class<A> val)
+    {
+      actionClass = val;
+      return this;
+    }
+
+    public WebService<A> build()
+    {
+      return new WebService<A>(this);
+    }
+  }
+
+  private final URL url;
+
+  private final String clientName;
+
+  private final String category;
+
+  private final String name;
+
+  private final String description;
+
+  private final boolean interactive;
+
+  private final ParamDatastoreI paramDatastore;
+
+  private final List<A> actions;
+
+  private final Class<A> actionClass;
+
+  protected WebService(Builder<A> builder)
+  {
+    requireNonNull(builder.url);
+    requireNonNull(builder.clientName);
+    requireNonNull(builder.category);
+    requireNonNull(builder.name);
+    requireNonNull(builder.paramDatastore);
+    requireNonNull(builder.actionClass);
+    this.url = builder.url;
+    this.clientName = builder.clientName;
+    this.category = builder.category;
+    this.name = builder.name;
+    this.description = builder.description;
+    this.interactive = builder.interactive;
+    this.paramDatastore = builder.paramDatastore;
+    this.actions = new ArrayList<>();
+    this.actionClass = builder.actionClass;
+  }
+
+  public static <A extends ActionI<?>> Builder<A> newBuilder()
+  {
+    return new Builder<A>();
+  }
+
+  public void addAction(A action)
+  {
+    this.actions.add(action);
+  }
+
+  public void addActions(Collection<? extends A> actions)
+  {
+    this.actions.addAll(actions);
+  }
+
+  public URL getUrl()
+  {
+    return url;
+  }
+
+  public String getClientName()
+  {
+    return clientName;
+  }
+
+  public String getCategory()
+  {
+    return category;
+  }
+
+  public String getName()
+  {
+    return name;
+  }
+
+  public String getDescription()
+  {
+    return description;
+  }
+
+  public boolean isInteractive()
+  {
+    return interactive;
+  }
+
+  public ParamDatastoreI getParamDatastore()
+  {
+    return paramDatastore;
+  }
+
+  public List<A> getActions()
+  {
+    return actions;
+  }
+
+  public Class<A> getActionClass()
+  {
+    return actionClass;
+  }
+}