View Javadoc

1   /* $Id: TestBean.java 1212599 2011-12-09 19:46:42Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  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  package org.apache.commons.digester3;
20  
21  import org.apache.commons.digester3.annotations.rules.CallParam;
22  import org.apache.commons.digester3.annotations.rules.ObjectCreate;
23  
24  /**
25   * General purpose test bean for Digester tests.
26   *
27   * @author Craig R. McClanahan
28   */
29  public class TestBean
30  {
31  
32      public TestBean()
33      {
34          // do nothing
35      }
36  
37      @ObjectCreate( pattern = "toplevel/bean" )
38      public TestBean( @CallParam( pattern = "toplevel/bean", attributeName = "boolean" ) boolean booleanProperty,
39                       @CallParam( pattern = "toplevel/bean", attributeName = "double" ) double doubleProperty )
40      {
41          setBooleanProperty( booleanProperty );
42          setDoubleProperty( doubleProperty );
43      }
44  
45      /**
46       * see DIGESTER-154
47       *
48       * @param booleanProperty
49       * @param doubleProperty
50       */
51      public TestBean( Boolean booleanProperty, Double doubleProperty )
52      {
53          this( booleanProperty.booleanValue(), doubleProperty.doubleValue() );
54      }
55  
56      // ------------------------------------------------------------- Properties
57  
58      /**
59       * A boolean property whose initial value is true.
60       */
61      private boolean booleanProperty = true;
62  
63      public boolean getBooleanProperty()
64      {
65          return ( booleanProperty );
66      }
67  
68      public void setBooleanProperty( boolean booleanProperty )
69      {
70          this.booleanProperty = booleanProperty;
71      }
72  
73      /**
74       * A double property.
75       */
76      private double doubleProperty = 321.0;
77  
78      public double getDoubleProperty()
79      {
80          return ( this.doubleProperty );
81      }
82  
83      public void setDoubleProperty( double doubleProperty )
84      {
85          this.doubleProperty = doubleProperty;
86      }
87  
88      /**
89       * A boolean property whose initial value is false
90       */
91      private boolean falseProperty = false;
92  
93      public boolean getFalseProperty()
94      {
95          return ( falseProperty );
96      }
97  
98      public void setFalseProperty( boolean falseProperty )
99      {
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 }