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.command;
22
23 import java.io.InputStream;
24
25 import autohit.common.AutohitErrorCodes;
26 import autohit.server.ServerException;
27 import autohit.vm.VM;
28 import autohit.vm.VMProcess;
29
30 /**
31 * The RUN command. It expects a single string that points
32 * to the universe object to run.
33 * <p>
34 * <code>
35 * COMMAND LIST
36 * this.assert(false,false,false,true,true,false)
37 * 0-UNI - OPTIONAL
38 * 1-RESPONSE - OPTIONAL
39 * 2-TARGET - OPTIONAL
40 * 3-CLASS - REQUIRED - VM implementation (ie. autohit.vm.SimVM)
41 * 4-COMMAND - REQUIRED - Name of object in universe to run
42 * 5-OBJECT - UNUSED
43 * </code>
44 *
45 * @author Erich P. Gatejen
46 * @version 1.0
47 * <i>Version History</i>
48 * <code>EPG - Initial - 24Jul03<
49 *
50 */
51 public class CommandRun extends Command {
52
53 final static long serialVersionUID = 1;
54
55 /**
56 * My name
57 */
58 public final static String MY_NAME = "run";
59
60 /**
61 * Execute the command.
62 * @throws ServerException
63 * @return return the manreadable message for success.
64 */
65 public String execute() throws ServerException {
66
67 InputStream is;
68 VM myVM;
69 String victory = "failed.";
70
71 try {
72
73 // Get the VM instance
74 Class t = Class.forName(classobject);
75 myVM = (VM) t.newInstance();
76 myVM.init(target, command);
77
78 // build the process and unleash
79 VMProcess pcb = (sc.getKernel()).get();
80 pcb.execute(myVM);
81
82 victory =
83 " 'run' dispatched. Program is starting under pid="
84 + pcb.getPID();
85
86 } catch (ClassNotFoundException e) {
87 throw new ServerException(
88 " failed because it could not load the class for the vm. VM specified ="
89 + classobject,
90 AutohitErrorCodes.CODE_COMMAND_FAULT);
91
92 } catch (Exception e) {
93 throw new ServerException(
94 " failed. There was a general Exception. message="
95 + e.getMessage(),
96 AutohitErrorCodes.CODE_COMMAND_FAULT);
97 }
98
99 // return
100 return victory;
101 }
102
103 /**
104 * Verify the Compile command.
105 * @throws ServerException
106 * @return return the manreadable message for accepting the command.
107 */
108 public String verify() throws ServerException {
109 this.assertparam(false, false, false, true, true, false);
110 return "parameters are good.";
111 }
112
113 /**
114 * Get the textual name for the command.
115 * @return return the manreadable name of this command.
116 */
117 public String getName() {
118 return MY_NAME;
119 }
120 }
|