Search in sources :

Example 1 with Command

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;
}
Also used : Command(dmg.util.command.Command) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Callable(java.util.concurrent.Callable)

Aggregations

Command (dmg.util.command.Command)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1