package net.sourceforge.javautil.ui.command;
import net.sourceforge.javautil.common.ReflectionUtil;
import net.sourceforge.javautil.common.reflection.cache.ClassDescriptor;
import net.sourceforge.javautil.common.reflection.cache.ClassMethod;
import net.sourceforge.javautil.ui.command.annotation.Command;
/**
* This will create a command set out of a particular class whose methods
* can be marked as {@link Command}'s that will be executed.
*
* @author elponderador
* @author $Author: ponderator $
* @version $Id: UICommandSetClass.java 912 2009-09-09 20:43:46Z ponderator $
*/
public class UICommandSetClass<CMD extends UICommand, CTX extends UICommandContext> extends UICommandSetAbstract<CMD, CTX> {
protected final Object instance;
public UICommandSetClass (ClassDescriptor descriptor) {
this.instance = descriptor.newInstance();
ClassMethod[] methods = descriptor.getMethods(Command.class);
for (ClassMethod method : methods) {
Command command = method.getAnnotation(Command.class);
String name = "".equals(command.name()) ? method.getName().toLowerCase() : command.name();
this.add( (CMD) new UICommandMethod(this, instance, method, name, command.value()) );
}
}
}