
website.automate.waml.io.model.main.action.ActionRegistry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of waml-io Show documentation
Show all versions of waml-io Show documentation
(De)Serializer of the web automation markup language (WAML) for Java
The newest version!
package website.automate.waml.io.model.main.action;
import website.automate.waml.io.deserializer.UnknownActionException;
import website.automate.waml.io.model.main.criteria.ExportCriteria;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static java.text.MessageFormat.format;
import static java.util.Arrays.asList;
public class ActionRegistry {
private static Map> ACTION_NAME_CLASS_MAP = new HashMap<>();
private static Map, String> ACTION_CLASS_NAME_MAP = new HashMap<>();
private static Collection> EXPLICIT_ACTIONS =
asList(ClickAction.class, EnterAction.class, MoveAction.class, OpenAction.class,
SelectAction.class, WaitAction.class, EnsureAction.class);
static {
register(AlertAction.TYPE_NAME, AlertAction.class);
register(ClickAction.TYPE_NAME, ClickAction.class);
register(DefineAction.TYPE_NAME, DefineAction.class);
register(EnsureAction.TYPE_NAME, EnsureAction.class);
register(EnterAction.TYPE_NAME, EnterAction.class);
register(IncludeAction.TYPE_NAME, IncludeAction.class);
register(MoveAction.TYPE_NAME, MoveAction.class);
register(OpenAction.TYPE_NAME, OpenAction.class);
register(SelectAction.TYPE_NAME, SelectAction.class);
register(WaitAction.TYPE_NAME, WaitAction.class);
register(DebugAction.TYPE_NAME, DebugAction.class);
register(ExecuteAction.TYPE_NAME, ExecuteAction.class);
register(UriAction.TYPE_NAME, UriAction.class);
register(ExportAction.TYPE_NAME, ExportAction.class);
}
private static void register(String name, Class extends Action> clazz) {
ACTION_NAME_CLASS_MAP.put(name, clazz);
ACTION_CLASS_NAME_MAP.put(clazz, name);
}
public static boolean isExplicit(Class extends Action> clazz) {
return EXPLICIT_ACTIONS.contains(clazz);
}
public static String findNameByClazz(Class extends Action> clazz) {
return ACTION_CLASS_NAME_MAP.get(clazz);
}
public static Class extends Action> findClazzByNames(final Collection names) {
Optional matchingTypeName = ACTION_NAME_CLASS_MAP.keySet().stream()
.filter(typeName -> names.contains(typeName)).findFirst();
if (matchingTypeName.isPresent()) {
return ACTION_NAME_CLASS_MAP.get(matchingTypeName.get());
}
throw new UnknownActionException(
format("Could not identify any action using keys: {0}.", names));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy