1 /* 2 * Replica is published under the terms 3 * of the Apache Software License. 4 */ 5 package replica.command.xml; 6 7 import java.io.InputStream; 8 9 import javax.xml.parsers.DocumentBuilderFactory; 10 11 import replica.command.*; 12 13 /*** 14 * The XML Command Processor gets its configuration from a xml file. 15 * 16 * @author Pedro Costa 17 * @author Helder Silva 18 * @since 17/Jan/2004 19 */ 20 public class XmlCommandProcessor extends AbstractCommandProcessor { 21 22 private String configurationFileFullPath; 23 24 /*** 25 * 26 */ 27 public XmlCommandProcessor() { 28 super(); 29 } 30 31 /* (non-Javadoc) 32 * @see replica.command.AbstractCommandProcessor#readMappings() 33 */ 34 protected Mappings readMappings() { 35 return readMappings( getConfigurationFileFullPath() ); 36 } 37 38 /*** 39 * Reads mappings from the given xml config file name. 40 * 41 * @param configFilePath 42 * @return 43 */ 44 protected Mappings readMappings( String configFilePath ){ 45 return readMappings( getClass().getClassLoader().getResourceAsStream(configFilePath) ); 46 } 47 48 /*** 49 * Read mappings from the given input stream. 50 * 51 * @param input 52 */ 53 protected Mappings readMappings(InputStream input){ 54 55 try{ 56 return new XmlHashtableMappings( 57 DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input) ); 58 } 59 catch(Throwable t){ 60 throw new CommandException("Error on configuration of the Commands Processor from XML source. Look for the root cause of this exeception.", t); 61 } 62 } 63 64 /*** 65 * @return 66 */ 67 public String getConfigurationFileFullPath() { 68 return configurationFileFullPath; 69 } 70 71 /*** 72 * @param string 73 */ 74 public void setConfigurationFileFullPath(String string) { 75 configurationFileFullPath = string; 76 } 77 78 /*** 79 * This default implementation assumes that command is a string and that the first word is the action Id. 80 * 81 * It passes the all command instruction, including the action Id, to the mapped command on execute. 82 * 83 * @return Object the result of the command execution. 84 * @see replica.server.cmd.CommandProcessor#process(java.lang.String) 85 * @throws CommandException if there is a problem executing the command. 86 * Callers can choose to catch or not. 87 */ 88 public Object process(Object command) { 89 90 return getCommand( command ).execute( command ); 91 } 92 }

This page was automatically generated by Maven