Package net.sourceforge.javautil.ui.command

Source Code of net.sourceforge.javautil.ui.command.UICommandSetClass

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()) );
    }
  }
 
}
TOP

Related Classes of net.sourceforge.javautil.ui.command.UICommandSetClass

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.