1 /* 2 * Replica is published under the terms 3 * of the Apache Software License. 4 */ 5 package replica.command; 6 7 import java.util.StringTokenizer; 8 9 /*** 10 * Generic implementation of a CommandProcessor. 11 * 12 * @author Pedro Costa 13 * @author Helder Silva 14 * @since 17/Jan/2004 15 */ 16 public abstract class AbstractCommandProcessor implements CommandProcessor { 17 18 private Mappings mappings; 19 20 /*** 21 * 22 */ 23 public AbstractCommandProcessor() { 24 super(); 25 } 26 27 /*** 28 * This default implementation assumes that command is a string and that the first word is the action Id. 29 * 30 * It passes the all command instruction, including the action Id, to the mapped command on execute. 31 * 32 * @return Object the result of the command execution. 33 * @see replica.server.cmd.CommandProcessor#process(java.lang.String) 34 * @throws CommandException if there is a problem executing the command. 35 * Callers can choose to catch or not. 36 */ 37 public Object process(Object command){ 38 39 return getCommand( command ).execute( command ); 40 } 41 42 protected Command getCommand(Object command){ 43 StringTokenizer tokenizer = new StringTokenizer(command.toString()); 44 45 return getMappings().getNewCommand( tokenizer.nextToken().trim() ); 46 } 47 48 /*** 49 * You must call this method to initialize this class mappings. 50 * 51 */ 52 public void configure(){ 53 54 setMappings( readMappings() ); 55 } 56 57 /*** 58 * Reads a new configuration mapping. 59 * 60 * Extended classes can read this configuration from diferent type of sources: xml files, properties files, 61 * databases, JNDI, or others. 62 * 63 * @return a new mapping configuration. 64 */ 65 protected abstract Mappings readMappings(); 66 67 /*** 68 * @return 69 */ 70 protected Mappings getMappings() { 71 return mappings; 72 } 73 74 /*** 75 * @param mappings 76 */ 77 protected void setMappings(Mappings mappings) { 78 this.mappings = mappings; 79 } 80 81 }

This page was automatically generated by Maven