2020-03-03 16:38:50 +01:00
|
|
|
package eu.dnetlib.dhp.selectioncriteria;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
2020-04-21 18:00:53 +02:00
|
|
|
import org.reflections.Reflections;
|
2020-03-03 16:38:50 +01:00
|
|
|
|
|
|
|
public class VerbResolver implements Serializable {
|
|
|
|
private final Map<String, Class<Selection>> map;
|
|
|
|
|
2020-04-21 18:00:53 +02:00
|
|
|
public VerbResolver() {
|
2020-03-03 16:38:50 +01:00
|
|
|
|
2020-04-21 18:00:53 +02:00
|
|
|
this.map =
|
|
|
|
new Reflections("eu.dnetlib")
|
|
|
|
.getTypesAnnotatedWith(VerbClass.class).stream()
|
|
|
|
.collect(
|
|
|
|
Collectors.toMap(
|
|
|
|
v -> v.getAnnotation(VerbClass.class).value(),
|
|
|
|
v -> (Class<Selection>) v));
|
|
|
|
}
|
2020-03-03 16:38:50 +01:00
|
|
|
|
2020-04-21 18:00:53 +02:00
|
|
|
public Selection getSelectionCriteria(String name, String param)
|
|
|
|
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
|
|
|
|
InstantiationException {
|
2020-03-03 16:38:50 +01:00
|
|
|
|
|
|
|
return map.get(name).getDeclaredConstructor((String.class)).newInstance(param);
|
|
|
|
}
|
2020-04-21 18:00:53 +02:00
|
|
|
}
|