1 4 5 20 21 package org.springframework.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.springframework.beans.factory.BeanNameAware; 34 import org.springframework.util.ObjectUtils; 35 36 43 public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable { 44 45 private String beanName; 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 private boolean destroyed = false; 78 79 private Number someNumber; 80 81 82 public TestBean() { 83 } 84 85 public TestBean(String name, int age) { 86 this.name = name; 87 this.age = age; 88 } 89 90 91 public void setBeanName(String beanName) { 92 this.beanName = beanName; 93 } 94 95 public String getBeanName() { 96 return beanName; 97 } 98 99 public void setBeanFactory(BeanFactory beanFactory) { 100 this.beanFactory = beanFactory; 101 } 102 103 public BeanFactory getBeanFactory() { 104 return beanFactory; 105 } 106 107 public void setPostProcessed(boolean postProcessed) { 108 this.postProcessed = postProcessed; 109 } 110 111 public boolean isPostProcessed() { 112 return postProcessed; 113 } 114 115 public String getName() { 116 return name; 117 } 118 119 public void setName(String name) { 120 this.name = name; 121 } 122 123 public int getAge() { 124 return age; 125 } 126 127 public void setAge(int age) { 128 this.age = age; 129 } 130 131 public ITestBean getSpouse() { 132 return spouse; 133 } 134 135 public void setSpouse(ITestBean spouse) { 136 this.spouse = spouse; 137 } 138 139 public String getTouchy() { 140 return touchy; 141 } 142 143 public void setTouchy(String touchy) throws Exception { 144 if (touchy.indexOf('.') != -1) { 145 throw new Exception ("Can't contain a ."); 146 } 147 if (touchy.indexOf(',') != -1) { 148 throw new NumberFormatException ("Number format exception: contains a ,"); 149 } 150 this.touchy = touchy; 151 } 152 153 public String [] getStringArray() { 154 return stringArray; 155 } 156 157 public void setStringArray(String [] stringArray) { 158 this.stringArray = stringArray; 159 } 160 161 public Date getDate() { 162 return date; 163 } 164 165 public void setDate(Date date) { 166 this.date = date; 167 } 168 169 public Float getMyFloat() { 170 return myFloat; 171 } 172 173 public void setMyFloat(Float myFloat) { 174 this.myFloat = myFloat; 175 } 176 177 public Collection getFriends() { 178 return friends; 179 } 180 181 public void setFriends(Collection friends) { 182 this.friends = friends; 183 } 184 185 public Set getSomeSet() { 186 return someSet; 187 } 188 189 public void setSomeSet(Set someSet) { 190 this.someSet = someSet; 191 } 192 193 public Map getSomeMap() { 194 return someMap; 195 } 196 197 public void setSomeMap(Map someMap) { 198 this.someMap = someMap; 199 } 200 201 public INestedTestBean getDoctor() { 202 return doctor; 203 } 204 205 public INestedTestBean getLawyer() { 206 return lawyer; 207 } 208 209 public void setDoctor(INestedTestBean bean) { 210 doctor = bean; 211 } 212 213 public void setLawyer(INestedTestBean bean) { 214 lawyer = bean; 215 } 216 217 public Number getSomeNumber() { 218 return someNumber; 219 } 220 221 public void setSomeNumber(Number someNumber) { 222 this.someNumber = someNumber; 223 } 224 225 public IndexedTestBean getNestedIndexedBean() { 226 return nestedIndexedBean; 227 } 228 229 public void setNestedIndexedBean(IndexedTestBean nestedIndexedBean) { 230 this.nestedIndexedBean = nestedIndexedBean; 231 } 232 233 234 237 public void exceptional(Throwable t) throws Throwable { 238 if (t != null) { 239 throw t; 240 } 241 } 242 243 246 public Object returnsThis() { 247 return this; 248 } 249 250 253 public void absquatulate() { 254 } 255 256 public int haveBirthday() { 257 return age++; 258 } 259 260 261 public void destroy() { 262 this.destroyed = true; 263 } 264 265 public boolean wasDestroyed() { 266 return destroyed; 267 } 268 269 270 public boolean equals(Object other) { 271 if (this == other) { 272 return true; 273 } 274 if (other == null || !(other instanceof TestBean)) { 275 return false; 276 } 277 TestBean tb2 = (TestBean) other; 278 return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age); 279 } 280 281 public int hashCode() { 282 return this.age; 283 } 284 285 public int compareTo(Object other) { 286 if (this.name != null && other instanceof TestBean) { 287 return this.name.compareTo(((TestBean) other).getName()); 288 } 289 else { 290 return 1; 291 } 292 } 293 294 public String toString() { 295 String s = "name=" + name + "; age=" + age + "; touchy=" + touchy; 296 s += "; spouse={" + (spouse != null ? spouse.getName() : null) + "}"; 297 return s; 298 } 299 300 } 301 | Popular Tags |