1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.logicblaze.lingo.beans;
22
23 import java.util.Collection;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.LinkedList;
28 import java.util.Map;
29 import java.util.Set;
30
31 import org.springframework.beans.factory.BeanFactory;
32 import org.springframework.beans.factory.BeanFactoryAware;
33 import org.logicblaze.lingo.beans.ITestBean;
34 import org.logicblaze.lingo.beans.IndexedTestBean;
35 import org.logicblaze.lingo.beans.INestedTestBean;
36 import org.logicblaze.lingo.beans.IOther;
37 import org.logicblaze.lingo.beans.ITestBean;
38
39 /***
40 * Simple test bean used for testing bean factories,
41 * AOP framework etc.
42 * @author Rod Johnson
43 * @since 15 April 2001
44 */
45 public class TestBean implements BeanFactoryAware, ITestBean, IOther, Comparable {
46
47 private BeanFactory beanFactory;
48
49 private boolean postProcessed;
50
51 private String name;
52
53 private int age;
54
55 private ITestBean spouse;
56
57 private String touchy;
58
59 private String[] stringArray;
60
61 private Date date = new Date();
62
63 private Float myFloat = new Float(0.0);
64
65 private Collection friends = new LinkedList();
66
67 private Set someSet = new HashSet();
68
69 private Map someMap = new HashMap();
70
71 private INestedTestBean doctor = new NestedTestBean();
72
73 private INestedTestBean lawyer = new NestedTestBean();
74
75 private IndexedTestBean nestedIndexedBean;
76
77
78 public TestBean() {
79 }
80
81 public TestBean(String name, int age) {
82 this.name = name;
83 this.age = age;
84 }
85
86
87 public void setBeanFactory(BeanFactory beanFactory) {
88 this.beanFactory = beanFactory;
89 }
90
91 public BeanFactory getBeanFactory() {
92 return beanFactory;
93 }
94
95 public void setPostProcessed(boolean postProcessed) {
96 this.postProcessed = postProcessed;
97 }
98
99 public boolean isPostProcessed() {
100 return postProcessed;
101 }
102
103 public String getName() {
104 System.out.println("### getting name: " + name + " for: " + this);
105 return name;
106 }
107
108 public void setName(String name) {
109 this.name = name;
110 }
111
112 public int getAge() {
113 System.out.println("### getting age: " + age + " for: " + this);
114 return age;
115 }
116
117 public void setAge(int age) {
118 System.out.println("### setting age to: " + age + " for: " + this);
119 this.age = age;
120 }
121
122 public ITestBean getSpouse() {
123 return spouse;
124 }
125
126 public void setSpouse(ITestBean spouse) {
127 this.spouse = spouse;
128 }
129
130 public String getTouchy() {
131 return touchy;
132 }
133
134 public void setTouchy(String touchy) throws Exception {
135 if (touchy.indexOf('.') != -1) {
136 throw new Exception("Can't contain a .");
137 }
138 if (touchy.indexOf(',') != -1) {
139 throw new NumberFormatException("Number format exception: contains a ,");
140 }
141 this.touchy = touchy;
142 }
143
144 public String[] getStringArray() {
145 return stringArray;
146 }
147
148 public void setStringArray(String[] stringArray) {
149 this.stringArray = stringArray;
150 }
151
152 public Date getDate() {
153 return date;
154 }
155
156 public void setDate(Date date) {
157 this.date = date;
158 }
159
160 public Float getMyFloat() {
161 return myFloat;
162 }
163
164 public void setMyFloat(Float myFloat) {
165 this.myFloat = myFloat;
166 }
167
168 public Collection getFriends() {
169 return friends;
170 }
171
172 public void setFriends(Collection friends) {
173 this.friends = friends;
174 }
175
176 public Set getSomeSet() {
177 return someSet;
178 }
179
180 public void setSomeSet(Set someSet) {
181 this.someSet = someSet;
182 }
183
184 public Map getSomeMap() {
185 return someMap;
186 }
187
188 public void setSomeMap(Map someMap) {
189 this.someMap = someMap;
190 }
191
192 public INestedTestBean getDoctor() {
193 return doctor;
194 }
195
196 public INestedTestBean getLawyer() {
197 return lawyer;
198 }
199
200 public void setDoctor(INestedTestBean bean) {
201 doctor = bean;
202 }
203
204 public void setLawyer(INestedTestBean bean) {
205 lawyer = bean;
206 }
207
208 public IndexedTestBean getNestedIndexedBean() {
209 return nestedIndexedBean;
210 }
211
212 public void setNestedIndexedBean(IndexedTestBean nestedIndexedBean) {
213 this.nestedIndexedBean = nestedIndexedBean;
214 }
215
216
217 /***
218 * @see org.logicblaze.lingo.beans.ITestBean#exceptional(Throwable)
219 */
220 public void exceptional(Throwable t) throws Throwable {
221 if (t != null)
222 throw t;
223 }
224
225 /***
226 * @see org.logicblaze.lingo.beans.ITestBean#returnsThis()
227 */
228 public Object returnsThis() {
229 return this;
230 }
231
232 /***
233 * @see IOther#absquatulate()
234 */
235 public void absquatulate() {
236 }
237
238 public int haveBirthday() {
239 return age++;
240 }
241
242
243 public boolean equals(Object other) {
244 if (this == other)
245 return true;
246
247 if (other == null || !(other instanceof TestBean))
248 return false;
249
250 TestBean tb2 = (TestBean) other;
251 if (tb2.age != age)
252 return false;
253
254 if (name == null)
255 return tb2.name == null;
256
257 if (!tb2.name.equals(name))
258 return false;
259
260 return true;
261 }
262
263 public int compareTo(Object other) {
264 if (this.name != null && other instanceof TestBean) {
265 return this.name.compareTo(((TestBean) other).getName());
266 }
267 else {
268 return 1;
269 }
270 }
271
272 public String toString() {
273 String s = "name=" + name + "; age=" + age + "; touchy=" + touchy;
274 s += "; spouse={" + (spouse != null ? spouse.getName() : null) + "}";
275 return s;
276 }
277
278 }