KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > exercise > TestBean


1 /*
2  * $Id: TestBean.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19
20 package org.apache.struts.webapp.exercise;
21
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Vector JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.util.LabelValueBean;
33
34
35 /**
36  * General purpose test bean for Struts custom tag tests.
37  *
38  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
39  */

40
41 public class TestBean extends ActionForm {
42
43
44     // ------------------------------------------------------------- Properties
45

46
47     /**
48      * A collection property where the elements of the collection are
49      * of type <code>LabelValueBean</code>.
50      */

51     private Collection JavaDoc beanCollection = null;
52
53     public Collection JavaDoc getBeanCollection() {
54         if (beanCollection == null) {
55             Vector JavaDoc entries = new Vector JavaDoc(10);
56
57             entries.add(new LabelValueBean("Label 0", "Value 0"));
58             entries.add(new LabelValueBean("Label 1", "Value 1"));
59             entries.add(new LabelValueBean("Label 2", "Value 2"));
60             entries.add(new LabelValueBean("Label 3", "Value 3"));
61             entries.add(new LabelValueBean("Label 4", "Value 4"));
62             entries.add(new LabelValueBean("Label 5", "Value 5"));
63             entries.add(new LabelValueBean("Label 6", "Value 6"));
64             entries.add(new LabelValueBean("Label 7", "Value 7"));
65             entries.add(new LabelValueBean("Label 8", "Value 8"));
66             entries.add(new LabelValueBean("Label 9", "Value 9"));
67
68             beanCollection = entries;
69         }
70
71         return (beanCollection);
72     }
73
74     public void setBeanCollection(Collection JavaDoc beanCollection) {
75         this.beanCollection = beanCollection;
76     }
77
78
79     /**
80      * A multiple-String SELECT element using a bean collection.
81      */

82     private String JavaDoc[] beanCollectionSelect = { "Value 1", "Value 3",
83                                               "Value 5" };
84
85     public String JavaDoc[] getBeanCollectionSelect() {
86         return (this.beanCollectionSelect);
87     }
88
89     public void setBeanCollectionSelect(String JavaDoc beanCollectionSelect[]) {
90         this.beanCollectionSelect = beanCollectionSelect;
91     }
92
93
94     /**
95      * A boolean property whose initial value is true.
96      */

97     private boolean booleanProperty = true;
98
99     public boolean getBooleanProperty() {
100         return (booleanProperty);
101     }
102
103     public void setBooleanProperty(boolean booleanProperty) {
104         this.booleanProperty = booleanProperty;
105     }
106
107
108     /**
109      * A multiple-String SELECT element using a collection.
110      */

111     private String JavaDoc[] collectionSelect = { "Value 2", "Value 4",
112                                           "Value 6" };
113
114     public String JavaDoc[] getCollectionSelect() {
115         return (this.collectionSelect);
116     }
117
118     public void setCollectionSelect(String JavaDoc collectionSelect[]) {
119         this.collectionSelect = collectionSelect;
120     }
121
122
123     /**
124      * A double property.
125      */

126     private double doubleProperty = 321.0;
127
128     public double getDoubleProperty() {
129         return (this.doubleProperty);
130     }
131
132     public void setDoubleProperty(double doubleProperty) {
133         this.doubleProperty = doubleProperty;
134     }
135
136
137     /**
138      * A boolean property whose initial value is false
139      */

140     private boolean falseProperty = false;
141
142     public boolean getFalseProperty() {
143         return (falseProperty);
144     }
145
146     public void setFalseProperty(boolean falseProperty) {
147         this.falseProperty = falseProperty;
148     }
149
150
151     /**
152      * A float property.
153      */

154     private float floatProperty = (float) 123.0;
155
156     public float getFloatProperty() {
157         return (this.floatProperty);
158     }
159
160     public void setFloatProperty(float floatProperty) {
161         this.floatProperty = floatProperty;
162     }
163
164
165     /**
166      * Integer arrays that are accessed as an array as well as indexed.
167      */

168     private int intArray[] = { 0, 10, 20, 30, 40 };
169
170     public int[] getIntArray() {
171         return (this.intArray);
172     }
173
174     public void setIntArray(int intArray[]) {
175         this.intArray = intArray;
176     }
177
178     private int intIndexed[] = { 0, 10, 20, 30, 40 };
179
180     public int getIntIndexed(int index) {
181         return (intIndexed[index]);
182     }
183
184     public void setIntIndexed(int index, int value) {
185         intIndexed[index] = value;
186     }
187
188
189     private int intMultibox[] = new int[0];
190
191     public int[] getIntMultibox() {
192         return (this.intMultibox);
193     }
194
195     public void setIntMultibox(int intMultibox[]) {
196         this.intMultibox = intMultibox;
197     }
198
199     /**
200      * An integer property.
201      */

202     private int intProperty = 123;
203
204     public int getIntProperty() {
205         return (this.intProperty);
206     }
207
208     public void setIntProperty(int intProperty) {
209         this.intProperty = intProperty;
210     }
211
212
213     /**
214      * A long property.
215      */

216     private long longProperty = 321;
217
218     public long getLongProperty() {
219         return (this.longProperty);
220     }
221
222     public void setLongProperty(long longProperty) {
223         this.longProperty = longProperty;
224     }
225
226
227     /**
228      * A multiple-String SELECT element.
229      */

230     private String JavaDoc[] multipleSelect = { "Multiple 3", "Multiple 5",
231                                         "Multiple 7" };
232
233     public String JavaDoc[] getMultipleSelect() {
234         return (this.multipleSelect);
235     }
236
237     public void setMultipleSelect(String JavaDoc multipleSelect[]) {
238         this.multipleSelect = multipleSelect;
239     }
240
241
242     /**
243      * A nested reference to another test bean (populated as needed).
244      */

245     private TestBean nested = null;
246
247     public TestBean getNested() {
248         if (nested == null)
249             nested = new TestBean();
250         return (nested);
251     }
252
253
254     /**
255      * A String property with an initial value of null.
256      */

257     private String JavaDoc nullProperty = null;
258
259     public String JavaDoc getNullProperty() {
260         return (this.nullProperty);
261     }
262
263     public void setNullProperty(String JavaDoc nullProperty) {
264         this.nullProperty = nullProperty;
265     }
266
267
268     /**
269      * A short property.
270      */

271     private short shortProperty = (short) 987;
272
273     public short getShortProperty() {
274         return (this.shortProperty);
275     }
276
277     public void setShortProperty(short shortProperty) {
278         this.shortProperty = shortProperty;
279     }
280
281
282     /**
283      * A single-String value for a SELECT element.
284      */

285     private String JavaDoc singleSelect = "Single 5";
286
287     public String JavaDoc getSingleSelect() {
288         return (this.singleSelect);
289     }
290
291     public void setSingleSelect(String JavaDoc singleSelect) {
292         this.singleSelect = singleSelect;
293     }
294
295
296     /**
297      * String arrays that are accessed as an array as well as indexed.
298      */

299     private String JavaDoc stringArray[] =
300     { "String 0", "String 1", "String 2", "String 3", "String 4" };
301
302     public String JavaDoc[] getStringArray() {
303         return (this.stringArray);
304     }
305
306     public void setStringArray(String JavaDoc stringArray[]) {
307         this.stringArray = stringArray;
308     }
309
310     private String JavaDoc stringIndexed[] =
311     { "String 0", "String 1", "String 2", "String 3", "String 4" };
312
313     public String JavaDoc getStringIndexed(int index) {
314         return (stringIndexed[index]);
315     }
316
317     public void setStringIndexed(int index, String JavaDoc value) {
318         stringIndexed[index] = value;
319     }
320
321
322     private String JavaDoc stringMultibox[] = new String JavaDoc[0];
323
324     public String JavaDoc[] getStringMultibox() {
325         return (this.stringMultibox);
326     }
327
328     public void setStringMultibox(String JavaDoc stringMultibox[]) {
329         this.stringMultibox = stringMultibox;
330     }
331
332     /**
333      * A String property.
334      */

335     private String JavaDoc stringProperty = "This is a string";
336
337     public String JavaDoc getStringProperty() {
338         return (this.stringProperty);
339     }
340
341     public void setStringProperty(String JavaDoc stringProperty) {
342         this.stringProperty = stringProperty;
343     }
344
345     /**
346      * An empty String property.
347      */

348     private String JavaDoc emptyStringProperty = "";
349
350     public String JavaDoc getEmptyStringProperty() {
351         return (this.emptyStringProperty);
352     }
353
354     public void setEmptyStringProperty(String JavaDoc emptyStringProperty) {
355         this.emptyStringProperty = emptyStringProperty;
356     }
357
358
359     /**
360      * A single-String value for a SELECT element based on resource strings.
361      */

362     private String JavaDoc resourcesSelect = "Resources 2";
363
364     public String JavaDoc getResourcesSelect() {
365         return (this.resourcesSelect);
366     }
367
368     public void setResourcesSelect(String JavaDoc resourcesSelect) {
369         this.resourcesSelect = resourcesSelect;
370     }
371
372
373     /**
374      * A property that allows a null value but is still used in a SELECT.
375      */

376     private String JavaDoc withNulls = null;
377
378     public String JavaDoc getWithNulls() {
379         return (this.withNulls);
380     }
381
382     public void setWithNulls(String JavaDoc withNulls) {
383         this.withNulls = withNulls;
384     }
385
386
387     /**
388      * A List property.
389      */

390     private List JavaDoc listProperty = null;
391
392     public List JavaDoc getListProperty() {
393         if (listProperty == null) {
394             listProperty = new ArrayList JavaDoc();
395             listProperty.add("dummy");
396         }
397         return listProperty;
398     }
399
400     public void setListProperty(List JavaDoc listProperty) {
401         this.listProperty = listProperty;
402     }
403
404     /**
405      * An empty List property.
406      */

407     private List JavaDoc emptyListProperty = null;
408
409     public List JavaDoc getEmptyListProperty() {
410         if (emptyListProperty == null) {
411             emptyListProperty = new ArrayList JavaDoc();
412         }
413         return emptyListProperty;
414     }
415
416     public void setEmptyListProperty(List JavaDoc emptyListProperty) {
417         this.emptyListProperty = emptyListProperty;
418     }
419
420
421     /**
422      * A Map property.
423      */

424     private Map JavaDoc mapProperty = null;
425
426     public Map JavaDoc getMapProperty() {
427         if (mapProperty == null) {
428             mapProperty = new HashMap JavaDoc();
429             mapProperty.put("dummy", "dummy");
430         }
431         return mapProperty;
432     }
433
434     public void setMapProperty(Map JavaDoc mapProperty) {
435         this.mapProperty = mapProperty;
436     }
437
438     /**
439      * An empty Map property.
440      */

441     private Map JavaDoc emptyMapProperty = null;
442
443     public Map JavaDoc getEmptyMapProperty() {
444         if (emptyMapProperty == null) {
445             emptyMapProperty = new HashMap JavaDoc();
446         }
447         return emptyMapProperty;
448     }
449
450     public void setEmptyMapProperty(Map JavaDoc emptyMapProperty) {
451         this.emptyMapProperty = emptyMapProperty;
452     }
453
454
455     // --------------------------------------------------------- Public Methods
456

457
458     /**
459      * Reset the properties that will be received as input.
460      */

461     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
462
463         booleanProperty = false;
464         collectionSelect = new String JavaDoc[0];
465         intMultibox = new int[0];
466         multipleSelect = new String JavaDoc[0];
467         stringMultibox = new String JavaDoc[0];
468         if (nested != null)
469             nested.reset(mapping, request);
470
471     }
472
473
474 }
475
Popular Tags