KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > bean > TestBean


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package com.tctest.spring.bean;
18
19 import java.util.Collection JavaDoc;
20 import java.util.Date JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.LinkedList JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Properties JavaDoc;
29
30 import org.springframework.beans.factory.BeanFactory;
31 import org.springframework.beans.factory.BeanFactoryAware;
32 import org.springframework.beans.factory.BeanNameAware;
33 import org.springframework.util.ObjectUtils;
34
35
36 /**
37  * Simple test bean used for testing bean factories,
38  * AOP framework etc.
39  *
40  * @author Rod Johnson
41  * @since 15 April 2001
42  */

43 public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable JavaDoc {
44
45     private String JavaDoc beanName;
46
47     private String JavaDoc country;
48
49     private BeanFactory beanFactory;
50
51     private boolean postProcessed;
52
53     private String JavaDoc name;
54
55     private String JavaDoc sex;
56
57     private int age;
58
59     private boolean jedi;
60
61     private ITestBean spouse;
62
63     private String JavaDoc touchy;
64
65     private String JavaDoc[] stringArray;
66
67     private Date JavaDoc date = new Date JavaDoc();
68
69     private Float JavaDoc myFloat = new Float JavaDoc(0.0);
70
71     private Collection JavaDoc friends = new LinkedList JavaDoc();
72
73     private Set JavaDoc someSet = new HashSet JavaDoc();
74
75     private Map JavaDoc someMap = new HashMap JavaDoc();
76
77     private List JavaDoc someList = new ArrayList JavaDoc();
78
79     private Properties JavaDoc someProperties = new Properties JavaDoc();
80
81     private INestedTestBean doctor = new NestedTestBean();
82
83     private INestedTestBean lawyer = new NestedTestBean();
84
85     private IndexedTestBean nestedIndexedBean;
86
87     private boolean destroyed = false;
88
89     private Number JavaDoc someNumber;
90
91
92     public TestBean() {
93     }
94
95     public TestBean(String JavaDoc name) {
96         this.name = name;
97     }
98
99     public TestBean(ITestBean spouse) {
100         this.spouse = spouse;
101     }
102
103     public TestBean(String JavaDoc name, int age) {
104         this.name = name;
105         this.age = age;
106     }
107
108     public void setBeanName(String JavaDoc beanName) {
109         this.beanName = beanName;
110     }
111
112     public String JavaDoc getBeanName() {
113         return beanName;
114     }
115
116     public void setBeanFactory(BeanFactory beanFactory) {
117         this.beanFactory = beanFactory;
118     }
119
120     public BeanFactory getBeanFactory() {
121         return beanFactory;
122     }
123
124     public void setPostProcessed(boolean postProcessed) {
125         this.postProcessed = postProcessed;
126     }
127
128     public boolean isPostProcessed() {
129         return postProcessed;
130     }
131
132     public String JavaDoc getName() {
133         return name;
134     }
135
136     public void setName(String JavaDoc name) {
137         this.name = name;
138     }
139
140     public String JavaDoc getSex() {
141         return sex;
142     }
143
144     public void setSex(String JavaDoc sex) {
145         this.sex = sex;
146     }
147
148     public int getAge() {
149         return age;
150     }
151
152     public void setAge(int age) {
153         this.age = age;
154     }
155
156     public boolean isJedi() {
157         return jedi;
158     }
159
160     public void setJedi(boolean jedi) {
161         this.jedi = jedi;
162     }
163
164     public ITestBean getSpouse() {
165         return spouse;
166     }
167
168     public void setSpouse(ITestBean spouse) {
169         this.spouse = spouse;
170     }
171
172     public String JavaDoc getTouchy() {
173         return touchy;
174     }
175
176     public void setTouchy(String JavaDoc touchy) throws Exception JavaDoc {
177         if (touchy.indexOf('.') != -1) {
178             throw new Exception JavaDoc("Can't contain a .");
179         }
180         if (touchy.indexOf(',') != -1) {
181             throw new NumberFormatException JavaDoc("Number format exception: contains a ,");
182         }
183         this.touchy = touchy;
184     }
185
186     public String JavaDoc getCountry() {
187         return country;
188     }
189
190     public void setCountry(String JavaDoc country) {
191         this.country = country;
192     }
193
194     public String JavaDoc[] getStringArray() {
195         return stringArray;
196     }
197
198     public void setStringArray(String JavaDoc[] stringArray) {
199         this.stringArray = stringArray;
200     }
201
202     public Date JavaDoc getDate() {
203         return date;
204     }
205
206     public void setDate(Date JavaDoc date) {
207         this.date = date;
208     }
209
210     public Float JavaDoc getMyFloat() {
211         return myFloat;
212     }
213
214     public void setMyFloat(Float JavaDoc myFloat) {
215         this.myFloat = myFloat;
216     }
217
218     public Collection JavaDoc getFriends() {
219         return friends;
220     }
221
222     public void setFriends(Collection JavaDoc friends) {
223         this.friends = friends;
224     }
225
226     public Set JavaDoc getSomeSet() {
227         return someSet;
228     }
229
230     public void setSomeSet(Set JavaDoc someSet) {
231         this.someSet = someSet;
232     }
233
234     public Map JavaDoc getSomeMap() {
235         return someMap;
236     }
237
238     public void setSomeMap(Map JavaDoc someMap) {
239         this.someMap = someMap;
240     }
241
242     public List JavaDoc getSomeList() {
243         return someList;
244     }
245
246     public void setSomeList(List JavaDoc someList) {
247         this.someList = someList;
248     }
249
250     public Properties JavaDoc getSomeProperties() {
251         return someProperties;
252     }
253
254     public void setSomeProperties(Properties JavaDoc someProperties) {
255         this.someProperties = someProperties;
256     }
257
258     public INestedTestBean getDoctor() {
259         return doctor;
260     }
261
262     public INestedTestBean getLawyer() {
263         return lawyer;
264     }
265
266     public void setDoctor(INestedTestBean bean) {
267         doctor = bean;
268     }
269
270     public void setLawyer(INestedTestBean bean) {
271         lawyer = bean;
272     }
273
274     public Number JavaDoc getSomeNumber() {
275         return someNumber;
276     }
277
278     public void setSomeNumber(Number JavaDoc someNumber) {
279         this.someNumber = someNumber;
280     }
281
282     public IndexedTestBean getNestedIndexedBean() {
283         return nestedIndexedBean;
284     }
285
286     public void setNestedIndexedBean(IndexedTestBean nestedIndexedBean) {
287         this.nestedIndexedBean = nestedIndexedBean;
288     }
289
290
291     /**
292      * @see ITestBean#exceptional(Throwable)
293      */

294     public void exceptional(Throwable JavaDoc t) throws Throwable JavaDoc {
295         if (t != null) {
296             throw t;
297         }
298     }
299
300     /**
301      * @see ITestBean#returnsThis()
302      */

303     public Object JavaDoc returnsThis() {
304         return this;
305     }
306
307     /**
308      * @see IOther#absquatulate()
309      */

310     public void absquatulate() {
311     }
312
313     public int haveBirthday() {
314         return age++;
315     }
316
317
318     public void destroy() {
319         this.destroyed = true;
320     }
321
322     public boolean wasDestroyed() {
323         return destroyed;
324     }
325
326
327     public boolean equals(Object JavaDoc other) {
328         if (this == other) {
329             return true;
330         }
331         if (other == null || !(other instanceof TestBean)) {
332             return false;
333         }
334         TestBean tb2 = (TestBean) other;
335         return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age);
336     }
337
338     public int hashCode() {
339         return this.age;
340     }
341
342     public int compareTo(Object JavaDoc other) {
343         if (this.name != null && other instanceof TestBean) {
344             return this.name.compareTo(((TestBean) other).getName());
345         }
346         else {
347             return 1;
348         }
349     }
350
351     public String JavaDoc toString() {
352         String JavaDoc s = "name=" + name + "; age=" + age + "; touchy=" + touchy;
353         s += "; spouse={" + (spouse != null ? spouse.getName() : null) + "}";
354         return s;
355     }
356
357 }
358
Popular Tags