
website.automate.jwebrobot.executor.action.ActionExecutorFactory Maven / Gradle / Ivy
package website.automate.jwebrobot.executor.action;
import website.automate.jwebrobot.exceptions.ActionExecutorMissingException;
import website.automate.waml.io.model.action.Action;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class ActionExecutorFactory {
private final Map, ActionExecutor extends Action>> executorRegistry = new HashMap<>();
private final Set> executors;
@Inject
public ActionExecutorFactory(Set> executors) {
this.executors = executors;
init();
}
private void init() {
for (ActionExecutor extends Action> executor : executors) {
executorRegistry.put(executor.getSupportedType(), executor);
}
}
@SuppressWarnings("unchecked")
public ActionExecutor getInstance(Class extends Action> actionClazz) {
ActionExecutor extends Action> actionExecutor = executorRegistry.get(actionClazz);
if (actionExecutor == null) {
throw new ActionExecutorMissingException(actionClazz);
}
return (ActionExecutor)actionExecutor;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy