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.util.Enumeration;
24 import java.util.Hashtable;
25
26 import autohit.common.AutohitErrorCodes;
27 import autohit.server.ServerException;
28
29 /**
30 * The PROPS command. It will dump the invoker propertiess list. It will be in
31 * the form of cmdid|name|value.
32 * <p>
33 * <code>
34 * COMMAND LIST
35 * this.assert(false,false,false,false,true,false)
36 * 0-UNI - OPTIONAL
37 * 1-RESPONSE - OPTIONAL
38 * 2-TARGET - OPTIONAL
39 * 3-CLASS - UNUSED
40 * 4-COMMAND - UNUSED
41 * 5-OBJECT - UNUSED
42 * </code>
43 *
44 * @author Erich P. Gatejen
45 * @version 1.0 <i>Version History</i><code>EPG - Initial - 27Jul03<
46 */
47 public class CommandProps extends Command {
48
49 final static long serialVersionUID = 1;
50
51 /**
52 * My name */
53 public final static String MY_NAME = "props";
54 public final static String LIST_HEADER = "INVOKER PROP LIST" + RESPONSE_ELEMENT_SEPERATOR;
55
56 /**
57 * Execute the command.
58 *
59 * @throws ServerException
60 * @return return the manreadable message for success.
61 */
62 public String execute() throws ServerException {
63
64 String victory = "failed.";
65 boolean started = false;
66
67 // Trap all non-critical errors and just log them to the
68 // responseChannel
69 try {
70
71 // Get the properties list and chug through it
72 // Send FINAL_RESULTS on the last item or if the list is empty;
73 Hashtable iprops = sc.getInvokerProperties();
74 if (iprops.isEmpty()) {
75 sendTarget(
76 LIST_HEADER
77 + uniqueID
78 + RESPONSE_ELEMENT_SEPERATOR
79 + "X"
80 + RESPONSE_ELEMENT_SEPERATOR
81 + "No properties are set.",
82 AutohitErrorCodes.EVENT_COMMAND_FINAL_RESULTS,
83 null);
84
85 } else {
86
87 String key;
88 String value;
89 Enumeration listi = iprops.keys();
90 StringBuffer text;
91 while (listi.hasMoreElements()) {
92
93 // build entry
94 key = (String) listi.nextElement();
95 value = (String) iprops.get(key);
96 text = new StringBuffer(LIST_HEADER);
97 text.append(key);
98 text.append(RESPONSE_ELEMENT_SEPERATOR);
99 text.append(value);
100
101 // is it the last one?
102 if (listi.hasMoreElements()) {
103 sendTarget(text.toString(), AutohitErrorCodes.EVENT_COMMAND_PARTIAL_RESULTS, null);
104 } else {
105 sendTarget(text.toString(), AutohitErrorCodes.EVENT_COMMAND_FINAL_RESULTS, null);
106 }
107
108 started = true;
109
110 } // end while
111
112 } // end if empty
113
114 // Ok, it's working
115 victory = "dispatched.";
116
117 } catch (Exception e) {
118
119 if (started == true) {
120 // We got some results out. Send a message to the target
121 try {
122 sendTarget(
123 LIST_HEADER + uniqueID + RESPONSE_ELEMENT_SEPERATOR + "ABORTED! Exception while listing.",
124 AutohitErrorCodes.EVENT_COMMAND_FAULTED,
125 null);
126
127 } catch (Exception eee) {
128 // no point. it WILL happen again
129 }
130 }
131 throw new ServerException(
132 "failed. There was a general Exception. message=" + e.getMessage(),
133 AutohitErrorCodes.EVENT_COMMAND_FAILED);
134 }
135
136 // return
137 return victory;
138 }
139
140 /**
141 * Verify the Compile command.
142 *
143 * @throws ServerException
144 * @return return the manreadable message for accepting the command.
145 */
146 public String verify() throws ServerException {
147 this.assertparam(false, false, false, false, false, false);
148 return "parameters are good.";
149 }
150
151 /**
152 * Get the textual name for the command.
153 *
154 * @return return the manreadable name of this command.
155 */
156 public String getName() {
157 return MY_NAME;
158 }
159 }
|