~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/struts-el/src/exercise-taglib/org/apache/struts/webapp/exercise/TestBean.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
ImportĀ upstreamĀ versionĀ 1.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Header: /home/cvs/jakarta-struts/contrib/struts-el/src/exercise-taglib/org/apache/struts/webapp/exercise/TestBean.java,v 1.3 2004/03/14 07:15:06 sraeburn Exp $
 
3
 * $Revision: 1.3 $
 
4
 * $Date: 2004/03/14 07:15:06 $
 
5
 *
 
6
 * Copyright 1999-2004 The Apache Software Foundation.
 
7
 * 
 
8
 * Licensed under the Apache License, Version 2.0 (the "License");
 
9
 * you may not use this file except in compliance with the License.
 
10
 * You may obtain a copy of the License at
 
11
 * 
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 * 
 
14
 * Unless required by applicable law or agreed to in writing, software
 
15
 * distributed under the License is distributed on an "AS IS" BASIS,
 
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
17
 * See the License for the specific language governing permissions and
 
18
 * limitations under the License.
 
19
 */
 
20
 
 
21
 
 
22
package org.apache.struts.webapp.exercise;
 
23
 
 
24
 
 
25
import java.util.Collection;
 
26
import java.util.Vector;
 
27
import javax.servlet.http.HttpServletRequest;
 
28
import org.apache.struts.action.ActionForm;
 
29
import org.apache.struts.action.ActionMapping;
 
30
import org.apache.struts.util.LabelValueBean;
 
31
 
 
32
 
 
33
/**
 
34
 * General purpose test bean for Struts custom tag tests.
 
35
 *
 
36
 * @author Craig R. McClanahan
 
37
 * @author Martin F N Cooper
 
38
 * @version $Revision: 1.3 $ $Date: 2004/03/14 07:15:06 $
 
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 beanCollection = null;
 
52
 
 
53
    public Collection getBeanCollection() {
 
54
        if (beanCollection == null) {
 
55
            Vector entries = new Vector(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 beanCollection) {
 
75
        this.beanCollection = beanCollection;
 
76
    }
 
77
 
 
78
 
 
79
    /**
 
80
     * A multiple-String SELECT element using a bean collection.
 
81
     */
 
82
    private String[] beanCollectionSelect = { "Value 1", "Value 3",
 
83
                                              "Value 5" };
 
84
 
 
85
    public String[] getBeanCollectionSelect() {
 
86
        return (this.beanCollectionSelect);
 
87
    }
 
88
 
 
89
    public void setBeanCollectionSelect(String 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[] collectionSelect = { "Value 2", "Value 4",
 
112
                                          "Value 6" };
 
113
 
 
114
    public String[] getCollectionSelect() {
 
115
        return (this.collectionSelect);
 
116
    }
 
117
 
 
118
    public void setCollectionSelect(String 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[] multipleSelect = { "Multiple 3", "Multiple 5",
 
231
                                        "Multiple 7" };
 
232
 
 
233
    public String[] getMultipleSelect() {
 
234
        return (this.multipleSelect);
 
235
    }
 
236
 
 
237
    public void setMultipleSelect(String 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 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
    {
 
326
        return (indexedStrings);
 
327
    }
 
328
    
 
329
    private String stringMultibox[] = new String[0];
 
330
 
 
331
    public String[] getStringMultibox() {
 
332
        return (this.stringMultibox);
 
333
    }
 
334
 
 
335
    public void setStringMultibox(String stringMultibox[]) {
 
336
        this.stringMultibox = stringMultibox;
 
337
    }
 
338
 
 
339
    /**
 
340
     * A String property.
 
341
     */
 
342
    private String stringProperty = "This is a string";
 
343
 
 
344
    public String getStringProperty() {
 
345
        return (this.stringProperty);
 
346
    }
 
347
 
 
348
    public void setStringProperty(String stringProperty) {
 
349
        this.stringProperty = stringProperty;
 
350
    }
 
351
 
 
352
    /**
 
353
     * An empty String property.
 
354
     */
 
355
    private String emptyStringProperty = "";
 
356
 
 
357
    public String getEmptyStringProperty() {
 
358
        return (this.emptyStringProperty);
 
359
    }
 
360
 
 
361
    public void setEmptyStringProperty(String emptyStringProperty) {
 
362
        this.emptyStringProperty = emptyStringProperty;
 
363
    }
 
364
 
 
365
    /**
 
366
     * A list of coordinate objects.
 
367
     */
 
368
    private Coord[]  coords   =
 
369
    { new Coord(0, 0), new Coord(0, 1), new Coord(1, 1), new Coord(2, 0),
 
370
      new Coord(2, 1) 
 
371
    };
 
372
 
 
373
    public  Coord[]  getCoords() { return (coords); }
 
374
    
 
375
    public  Coord getCoord(int index) { return (coords[index]); }
 
376
 
 
377
    public  void  setCoord(int index, Coord coord) { coords[index]   = coord; }
 
378
 
 
379
    /**
 
380
     * A list of images.
 
381
     */
 
382
    public  String   images[] = {"T1.gif", "T2.gif"};
 
383
 
 
384
    public  String[] getImages() { return (images); }
 
385
 
 
386
    private Coord[]  imageCoords = { new Coord(0, 0),  new Coord(0, 0) };
 
387
 
 
388
    public  Coord[]  getImageCoords() { return (imageCoords); }
 
389
 
 
390
    public  Coord getImageCoord(int index) { return (imageCoords[index]); }
 
391
 
 
392
    public  void  setImageCoord(int index, Coord coord)
 
393
    { imageCoords[index] = coord; }
 
394
    
 
395
    /**
 
396
     * A property that allows a null value but is still used in a SELECT.
 
397
     */
 
398
    private String withNulls = null;
 
399
 
 
400
    public String getWithNulls() {
 
401
        return (this.withNulls);
 
402
    }
 
403
 
 
404
    public void setWithNulls(String withNulls) {
 
405
        this.withNulls = withNulls;
 
406
    }
 
407
 
 
408
 
 
409
    // --------------------------------------------------------- Public Methods
 
410
 
 
411
 
 
412
    /**
 
413
     * Reset the properties that will be received as input.
 
414
     */
 
415
    public void reset(ActionMapping mapping, HttpServletRequest request) {
 
416
 
 
417
        booleanProperty = false;
 
418
        collectionSelect = new String[0];
 
419
        intMultibox = new int[0];
 
420
        multipleSelect = new String[0];
 
421
        stringMultibox = new String[0];
 
422
        if (nested != null)
 
423
            nested.reset(mapping, request);
 
424
 
 
425
    }
 
426
 
 
427
 
 
428
}