use of dmg.util.command.Command in project dcache by dCache.
the class AnnotatedCommandScanner method scan.
@Override
public Map<List<String>, ? extends CommandExecutor> scan(Object obj) {
Map<List<String>, AnnotatedCommandExecutor> commands = Maps.newHashMap();
Class<?> containerClass = obj.getClass();
while (containerClass != null) {
Class<?>[] classes = containerClass.getDeclaredClasses();
for (Class<?> commandClass : classes) {
Command command = commandClass.getAnnotation(Command.class);
if (command != null && !commandClass.isInterface() && Callable.class.isAssignableFrom(commandClass)) {
try {
Constructor<? extends Callable<? extends Serializable>> constructor = cast(commandClass).getDeclaredConstructor(commandClass.getDeclaringClass());
constructor.setAccessible(true);
commands.put(asList(command.name().split(" ")), new AnnotatedCommandExecutor(obj, command, constructor));
} catch (NoSuchMethodException e) {
throw new RuntimeException("This is a bug. Please notify support@dcache.org.", e);
}
}
}
containerClass = containerClass.getSuperclass();
}
return commands;
}
Aggregations