View Javadoc

1   /*
2    * $Id: TestBean.java 421491 2006-07-13 03:47:01Z wsmoak $
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.el.exercise;
21  
22  
23  import org.apache.struts.action.ActionForm;
24  import org.apache.struts.action.ActionMapping;
25  import org.apache.struts.util.LabelValueBean;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import java.util.Collection;
29  import java.util.Vector;
30  
31  
32  /***
33   * General purpose test bean for Struts custom tag tests.
34   *
35   * @author Craig R. McClanahan
36   * @author Martin F N Cooper
37   * @version $Rev: 421491 $ $Date: 2004-10-16 13:04:52 -0400 (Sat, 16 Oct 2004)
38   *          $
39   */
40  
41  public class TestBean extends ActionForm {
42  
43      // ------------------------------------------------------------- Properties
44  
45  
46      /***
47       * A collection property where the elements of the collection are of type
48       * <code>LabelValueBean</code>.
49       */
50      private Collection beanCollection = null;
51  
52      public Collection getBeanCollection() {
53          if (beanCollection == null) {
54              Vector entries = new Vector(10);
55  
56              entries.add(new LabelValueBean("Label 0", "Value 0"));
57              entries.add(new LabelValueBean("Label 1", "Value 1"));
58              entries.add(new LabelValueBean("Label 2", "Value 2"));
59              entries.add(new LabelValueBean("Label 3", "Value 3"));
60              entries.add(new LabelValueBean("Label 4", "Value 4"));
61              entries.add(new LabelValueBean("Label 5", "Value 5"));
62              entries.add(new LabelValueBean("Label 6", "Value 6"));
63              entries.add(new LabelValueBean("Label 7", "Value 7"));
64              entries.add(new LabelValueBean("Label 8", "Value 8"));
65              entries.add(new LabelValueBean("Label 9", "Value 9"));
66  
67              beanCollection = entries;
68          }
69  
70          return (beanCollection);
71      }
72  
73      public void setBeanCollection(Collection beanCollection) {
74          this.beanCollection = beanCollection;
75      }
76  
77  
78      /***
79       * A multiple-String SELECT element using a bean collection.
80       */
81      private String[] beanCollectionSelect = { "Value 1", "Value 3",
82              "Value 5" };
83  
84      public String[] getBeanCollectionSelect() {
85          return (this.beanCollectionSelect);
86      }
87  
88      public void setBeanCollectionSelect(String beanCollectionSelect[]) {
89          this.beanCollectionSelect = beanCollectionSelect;
90      }
91  
92  
93      /***
94       * A boolean property whose initial value is true.
95       */
96      private boolean booleanProperty = true;
97  
98      public boolean getBooleanProperty() {
99          return (booleanProperty);
100     }
101 
102     public void setBooleanProperty(boolean booleanProperty) {
103         this.booleanProperty = booleanProperty;
104     }
105 
106 
107     /***
108      * A multiple-String SELECT element using a collection.
109      */
110     private String[] collectionSelect = { "Value 2", "Value 4",
111             "Value 6" };
112 
113     public String[] getCollectionSelect() {
114         return (this.collectionSelect);
115     }
116 
117     public void setCollectionSelect(String collectionSelect[]) {
118         this.collectionSelect = collectionSelect;
119     }
120 
121 
122     /***
123      * A double property.
124      */
125     private double doubleProperty = 321.0;
126 
127     public double getDoubleProperty() {
128         return (this.doubleProperty);
129     }
130 
131     public void setDoubleProperty(double doubleProperty) {
132         this.doubleProperty = doubleProperty;
133     }
134 
135 
136     /***
137      * A boolean property whose initial value is false
138      */
139     private boolean falseProperty = false;
140 
141     public boolean getFalseProperty() {
142         return (falseProperty);
143     }
144 
145     public void setFalseProperty(boolean falseProperty) {
146         this.falseProperty = falseProperty;
147     }
148 
149 
150     /***
151      * A float property.
152      */
153     private float floatProperty = (float) 123.0;
154 
155     public float getFloatProperty() {
156         return (this.floatProperty);
157     }
158 
159     public void setFloatProperty(float floatProperty) {
160         this.floatProperty = floatProperty;
161     }
162 
163 
164     /***
165      * Integer arrays that are accessed as an array as well as indexed.
166      */
167     private int intArray[] = { 0, 10, 20, 30, 40 };
168 
169     public int[] getIntArray() {
170         return (this.intArray);
171     }
172 
173     public void setIntArray(int intArray[]) {
174         this.intArray = intArray;
175     }
176 
177     private int intIndexed[] = { 0, 10, 20, 30, 40 };
178 
179     public int getIntIndexed(int index) {
180         return (intIndexed[index]);
181     }
182 
183     public void setIntIndexed(int index, int value) {
184         intIndexed[index] = value;
185     }
186 
187 
188     private int intMultibox[] = new int[0];
189 
190     public int[] getIntMultibox() {
191         return (this.intMultibox);
192     }
193 
194     public void setIntMultibox(int intMultibox[]) {
195         this.intMultibox = intMultibox;
196     }
197 
198     /***
199      * An integer property.
200      */
201     private int intProperty = 123;
202 
203     public int getIntProperty() {
204         return (this.intProperty);
205     }
206 
207     public void setIntProperty(int intProperty) {
208         this.intProperty = intProperty;
209     }
210 
211 
212     /***
213      * A long property.
214      */
215     private long longProperty = 321;
216 
217     public long getLongProperty() {
218         return (this.longProperty);
219     }
220 
221     public void setLongProperty(long longProperty) {
222         this.longProperty = longProperty;
223     }
224 
225 
226     /***
227      * A multiple-String SELECT element.
228      */
229     private String[] multipleSelect = { "Multiple 3", "Multiple 5",
230             "Multiple 7" };
231 
232     public String[] getMultipleSelect() {
233         return (this.multipleSelect);
234     }
235 
236     public void setMultipleSelect(String multipleSelect[]) {
237         this.multipleSelect = multipleSelect;
238     }
239 
240 
241     /***
242      * A nested reference to another test bean (populated as needed).
243      */
244     private TestBean nested = null;
245 
246     public TestBean getNested() {
247         if (nested == null) {
248             nested = new TestBean();
249         }
250         return (nested);
251     }
252 
253 
254     /***
255      * A String property with an initial value of null.
256      */
257     private String nullProperty = null;
258 
259     public String getNullProperty() {
260         return (this.nullProperty);
261     }
262 
263     public void setNullProperty(String 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 singleSelect = "Single 5";
286 
287     public String getSingleSelect() {
288         return (this.singleSelect);
289     }
290 
291     public void setSingleSelect(String 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 stringArray[] =
300             { "String 0", "String 1", "String 2", "String 3", "String 4" };
301 
302     public String[] getStringArray() {
303         return (this.stringArray);
304     }
305 
306     public void setStringArray(String stringArray[]) {
307         this.stringArray = stringArray;
308     }
309 
310     private String stringIndexed[] =
311             { "String 0", "String 1", "String 2", "String 3", "String 4" };
312 
313     public String getStringIndexed(int index) {
314         return (stringIndexed[index]);
315     }
316 
317     public void setStringIndexed(int index, String value) {
318         stringIndexed[index] = value;
319     }
320 
321     private String indexedStrings[] =
322             { "alpha", "beta", "gamma", "delta", "epsilon" };
323 
324     public String[] getIndexedStrings() {
325         return (indexedStrings);
326     }
327 
328     private String stringMultibox[] = new String[0];
329 
330     public String[] getStringMultibox() {
331         return (this.stringMultibox);
332     }
333 
334     public void setStringMultibox(String stringMultibox[]) {
335         this.stringMultibox = stringMultibox;
336     }
337 
338     /***
339      * A String property.
340      */
341     private String stringProperty = "This is a string";
342 
343     public String getStringProperty() {
344         return (this.stringProperty);
345     }
346 
347     public void setStringProperty(String stringProperty) {
348         this.stringProperty = stringProperty;
349     }
350 
351     /***
352      * An empty String property.
353      */
354     private String emptyStringProperty = "";
355 
356     public String getEmptyStringProperty() {
357         return (this.emptyStringProperty);
358     }
359 
360     public void setEmptyStringProperty(String emptyStringProperty) {
361         this.emptyStringProperty = emptyStringProperty;
362     }
363 
364     /***
365      * A list of coordinate objects.
366      */
367     private Coord[] coords =
368             { new Coord(0, 0), new Coord(0, 1), new Coord(1, 1),
369                     new Coord(2, 0),
370                     new Coord(2, 1)
371             };
372 
373     public Coord[]  getCoords() {
374         return (coords);
375     }
376 
377     public Coord getCoord(int index) {
378         return (coords[index]);
379     }
380 
381     public void setCoord(int index, Coord coord) {
382         coords[index] = coord;
383     }
384 
385     /***
386      * A list of images.
387      */
388     public String images[] = { "T1.gif", "T2.gif" };
389 
390     public String[] getImages() {
391         return (images);
392     }
393 
394     private Coord[] imageCoords = { new Coord(0, 0), new Coord(0, 0) };
395 
396     public Coord[]  getImageCoords() {
397         return (imageCoords);
398     }
399 
400     public Coord getImageCoord(int index) {
401         return (imageCoords[index]);
402     }
403 
404     public void setImageCoord(int index, Coord coord) {
405         imageCoords[index] = coord;
406     }
407 
408     /***
409      * A property that allows a null value but is still used in a SELECT.
410      */
411     private String withNulls = null;
412 
413     public String getWithNulls() {
414         return (this.withNulls);
415     }
416 
417     public void setWithNulls(String withNulls) {
418         this.withNulls = withNulls;
419     }
420 
421     // --------------------------------------------------------- Public Methods
422 
423 
424     /***
425      * Reset the properties that will be received as input.
426      */
427     public void reset(ActionMapping mapping, HttpServletRequest request) {
428 
429         booleanProperty = false;
430         collectionSelect = new String[0];
431         intMultibox = new int[0];
432         multipleSelect = new String[0];
433         stringMultibox = new String[0];
434         if (nested != null) {
435             nested.reset(mapping, request);
436         }
437 
438     }
439 
440 
441 }