001: /*
002: * $Id: TestBean.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.webapp.el.exercise;
023:
024: import org.apache.struts.action.ActionForm;
025: import org.apache.struts.action.ActionMapping;
026: import org.apache.struts.util.LabelValueBean;
027:
028: import javax.servlet.http.HttpServletRequest;
029: import java.util.Collection;
030: import java.util.Vector;
031:
032: /**
033: * General purpose test bean for Struts custom tag tests.
034: *
035: * @author Craig R. McClanahan
036: * @author Martin F N Cooper
037: * @version $Rev: 471754 $ $Date: 2004-10-16 13:04:52 -0400 (Sat, 16 Oct 2004)
038: * $
039: */
040:
041: public class TestBean extends ActionForm {
042:
043: // ------------------------------------------------------------- Properties
044:
045: /**
046: * A collection property where the elements of the collection are of type
047: * <code>LabelValueBean</code>.
048: */
049: private Collection beanCollection = null;
050:
051: public Collection getBeanCollection() {
052: if (beanCollection == null) {
053: Vector entries = new Vector(10);
054:
055: entries.add(new LabelValueBean("Label 0", "Value 0"));
056: entries.add(new LabelValueBean("Label 1", "Value 1"));
057: entries.add(new LabelValueBean("Label 2", "Value 2"));
058: entries.add(new LabelValueBean("Label 3", "Value 3"));
059: entries.add(new LabelValueBean("Label 4", "Value 4"));
060: entries.add(new LabelValueBean("Label 5", "Value 5"));
061: entries.add(new LabelValueBean("Label 6", "Value 6"));
062: entries.add(new LabelValueBean("Label 7", "Value 7"));
063: entries.add(new LabelValueBean("Label 8", "Value 8"));
064: entries.add(new LabelValueBean("Label 9", "Value 9"));
065:
066: beanCollection = entries;
067: }
068:
069: return (beanCollection);
070: }
071:
072: public void setBeanCollection(Collection beanCollection) {
073: this .beanCollection = beanCollection;
074: }
075:
076: /**
077: * A multiple-String SELECT element using a bean collection.
078: */
079: private String[] beanCollectionSelect = { "Value 1", "Value 3",
080: "Value 5" };
081:
082: public String[] getBeanCollectionSelect() {
083: return (this .beanCollectionSelect);
084: }
085:
086: public void setBeanCollectionSelect(String beanCollectionSelect[]) {
087: this .beanCollectionSelect = beanCollectionSelect;
088: }
089:
090: /**
091: * A boolean property whose initial value is true.
092: */
093: private boolean booleanProperty = true;
094:
095: public boolean getBooleanProperty() {
096: return (booleanProperty);
097: }
098:
099: public void setBooleanProperty(boolean booleanProperty) {
100: this .booleanProperty = booleanProperty;
101: }
102:
103: /**
104: * A multiple-String SELECT element using a collection.
105: */
106: private String[] collectionSelect = { "Value 2", "Value 4",
107: "Value 6" };
108:
109: public String[] getCollectionSelect() {
110: return (this .collectionSelect);
111: }
112:
113: public void setCollectionSelect(String collectionSelect[]) {
114: this .collectionSelect = collectionSelect;
115: }
116:
117: /**
118: * A double property.
119: */
120: private double doubleProperty = 321.0;
121:
122: public double getDoubleProperty() {
123: return (this .doubleProperty);
124: }
125:
126: public void setDoubleProperty(double doubleProperty) {
127: this .doubleProperty = doubleProperty;
128: }
129:
130: /**
131: * A boolean property whose initial value is false
132: */
133: private boolean falseProperty = false;
134:
135: public boolean getFalseProperty() {
136: return (falseProperty);
137: }
138:
139: public void setFalseProperty(boolean falseProperty) {
140: this .falseProperty = falseProperty;
141: }
142:
143: /**
144: * A float property.
145: */
146: private float floatProperty = (float) 123.0;
147:
148: public float getFloatProperty() {
149: return (this .floatProperty);
150: }
151:
152: public void setFloatProperty(float floatProperty) {
153: this .floatProperty = floatProperty;
154: }
155:
156: /**
157: * Integer arrays that are accessed as an array as well as indexed.
158: */
159: private int intArray[] = { 0, 10, 20, 30, 40 };
160:
161: public int[] getIntArray() {
162: return (this .intArray);
163: }
164:
165: public void setIntArray(int intArray[]) {
166: this .intArray = intArray;
167: }
168:
169: private int intIndexed[] = { 0, 10, 20, 30, 40 };
170:
171: public int getIntIndexed(int index) {
172: return (intIndexed[index]);
173: }
174:
175: public void setIntIndexed(int index, int value) {
176: intIndexed[index] = value;
177: }
178:
179: private int intMultibox[] = new int[0];
180:
181: public int[] getIntMultibox() {
182: return (this .intMultibox);
183: }
184:
185: public void setIntMultibox(int intMultibox[]) {
186: this .intMultibox = intMultibox;
187: }
188:
189: /**
190: * An integer property.
191: */
192: private int intProperty = 123;
193:
194: public int getIntProperty() {
195: return (this .intProperty);
196: }
197:
198: public void setIntProperty(int intProperty) {
199: this .intProperty = intProperty;
200: }
201:
202: /**
203: * A long property.
204: */
205: private long longProperty = 321;
206:
207: public long getLongProperty() {
208: return (this .longProperty);
209: }
210:
211: public void setLongProperty(long longProperty) {
212: this .longProperty = longProperty;
213: }
214:
215: /**
216: * A multiple-String SELECT element.
217: */
218: private String[] multipleSelect = { "Multiple 3", "Multiple 5",
219: "Multiple 7" };
220:
221: public String[] getMultipleSelect() {
222: return (this .multipleSelect);
223: }
224:
225: public void setMultipleSelect(String multipleSelect[]) {
226: this .multipleSelect = multipleSelect;
227: }
228:
229: /**
230: * A nested reference to another test bean (populated as needed).
231: */
232: private TestBean nested = null;
233:
234: public TestBean getNested() {
235: if (nested == null) {
236: nested = new TestBean();
237: }
238: return (nested);
239: }
240:
241: /**
242: * A String property with an initial value of null.
243: */
244: private String nullProperty = null;
245:
246: public String getNullProperty() {
247: return (this .nullProperty);
248: }
249:
250: public void setNullProperty(String nullProperty) {
251: this .nullProperty = nullProperty;
252: }
253:
254: /**
255: * A short property.
256: */
257: private short shortProperty = (short) 987;
258:
259: public short getShortProperty() {
260: return (this .shortProperty);
261: }
262:
263: public void setShortProperty(short shortProperty) {
264: this .shortProperty = shortProperty;
265: }
266:
267: /**
268: * A single-String value for a SELECT element.
269: */
270: private String singleSelect = "Single 5";
271:
272: public String getSingleSelect() {
273: return (this .singleSelect);
274: }
275:
276: public void setSingleSelect(String singleSelect) {
277: this .singleSelect = singleSelect;
278: }
279:
280: /**
281: * String arrays that are accessed as an array as well as indexed.
282: */
283: private String stringArray[] = { "String 0", "String 1",
284: "String 2", "String 3", "String 4" };
285:
286: public String[] getStringArray() {
287: return (this .stringArray);
288: }
289:
290: public void setStringArray(String stringArray[]) {
291: this .stringArray = stringArray;
292: }
293:
294: private String stringIndexed[] = { "String 0", "String 1",
295: "String 2", "String 3", "String 4" };
296:
297: public String getStringIndexed(int index) {
298: return (stringIndexed[index]);
299: }
300:
301: public void setStringIndexed(int index, String value) {
302: stringIndexed[index] = value;
303: }
304:
305: private String indexedStrings[] = { "alpha", "beta", "gamma",
306: "delta", "epsilon" };
307:
308: public String[] getIndexedStrings() {
309: return (indexedStrings);
310: }
311:
312: private String stringMultibox[] = new String[0];
313:
314: public String[] getStringMultibox() {
315: return (this .stringMultibox);
316: }
317:
318: public void setStringMultibox(String stringMultibox[]) {
319: this .stringMultibox = stringMultibox;
320: }
321:
322: /**
323: * A String property.
324: */
325: private String stringProperty = "This is a string";
326:
327: public String getStringProperty() {
328: return (this .stringProperty);
329: }
330:
331: public void setStringProperty(String stringProperty) {
332: this .stringProperty = stringProperty;
333: }
334:
335: /**
336: * An empty String property.
337: */
338: private String emptyStringProperty = "";
339:
340: public String getEmptyStringProperty() {
341: return (this .emptyStringProperty);
342: }
343:
344: public void setEmptyStringProperty(String emptyStringProperty) {
345: this .emptyStringProperty = emptyStringProperty;
346: }
347:
348: /**
349: * A list of coordinate objects.
350: */
351: private Coord[] coords = { new Coord(0, 0), new Coord(0, 1),
352: new Coord(1, 1), new Coord(2, 0), new Coord(2, 1) };
353:
354: public Coord[] getCoords() {
355: return (coords);
356: }
357:
358: public Coord getCoord(int index) {
359: return (coords[index]);
360: }
361:
362: public void setCoord(int index, Coord coord) {
363: coords[index] = coord;
364: }
365:
366: /**
367: * A list of images.
368: */
369: public String images[] = { "T1.gif", "T2.gif" };
370:
371: public String[] getImages() {
372: return (images);
373: }
374:
375: private Coord[] imageCoords = { new Coord(0, 0), new Coord(0, 0) };
376:
377: public Coord[] getImageCoords() {
378: return (imageCoords);
379: }
380:
381: public Coord getImageCoord(int index) {
382: return (imageCoords[index]);
383: }
384:
385: public void setImageCoord(int index, Coord coord) {
386: imageCoords[index] = coord;
387: }
388:
389: /**
390: * A property that allows a null value but is still used in a SELECT.
391: */
392: private String withNulls = null;
393:
394: public String getWithNulls() {
395: return (this .withNulls);
396: }
397:
398: public void setWithNulls(String withNulls) {
399: this .withNulls = withNulls;
400: }
401:
402: // --------------------------------------------------------- Public Methods
403:
404: /**
405: * Reset the properties that will be received as input.
406: */
407: public void reset(ActionMapping mapping, HttpServletRequest request) {
408:
409: booleanProperty = false;
410: collectionSelect = new String[0];
411: intMultibox = new int[0];
412: multipleSelect = new String[0];
413: stringMultibox = new String[0];
414: if (nested != null) {
415: nested.reset(mapping, request);
416: }
417:
418: }
419:
420: }
|