package jalview.ws2.actions;
import java.util.EnumSet;
+import java.util.Objects;
import jalview.ws2.actions.api.ActionI;
import jalview.ws2.api.CredentialType;
+import jalview.ws2.api.WebService;
/**
* An abstract base class storing common data and implementing their getters
* {@code isActive} implementations.
*
* @author mmwarowny
- *
- * @param <T>
+ * @param <R>
* task result type
*/
-public abstract class BaseAction<T> implements ActionI<T>
+public abstract class BaseAction<R> implements ActionI<R>
{
- public static class Builder
+ public static abstract class Builder<A extends BaseAction<?>>
{
+ protected WebService<A> webService;
+
protected String name;
protected String tooltip = "";
this.name = name;
}
+ public void webService(WebService<A> val)
+ {
+ this.webService = val;
+ }
+
public void tooltip(String val)
{
tooltip = val;
}
}
+ protected final WebService<? extends ActionI<R>> webService;
+
protected final String name;
protected final String tooltip;
protected final EnumSet<CredentialType> requiredCredentials;
- protected BaseAction(Builder builder)
+ protected BaseAction(Builder<? extends BaseAction<R>> builder)
{
+ Objects.requireNonNull(builder.webService);
+ this.webService = builder.webService;
this.name = builder.name;
this.tooltip = builder.tooltip;
this.subcategory = builder.subcategory;
this.requiredCredentials = builder.requiredCredentials;
}
- public static Builder newBuilder(String name)
+ @Override
+ public WebService<? extends ActionI<R>> getWebService()
{
- return new Builder(name);
+ return webService;
}
@Override
import jalview.ws.params.ArgumentI;
import jalview.ws2.api.CredentialType;
import jalview.ws2.api.Credentials;
+import jalview.ws2.api.WebService;
/**
* {@code Action} object represents an executable action that the web service
*
* @author mmwarowny
*
- * @param <T>
+ * @param <R>
* task result type
*/
-public interface ActionI<T>
+public interface ActionI<R>
{
/**
+ * Get the web service containing this action.
+ *
+ * @return containing web service
+ */
+ WebService<? extends ActionI<R>> getWebService();
+
+ /**
* Get the name of the action. Typically, it should be the same as the name of
* the service.
*
* event handler attached to the new task
* @return new running task
*/
- TaskI<T> perform(AlignmentViewport viewport, List<ArgumentI> args,
- Credentials credentials, TaskEventListener<T> handler);
+ TaskI<R> perform(AlignmentViewport viewport, List<ArgumentI> args,
+ Credentials credentials, TaskEventListener<R> handler);
/**
* Return if the action is currently active for the given viewport. Active
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collections;
+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<T extends ActionI>
+public class WebService<A extends ActionI<?>>
{
- public static class Builder<T extends ActionI>
+ public static class Builder<A extends ActionI<?>>
{
private URL url;
private ParamDatastoreI paramDatastore;
- private List<T> actions = new ArrayList<>();
+ private Class<A> actionClass;
- private Class<T> actionClass;
-
- public Builder<T> url(URL val)
+ public Builder<A> url(URL val)
{
url = val;
return this;
}
- public Builder<T> clientName(String val)
+ public Builder<A> clientName(String val)
{
clientName = val;
return this;
}
- public Builder<T> category(String val)
+ public Builder<A> category(String val)
{
category = val;
return this;
}
- public Builder<T> name(String val)
+ public Builder<A> name(String val)
{
name = val;
return this;
}
- public Builder<T> description(String val)
+ public Builder<A> description(String val)
{
description = val;
return this;
}
- public Builder<T> interactive(boolean val)
+ public Builder<A> interactive(boolean val)
{
interactive = val;
return this;
}
- public Builder<T> paramDatastore(ParamDatastoreI val)
+ public Builder<A> paramDatastore(ParamDatastoreI val)
{
paramDatastore = val;
return this;
}
- public Builder<T> actions(List<T> val)
- {
- actions = val;
- return this;
- }
-
- public Builder<T> action(T val)
- {
- actions.add(val);
- return this;
- }
-
- public Builder<T> actionClass(Class<T> val)
+ public Builder<A> actionClass(Class<A> val)
{
actionClass = val;
return this;
}
- public WebService<T> build()
+ public WebService<A> 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<T>(this);
+ return new WebService<A>(this);
}
}
private final ParamDatastoreI paramDatastore;
- private final List<T> actions;
+ private final List<A> actions;
- private final Class<T> actionClass;
+ private final Class<A> actionClass;
- WebService(Builder<T> builder)
+ 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.description = builder.description;
this.interactive = builder.interactive;
this.paramDatastore = builder.paramDatastore;
- this.actions = Collections.unmodifiableList(builder.actions);
+ this.actions = new ArrayList<>();
this.actionClass = builder.actionClass;
}
-
- public static <T extends ActionI> Builder<T> newBuilder()
+
+ 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)
{
- return new Builder<T>();
+ this.actions.addAll(actions);
}
public URL getUrl()
return paramDatastore;
}
- public List<T> getActions()
+ public List<A> getActions()
{
return actions;
}
- public Class<T> getActionClass()
+ public Class<A> getActionClass()
{
return actionClass;
}