1 /* 2 * Replica is published under the terms 3 * of the Apache Software License. 4 */ 5 package replica.core; 6 7 import java.util.logging.Level; 8 import java.util.logging.Logger; 9 10 import replica.command.Command; 11 import replica.command.CommandException; 12 import replica.command.beans.BeansCommandProcessor; 13 14 /*** 15 * This processor extends the beans processor to provide suport for 16 * ApplicationMessages as command argument. 17 * 18 * @author Pedro Costa 19 * @author Helder Silva 20 * @since 21/Jan/2004 21 */ 22 public class ApplicationCommandProcessor extends BeansCommandProcessor { 23 24 static Logger logger = Logger.getLogger(ApplicationCommandProcessor.class.getName()); 25 26 /*** 27 * 28 */ 29 public ApplicationCommandProcessor() { 30 super(); 31 } 32 33 /*** 34 * This default implementation assumes that command is a string and that the first word is the action Id. 35 * 36 * It passes the all command instruction, including the action Id, to the mapped command on execute. 37 * 38 * @return Object the result of the command execution. 39 * @see replica.server.cmd.CommandProcessor#process(java.lang.String) 40 * @throws CommandException if there is a problem executing the command. 41 * Callers can choose to catch or not. 42 */ 43 public Object process(Object command){ 44 45 if( command instanceof ApplicationMessage ) 46 return process((ApplicationMessage) command); 47 48 return super.process(command); 49 } 50 51 protected Object process(ApplicationMessage appMsg){ 52 53 try{ 54 Command c = getCommand( appMsg.getBody()); 55 56 if( c == null) 57 throw new CommandException("Command not found."); 58 59 return executeCommand( c, appMsg); 60 } 61 catch(Throwable e){ 62 logger.log(Level.WARNING, e.getMessage(), e); 63 return "Error executing [" + appMsg.getBody().toString() + "] : " + e.getMessage(); 64 } 65 } 66 67 /*** 68 * Default beahavior,simple call the execute method on command. 69 * 70 * @param command 71 * @param appMsg 72 * @return 73 */ 74 protected Object executeCommand( Command command, ApplicationMessage appMsg ){ 75 76 return command.execute( appMsg); 77 } 78 79 }

This page was automatically generated by Maven