|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
XmlCommandProcessor.java | - | 0% | 0% | 0% |
|
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 | 0 |
public XmlCommandProcessor() {
|
28 | 0 |
super();
|
29 |
} |
|
30 |
|
|
31 |
/* (non-Javadoc)
|
|
32 |
* @see replica.command.AbstractCommandProcessor#readMappings()
|
|
33 |
*/
|
|
34 | 0 |
protected Mappings readMappings() {
|
35 | 0 |
return readMappings( getConfigurationFileFullPath() );
|
36 |
} |
|
37 |
|
|
38 |
/**
|
|
39 |
* Reads mappings from the given xml config file name.
|
|
40 |
*
|
|
41 |
* @param configFilePath
|
|
42 |
* @return
|
|
43 |
*/
|
|
44 | 0 |
protected Mappings readMappings( String configFilePath ){
|
45 | 0 |
return readMappings( getClass().getClassLoader().getResourceAsStream(configFilePath) );
|
46 |
} |
|
47 |
|
|
48 |
/**
|
|
49 |
* Read mappings from the given input stream.
|
|
50 |
*
|
|
51 |
* @param input
|
|
52 |
*/
|
|
53 | 0 |
protected Mappings readMappings(InputStream input){
|
54 |
|
|
55 | 0 |
try{
|
56 | 0 |
return new XmlHashtableMappings( |
57 |
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input) ); |
|
58 |
} |
|
59 |
catch(Throwable t){
|
|
60 | 0 |
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 | 0 |
public String getConfigurationFileFullPath() {
|
68 | 0 |
return configurationFileFullPath;
|
69 |
} |
|
70 |
|
|
71 |
/**
|
|
72 |
* @param string
|
|
73 |
*/
|
|
74 | 0 |
public void setConfigurationFileFullPath(String string) { |
75 | 0 |
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 | 0 |
public Object process(Object command) {
|
89 |
|
|
90 | 0 |
return getCommand( command ).execute( command );
|
91 |
} |
|
92 |
} |
|
93 |
|
|