|
StatsProgram |
|
1 package com.mccrory.scott.spumoni;
2
3 ////////////////////////////////////////////////////////////////////////////////
4 // Copyright (C) 2002 Scott McCrory
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 ////////////////////////////////////////////////////////////////////////////////
20
21 import java.io.IOException;
22 import java.io.ObjectInputStream;
23 import java.io.ObjectOutputStream;
24 import java.util.StringTokenizer;
25 import java.util.Vector;
26
27 /**
28 * <P><code>StatsProgram</code> is a data object for the statistics programs
29 * handled by Spumoni through the StatsCollector class.
30 * It also contains attributes such as the program name, regexp, a list
31 * of required modules, max run time and a Vector of StatsValue objects.</P>
32 *
33 * @author <a href="mailto:smccrory@users.sourceforge.net">Scott McCrory</a>.
34 * @version CVS $Id: StatsProgram.java,v 1.8 2002/08/04 22:04:53 smccrory Exp $
35 */
36 public class StatsProgram {
37
38 /** The name of this class to log context without introspection **/
39 private static final String CLASS_NAME = "StatsProgram";
40
41 /** The version of this class (filled in by CVS) **/
42 private static final String VERSION = "CVS $Revision: 1.8 $";
43
44 /** The program's configuration filename (where we learned about it) **/
45 private String xmlFilename = "";
46
47 /** The program's command **/
48 private String program = "";
49
50 /** The program's regular expression string **/
51 private String regexp = "";
52
53 /** The program's list of required modules **/
54 private Vector requiredModules = new Vector();
55
56 /** The program's maximum run time in seconds **/
57 private int maxRunTime = 0;
58
59 /** A set of stats values that are extracted from our output **/
60 private StatsValueList statsValueList = new StatsValueList();
61
62 /**
63 * Basic StatsProgram constructor.
64 */
65 public StatsProgram() {
66 super();
67 }
68
69 /**
70 * A convenience StatsProgram contructor to set all of the data elements
71 * at the time of creation.
72 *
73 * @param newXmlFilename The program's source XML filename
74 * @param newProgram The program's command string
75 * @param newRegexp Regexp string
76 * @param newRequiredModules List of required modules
77 * @param newMaxRunTime Maximum run time
78 * @param newStatsValueList List of stats values
79 */
80 public StatsProgram(
81 String newXmlFilename,
82 String newProgram,
83 String newRegexp,
84 Vector newRequiredModules,
85 int newMaxRunTime,
86 StatsValueList newStatsValueList) {
87
88 xmlFilename = newXmlFilename;
89 program = newProgram;
90 regexp = newRegexp;
91 requiredModules = newRequiredModules;
92 maxRunTime = newMaxRunTime;
93 statsValueList = newStatsValueList;
94
95 }
96
97 /**
98 * Adds the StatsValue object to our StatsValueList
99 * @param sv com.mccrory.scott.spumoni.StatsValue
100 */
101 public void addStatsValue(StatsValue sv) {
102 statsValueList.add(sv);
103 }
104
105 /**
106 * We override the <code>clone</code> method here to prevent cloning of our class.
107 *
108 * @throws CloneNotSupportedException To indicate cloning is not allowed
109 * @return Nothing ever really returned since we throw a CloneNotSupportedException
110 **/
111 public final Object clone() throws CloneNotSupportedException {
112
113 throw new CloneNotSupportedException();
114
115 }
116
117 /**
118 * Returns the program's maximum run time in seconds.
119 * @return int
120 */
121 public int getMaxRunTime() {
122 return maxRunTime;
123 }
124
125 /**
126 * Returns the program's command string.
127 * @return java.lang.String
128 */
129 public java.lang.String getProgram() {
130 return program;
131 }
132
133 /**
134 * Returns the program's regexp string.
135 * @return java.lang.String
136 */
137 public java.lang.String getRegexp() {
138 return regexp;
139 }
140
141 /**
142 * Returns a Vector of the program's required modules.
143 * @return java.util.Vector
144 */
145 public java.util.Vector getRequiredModules() {
146 return requiredModules;
147 }
148
149 /**
150 * Returns a StatsValueList of the program's StatsValue objects.
151 * @return StatsValueList
152 */
153 public StatsValueList getStatsValueList() {
154 return statsValueList;
155 }
156
157 /**
158 * Returns a vector of all of the OIDs in this StatsProgram
159 * @return A vector of all of the OIDs in this StatsProgram
160 */
161 public Vector getOids() {
162
163 return statsValueList.getOids();
164
165 }
166
167 /**
168 * Returns the program's source XML filename.
169 * (i.e. where we learned about it).
170 * @return java.lang.String
171 */
172 public java.lang.String getXmlFilename() {
173 return xmlFilename;
174 }
175
176 /**
177 * Parses a module list and returns them as individual elements in a Vector.
178 * We assume that the comma (",") is the delimiter
179 *
180 * @param moduleList A list of modules separated by commas
181 * @return The list of modules parsed from the comma-delimited string
182 */
183 private static Vector parseModuleList(String moduleList) {
184
185 if (moduleList == null || moduleList.length() < 1) {
186 return null;
187 }
188
189 Vector tempModuleList = new Vector();
190
191 StringTokenizer st = new StringTokenizer(moduleList, ",");
192 while (st.hasMoreTokens()) {
193 tempModuleList.add(st.nextElement());
194 }
195
196 return tempModuleList;
197
198 }
199
200 /**
201 * We override the <code>readObject</code> method here to prevent
202 * deserialization of our class for security reasons.
203 *
204 * @param in java.io.ObjectInputStream
205 * @throws IOException thrown if a problem occurs
206 **/
207 private final void readObject(ObjectInputStream in) throws IOException {
208
209 throw new IOException("Object cannot be deserialized");
210
211 }
212
213 /**
214 * Sets the program's maximum run time in seconds.
215 * @param newMaxRunTime int
216 */
217 public void setMaxRunTime(int newMaxRunTime) {
218 maxRunTime = newMaxRunTime;
219 }
220
221 /**
222 * Sets the program's command string.
223 * @param newProgram java.lang.String
224 */
225 public void setProgram(java.lang.String newProgram) {
226 program = newProgram;
227 }
228
229 /**
230 * Sets the program's regular expression string.
231 * @param newRegexp java.lang.String
232 */
233 public void setRegexp(java.lang.String newRegexp) {
234 regexp = newRegexp;
235 }
236
237 /**
238 * Sets the program's Vector of required modules from a
239 * comma-delimited string.
240 * @param newRequiredModules java.util.Vector
241 */
242 public void setRequiredModules(String newRequiredModules) {
243 requiredModules = parseModuleList(newRequiredModules);
244 }
245
246 /**
247 * Sets the program's Vector of required modules.
248 * @param newRequiredModules java.util.Vector
249 */
250 public void setRequiredModules(java.util.Vector newRequiredModules) {
251 requiredModules = newRequiredModules;
252 }
253
254 /**
255 * Sets the program's Vector of StatsValue objects.
256 * @param newStatsValueList The new StatsValueList we're storing
257 */
258 public void setStatsValues(StatsValueList newStatsValueList) {
259 statsValueList = newStatsValueList;
260 }
261
262 /**
263 * Sets the program's source XML filename.
264 * (i.e. where we learned about it).
265 * @param newXmlFilename The XML filename which defines this object
266 */
267 public void setXmlFilename(java.lang.String newXmlFilename) {
268 xmlFilename = newXmlFilename;
269 }
270
271 /**
272 * Returns a formatted String of this object's values
273 * @return java.lang.String
274 */
275 public String toString() {
276 String s =
277 "xmlFilename='"
278 + xmlFilename
279 + "', "
280 + "program='"
281 + program
282 + "', "
283 + "regexp='"
284 + regexp
285 + "', "
286 + "requiredModules='"
287 + requiredModules
288 + "', "
289 + "maxRunTime='"
290 + maxRunTime
291 + "', "
292 + "statsValueList='"
293 + statsValueList
294 + "'";
295 return s;
296 }
297
298 /**
299 * Unsets the values in all of the attached StatsValue objects.
300 * Creation date: (1/22/2002 8:55:26 PM)
301 */
302 public void unsetStatsValues() {
303
304 statsValueList.unsetValues();
305
306 }
307
308 /**
309 * We override the <code>writeObject</code> method here to prevent
310 * serialization of our class for security reasons.
311 *
312 * @param out java.io.ObjectOutputStream
313 * @throws IOException thrown if a problem occurs
314 **/
315 private final void writeObject(ObjectOutputStream out) throws IOException {
316
317 throw new IOException("Object cannot be serialized");
318
319 }
320
321 }
|
StatsProgram |
|