1 16 17 package com.tctest.spring.bean; 18 19 import java.util.Collection ; 20 import java.util.Date ; 21 import java.util.HashMap ; 22 import java.util.HashSet ; 23 import java.util.LinkedList ; 24 import java.util.Map ; 25 import java.util.Set ; 26 import java.util.List ; 27 import java.util.ArrayList ; 28 import java.util.Properties ; 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 43 public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable { 44 45 private String beanName; 46 47 private String country; 48 49 private BeanFactory beanFactory; 50 51 private boolean postProcessed; 52 53 private String name; 54 55 private String sex; 56 57 private int age; 58 59 private boolean jedi; 60 61 private ITestBean spouse; 62 63 private String touchy; 64 65 private String [] stringArray; 66 67 private Date date = new Date (); 68 69 private Float myFloat = new Float (0.0); 70 71 private Collection friends = new LinkedList (); 72 73 private Set someSet = new HashSet (); 74 75 private Map someMap = new HashMap (); 76 77 private List someList = new ArrayList (); 78 79 private Properties someProperties = new Properties (); 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 someNumber; 90 91 92 public TestBean() { 93 } 94 95 public TestBean(String name) { 96 this.name = name; 97 } 98 99 public TestBean(ITestBean spouse) { 100 this.spouse = spouse; 101 } 102 103 public TestBean(String name, int age) { 104 this.name = name; 105 this.age = age; 106 } 107 108 public void setBeanName(String beanName) { 109 this.beanName = beanName; 110 } 111 112 public String 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 getName() { 133 return name; 134 } 135 136 public void setName(String name) { 137 this.name = name; 138 } 139 140 public String getSex() { 141 return sex; 142 } 143 144 public void setSex(String 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 getTouchy() { 173 return touchy; 174 } 175 176 public void setTouchy(String touchy) throws Exception { 177 if (touchy.indexOf('.') != -1) { 178 throw new Exception ("Can't contain a ."); 179 } 180 if (touchy.indexOf(',') != -1) { 181 throw new NumberFormatException ("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 294 public void exceptional(Throwable t) throws Throwable { 295 if (t != null) { 296 throw t; 297 } 298 } 299 300 303 public Object returnsThis() { 304 return this; 305 } 306 307 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 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 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 toString() { 352 String s = "name=" + name + "; age=" + age + "; touchy=" + touchy; 353 s += "; spouse={" + (spouse != null ? spouse.getName() : null) + "}"; 354 return s; 355 } 356 357 } 358 | Popular Tags |