001/* $Id: TestBean.java 1212599 2011-12-09 19:46:42Z simonetripodi $
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements.  See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.commons.digester3;
020
021import org.apache.commons.digester3.annotations.rules.CallParam;
022import org.apache.commons.digester3.annotations.rules.ObjectCreate;
023
024/**
025 * General purpose test bean for Digester tests.
026 *
027 * @author Craig R. McClanahan
028 */
029public class TestBean
030{
031
032    public TestBean()
033    {
034        // do nothing
035    }
036
037    @ObjectCreate( pattern = "toplevel/bean" )
038    public TestBean( @CallParam( pattern = "toplevel/bean", attributeName = "boolean" ) boolean booleanProperty,
039                     @CallParam( pattern = "toplevel/bean", attributeName = "double" ) double doubleProperty )
040    {
041        setBooleanProperty( booleanProperty );
042        setDoubleProperty( doubleProperty );
043    }
044
045    /**
046     * see DIGESTER-154
047     *
048     * @param booleanProperty
049     * @param doubleProperty
050     */
051    public TestBean( Boolean booleanProperty, Double doubleProperty )
052    {
053        this( booleanProperty.booleanValue(), doubleProperty.doubleValue() );
054    }
055
056    // ------------------------------------------------------------- Properties
057
058    /**
059     * A boolean property whose initial value is true.
060     */
061    private boolean booleanProperty = true;
062
063    public boolean getBooleanProperty()
064    {
065        return ( booleanProperty );
066    }
067
068    public void setBooleanProperty( boolean booleanProperty )
069    {
070        this.booleanProperty = booleanProperty;
071    }
072
073    /**
074     * A double property.
075     */
076    private double doubleProperty = 321.0;
077
078    public double getDoubleProperty()
079    {
080        return ( this.doubleProperty );
081    }
082
083    public void setDoubleProperty( double doubleProperty )
084    {
085        this.doubleProperty = doubleProperty;
086    }
087
088    /**
089     * A boolean property whose initial value is false
090     */
091    private boolean falseProperty = false;
092
093    public boolean getFalseProperty()
094    {
095        return ( falseProperty );
096    }
097
098    public void setFalseProperty( boolean falseProperty )
099    {
100        this.falseProperty = falseProperty;
101    }
102
103    /**
104     * A float property.
105     */
106    private float floatProperty = (float) 123.0;
107
108    public float getFloatProperty()
109    {
110        return ( this.floatProperty );
111    }
112
113    public void setFloatProperty( float floatProperty )
114    {
115        this.floatProperty = floatProperty;
116    }
117
118    /**
119     * Integer arrays that are accessed as an array as well as indexed.
120     */
121    private int intArray[] = { 0, 10, 20, 30, 40 };
122
123    public int[] getIntArray()
124    {
125        return ( this.intArray );
126    }
127
128    public void setIntArray( int intArray[] )
129    {
130        this.intArray = intArray;
131    }
132
133    private int intIndexed[] = { 0, 10, 20, 30, 40 };
134
135    public int getIntIndexed( int index )
136    {
137        return ( intIndexed[index] );
138    }
139
140    public void setIntIndexed( int index, int value )
141    {
142        intIndexed[index] = value;
143    }
144
145    private int intMultibox[] = new int[0];
146
147    public int[] getIntMultibox()
148    {
149        return ( this.intMultibox );
150    }
151
152    public void setIntMultibox( int intMultibox[] )
153    {
154        this.intMultibox = intMultibox;
155    }
156
157    /**
158     * An integer property.
159     */
160    private int intProperty = 123;
161
162    public int getIntProperty()
163    {
164        return ( this.intProperty );
165    }
166
167    public void setIntProperty( int intProperty )
168    {
169        this.intProperty = intProperty;
170    }
171
172    /**
173     * A long property.
174     */
175    private long longProperty = 321;
176
177    public long getLongProperty()
178    {
179        return ( this.longProperty );
180    }
181
182    public void setLongProperty( long longProperty )
183    {
184        this.longProperty = longProperty;
185    }
186
187    /**
188     * A multiple-String SELECT element.
189     */
190    private String[] multipleSelect = { "Multiple 3", "Multiple 5", "Multiple 7" };
191
192    public String[] getMultipleSelect()
193    {
194        return ( this.multipleSelect );
195    }
196
197    public void setMultipleSelect( String multipleSelect[] )
198    {
199        this.multipleSelect = multipleSelect;
200    }
201
202    /**
203     * A nested reference to another test bean (populated as needed).
204     */
205    private TestBean nested = null;
206
207    public TestBean getNested()
208    {
209        if ( nested == null )
210            nested = new TestBean();
211        return ( nested );
212    }
213
214    /**
215     * A String property with an initial value of null.
216     */
217    private String nullProperty = null;
218
219    public String getNullProperty()
220    {
221        return ( this.nullProperty );
222    }
223
224    public void setNullProperty( String nullProperty )
225    {
226        this.nullProperty = nullProperty;
227    }
228
229    /**
230     * A short property.
231     */
232    private short shortProperty = (short) 987;
233
234    public short getShortProperty()
235    {
236        return ( this.shortProperty );
237    }
238
239    public void setShortProperty( short shortProperty )
240    {
241        this.shortProperty = shortProperty;
242    }
243
244    /**
245     * A single-String value for a SELECT element.
246     */
247    private String singleSelect = "Single 5";
248
249    public String getSingleSelect()
250    {
251        return ( this.singleSelect );
252    }
253
254    public void setSingleSelect( String singleSelect )
255    {
256        this.singleSelect = singleSelect;
257    }
258
259    /**
260     * String arrays that are accessed as an array as well as indexed.
261     */
262    private String stringArray[] = { "String 0", "String 1", "String 2", "String 3", "String 4" };
263
264    public String[] getStringArray()
265    {
266        return ( this.stringArray );
267    }
268
269    public void setStringArray( String stringArray[] )
270    {
271        this.stringArray = stringArray;
272    }
273
274    private String stringIndexed[] = { "String 0", "String 1", "String 2", "String 3", "String 4" };
275
276    public String getStringIndexed( int index )
277    {
278        return ( stringIndexed[index] );
279    }
280
281    public void setStringIndexed( int index, String value )
282    {
283        stringIndexed[index] = value;
284    }
285
286    /**
287     * A String property.
288     */
289    private String stringProperty = "This is a string";
290
291    public String getStringProperty()
292    {
293        return ( this.stringProperty );
294    }
295
296    public void setStringProperty( String stringProperty )
297    {
298        this.stringProperty = stringProperty;
299    }
300
301    /**
302     * An empty String property.
303     */
304    private String emptyStringProperty = "";
305
306    public String getEmptyStringProperty()
307    {
308        return ( this.emptyStringProperty );
309    }
310
311    public void setEmptyStringProperty( String emptyStringProperty )
312    {
313        this.emptyStringProperty = emptyStringProperty;
314    }
315
316}