Package zephyropen.command

Source Code of zephyropen.command.CommandDispatcher

package zephyropen.command;

import zephyropen.api.API;
import zephyropen.api.ApiFactory;
import zephyropen.command.Command;

/**
* Dispatches commands received from the server to the appropriate API for execution.
*
* @author <a href="mailto:brad.zdanivsky@gmail.com">Brad Zdanivsky</a>
*
*/
public final class CommandDispatcher {

  /** framework configuration */
  private static ApiFactory apiFactory = ApiFactory.getReference();

  /**
   * Dispatches the specified command to the appropriate API for execution.
   *
   * @param command is the command to dispatch
   */
  public static void dispatch(Command command) {
   
    /** sanity test */
    if (command == null) return;
 
    /** retrieve the specified device name */
    String deviceName = command.getType();
   
    if (deviceName == null || deviceName.equals("")){
      // System.err.println("null device name: " + deviceName);
      return;
    }
   
    /** check device name first */
    if (deviceName == null || deviceName.equals("")){
      // System.err.println("null device: " + deviceName);
      return;
    }
   
    /** look up the API */
    API api = apiFactory.create(deviceName);
   
    /** error check */
    if (api == null){
      //System.err.println("api look fails for device name: " + deviceName);
      //System.err.println("factory: " + apiFactory.toXML());
      return;
    }
   
    /** check that this is a valid command for this device */
    if (command.isMalformedCommand(api)) return;
     
    /** execute the command */
    api.execute(command);
  }
}
 
TOP

Related Classes of zephyropen.command.CommandDispatcher

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.