1 /**
2 * AUTOHIT 2003
3 * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Additional license information can be found in the documentation.
19 * @author Erich P Gatejen
20 */
21 package autohit.server.invoker;
22
23 import autohit.server.BasicBootstrap;
24 import autohit.server.command.CommandAtom;
25 import autohit.server.command.CommandServerLocal;
26
27 /**
28 * A single command invoker.
29 *
30 * @author Erich P. Gatejen
31 * @version 1.0 <i>Version History</i><code>EPG - Initial - 19Jul03
32 */
33 public class SingleCommandLine extends BasicBootstrap {
34
35 /**
36 * Command system */
37 public SimTextCommand cmd;
38 public CommandServerLocal cserver;
39
40 /**
41 * Default constructor. */
42 public SingleCommandLine() throws Exception {
43 throw new Exception("Dont use the default constructor!");
44 }
45
46 /**
47 * Properties constructor. Give it a full path to the properties file. */
48 public SingleCommandLine(String rootProps) throws Exception {
49
50 // CRITICAL TO CALL SUPER
51 super(rootProps);
52
53 // command muncher
54 cmd = new SimTextCommand();
55 cmd.init(sc);
56
57 // command server
58 cserver = new CommandServerLocal();
59 cserver.init(sc);
60 }
61
62 /**
63 * main interface */
64 public static void usage() {
65 System.out.println("Single Command Line for Autohit (2003):");
66 System.out.println("This will issue a command to the SimTextCommand processor. The arguments");
67 System.out.println("include the SimTextCommand and it's arguments packed as a single String.");
68 System.out.println(" SingleCommandLine [prop file] [argument string]");
69 System.out.println(" the classpath must be set properly. (See documentation)");
70 System.out.println(" [prop file] configuration property file, such as");
71 System.out.println(" etc/default.prop");
72 System.out.println(" [argument string] command parameters as a single string.");
73 System.out.println(" If invoking this from a script, be sure to");
74 System.out.println(" collect the parameters into a single string using");
75 System.out.println(" quotes.");
76 System.out.println("If running this from a platform helper script, such as");
77 System.out.println("/bin/command.bat, the usage may be different. See the");
78 System.out.println("Autohit User guide.");
79 }
80
81 /**
82 * logic */
83 public void go(String commandString) {
84
85 try {
86 CommandAtom a = cmd.create(commandString);
87 cserver.execute(a);
88 } catch (Exception ee) {
89 System.out.println("COMMAND FAILED due to exception. message=" + ee.getMessage());
90 ee.printStackTrace();
91 }
92 }
93
94 /**
95 * main interface */
96 public static void main(String[] args) {
97
98 // handle arguments
99 if (args.length == 0) {
100 System.out.println("No .prop specified");
101 usage();
102 return;
103 }
104
105 // handle arguments
106 if (args.length == 1) {
107 System.out.println("No argument string given");
108 usage();
109 return;
110 }
111
112 try {
113 SingleCommandLine me = new SingleCommandLine(args[0]);
114 me.go(args[1]);
115 } catch (Exception e) {
116 e.printStackTrace();
117 }
118 }
119
120 }
|