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 autohit.common.AutohitErrorCodes;
24 import autohit.server.ServerException;
25
26 /**
27 * The SET command. This will set and invoker property.
28 * It expects a name value pair, seperated by a '='. Everything
29 * to the right of the equals sign to the end of the string will be put in the
30 * property.
31 * <p>
32 * <code>
33 * COMMAND LIST
34 * this.assert(false,false,false,false,true,false)
35 * 0-UNI - OPTIONAL
36 * 1-RESPONSE - OPTIONAL
37 * 2-TARGET - UNUSED
38 * 3-CLASS - UNUSED
39 * 4-COMMAND - REQUIRED - The name/value specification (name=value text)
40 * 5-OBJECT - UNUSED
41 * </code>
42 *
43 * @author Erich P. Gatejen
44 * @version 1.0
45 * <i>Version History</i>
46 * <code>EPG - Initial - 30Jul03</code>
47 *
48 */
49 public class CommandSet extends Command {
50
51 final static long serialVersionUID = 1;
52
53 /**
54 * My name
55 */
56 public final static String MY_NAME = "set";
57
58 /**
59 * Execute the command.
60 * @throws ServerException
61 * @return return the manreadable message for success.
62 */
63 public String execute() throws ServerException {
64
65 String victory = "failed.";
66
67 try {
68
69 String name;
70 String value;
71
72 int pivot = command.indexOf('=');
73 if (pivot < 1) {
74 throw new ServerException(
75 "Malformed name/value pair.",
76 AutohitErrorCodes.CODE_COMMAND_ERROR);
77 }
78
79 name = command.substring(0, pivot).trim();
80 value = command.substring(pivot + 1);
81
82 // Add to invoker properties
83 sc.getInvokerProperties().put(name, value);
84
85 // Report it
86 victory = "completed. Property " + name + " added (or replaced).";
87
88 } catch (IndexOutOfBoundsException ie) {
89 throw new ServerException(
90 "Malformed name/value pair.",
91 AutohitErrorCodes.CODE_COMMAND_ERROR);
92 } catch (Exception eee) {
93 throw new ServerException(
94 "Failed to general exception. message=" + eee.getMessage(),
95 AutohitErrorCodes.CODE_COMMAND_FAULT);
96 }
97
98 // return the receipt
99 return victory;
100 }
101
102 /**
103 * Verify the Compile command.
104 * @throws ServerException
105 * @return return the manreadable message for accepting the command.
106 */
107 public String verify() throws ServerException {
108 this.assertparam(false, false, false, false, true, false);
109 return "parameters are good.";
110 }
111
112 /**
113 * Get the textual name for the command.
114 * @return return the manreadable name of this command.
115 */
116 public String getName() {
117 return MY_NAME;
118 }
119 }
|