001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package com.tctest.spring.bean;
018:
019: import java.util.Collection;
020: import java.util.Date;
021: import java.util.HashMap;
022: import java.util.HashSet;
023: import java.util.LinkedList;
024: import java.util.Map;
025: import java.util.Set;
026: import java.util.List;
027: import java.util.ArrayList;
028: import java.util.Properties;
029:
030: import org.springframework.beans.factory.BeanFactory;
031: import org.springframework.beans.factory.BeanFactoryAware;
032: import org.springframework.beans.factory.BeanNameAware;
033: import org.springframework.util.ObjectUtils;
034:
035: /**
036: * Simple test bean used for testing bean factories,
037: * AOP framework etc.
038: *
039: * @author Rod Johnson
040: * @since 15 April 2001
041: */
042: public class TestBean implements BeanNameAware, BeanFactoryAware,
043: ITestBean, IOther, Comparable {
044:
045: private String beanName;
046:
047: private String country;
048:
049: private BeanFactory beanFactory;
050:
051: private boolean postProcessed;
052:
053: private String name;
054:
055: private String sex;
056:
057: private int age;
058:
059: private boolean jedi;
060:
061: private ITestBean spouse;
062:
063: private String touchy;
064:
065: private String[] stringArray;
066:
067: private Date date = new Date();
068:
069: private Float myFloat = new Float(0.0);
070:
071: private Collection friends = new LinkedList();
072:
073: private Set someSet = new HashSet();
074:
075: private Map someMap = new HashMap();
076:
077: private List someList = new ArrayList();
078:
079: private Properties someProperties = new Properties();
080:
081: private INestedTestBean doctor = new NestedTestBean();
082:
083: private INestedTestBean lawyer = new NestedTestBean();
084:
085: private IndexedTestBean nestedIndexedBean;
086:
087: private boolean destroyed = false;
088:
089: private Number someNumber;
090:
091: public TestBean() {
092: }
093:
094: public TestBean(String name) {
095: this .name = name;
096: }
097:
098: public TestBean(ITestBean spouse) {
099: this .spouse = spouse;
100: }
101:
102: public TestBean(String name, int age) {
103: this .name = name;
104: this .age = age;
105: }
106:
107: public void setBeanName(String beanName) {
108: this .beanName = beanName;
109: }
110:
111: public String getBeanName() {
112: return beanName;
113: }
114:
115: public void setBeanFactory(BeanFactory beanFactory) {
116: this .beanFactory = beanFactory;
117: }
118:
119: public BeanFactory getBeanFactory() {
120: return beanFactory;
121: }
122:
123: public void setPostProcessed(boolean postProcessed) {
124: this .postProcessed = postProcessed;
125: }
126:
127: public boolean isPostProcessed() {
128: return postProcessed;
129: }
130:
131: public String getName() {
132: return name;
133: }
134:
135: public void setName(String name) {
136: this .name = name;
137: }
138:
139: public String getSex() {
140: return sex;
141: }
142:
143: public void setSex(String sex) {
144: this .sex = sex;
145: }
146:
147: public int getAge() {
148: return age;
149: }
150:
151: public void setAge(int age) {
152: this .age = age;
153: }
154:
155: public boolean isJedi() {
156: return jedi;
157: }
158:
159: public void setJedi(boolean jedi) {
160: this .jedi = jedi;
161: }
162:
163: public ITestBean getSpouse() {
164: return spouse;
165: }
166:
167: public void setSpouse(ITestBean spouse) {
168: this .spouse = spouse;
169: }
170:
171: public String getTouchy() {
172: return touchy;
173: }
174:
175: public void setTouchy(String touchy) throws Exception {
176: if (touchy.indexOf('.') != -1) {
177: throw new Exception("Can't contain a .");
178: }
179: if (touchy.indexOf(',') != -1) {
180: throw new NumberFormatException(
181: "Number format exception: contains a ,");
182: }
183: this .touchy = touchy;
184: }
185:
186: public String getCountry() {
187: return country;
188: }
189:
190: public void setCountry(String country) {
191: this .country = country;
192: }
193:
194: public String[] getStringArray() {
195: return stringArray;
196: }
197:
198: public void setStringArray(String[] stringArray) {
199: this .stringArray = stringArray;
200: }
201:
202: public Date getDate() {
203: return date;
204: }
205:
206: public void setDate(Date date) {
207: this .date = date;
208: }
209:
210: public Float getMyFloat() {
211: return myFloat;
212: }
213:
214: public void setMyFloat(Float myFloat) {
215: this .myFloat = myFloat;
216: }
217:
218: public Collection getFriends() {
219: return friends;
220: }
221:
222: public void setFriends(Collection friends) {
223: this .friends = friends;
224: }
225:
226: public Set getSomeSet() {
227: return someSet;
228: }
229:
230: public void setSomeSet(Set someSet) {
231: this .someSet = someSet;
232: }
233:
234: public Map getSomeMap() {
235: return someMap;
236: }
237:
238: public void setSomeMap(Map someMap) {
239: this .someMap = someMap;
240: }
241:
242: public List getSomeList() {
243: return someList;
244: }
245:
246: public void setSomeList(List someList) {
247: this .someList = someList;
248: }
249:
250: public Properties getSomeProperties() {
251: return someProperties;
252: }
253:
254: public void setSomeProperties(Properties 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 getSomeNumber() {
275: return someNumber;
276: }
277:
278: public void setSomeNumber(Number 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: * @see ITestBean#exceptional(Throwable)
292: */
293: public void exceptional(Throwable t) throws Throwable {
294: if (t != null) {
295: throw t;
296: }
297: }
298:
299: /**
300: * @see ITestBean#returnsThis()
301: */
302: public Object returnsThis() {
303: return this ;
304: }
305:
306: /**
307: * @see IOther#absquatulate()
308: */
309: public void absquatulate() {
310: }
311:
312: public int haveBirthday() {
313: return age++;
314: }
315:
316: public void destroy() {
317: this .destroyed = true;
318: }
319:
320: public boolean wasDestroyed() {
321: return destroyed;
322: }
323:
324: public boolean equals(Object other) {
325: if (this == other) {
326: return true;
327: }
328: if (other == null || !(other instanceof TestBean)) {
329: return false;
330: }
331: TestBean tb2 = (TestBean) other;
332: return (ObjectUtils.nullSafeEquals(this .name, tb2.name) && this .age == tb2.age);
333: }
334:
335: public int hashCode() {
336: return this .age;
337: }
338:
339: public int compareTo(Object other) {
340: if (this .name != null && other instanceof TestBean) {
341: return this .name.compareTo(((TestBean) other).getName());
342: } else {
343: return 1;
344: }
345: }
346:
347: public String toString() {
348: String s = "name=" + name + "; age=" + age + "; touchy="
349: + touchy;
350: s += "; spouse={" + (spouse != null ? spouse.getName() : null)
351: + "}";
352: return s;
353: }
354:
355: }
|