1 10 11 package org.mule.samples.voipservice.to; 12 13 import java.io.Serializable ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 20 public class CustomerTO implements Serializable , Cloneable 21 { 22 25 private static final long serialVersionUID = -7760891283901332894L; 26 27 private String firstName; 28 private String lastName; 29 private AddressTO addressTO; 30 31 private static final List CUSTOMERS; 32 33 static 34 { 35 CUSTOMERS = new ArrayList (); 36 37 CUSTOMERS.add(new CustomerTO("Binil", "Das")); 38 CUSTOMERS.add(new CustomerTO("Rajesh", "Warrier")); 39 CUSTOMERS.add(new CustomerTO("Jacob", "Oommen")); 40 CUSTOMERS.add(new CustomerTO("Shahanas", "Mohammed")); 41 CUSTOMERS.add(new CustomerTO("Sowmya", "Hubert")); 42 CUSTOMERS.add(new CustomerTO("Ann", "Binil")); 43 CUSTOMERS.add(new CustomerTO("Rajesh", "Ravindran")); 44 CUSTOMERS.add(new CustomerTO("Renjit", "Hubert")); 45 CUSTOMERS.add(new CustomerTO("Brijesh", "Deb")); 46 CUSTOMERS.add(new CustomerTO("Rama", "Varma")); 47 } 48 49 public CustomerTO() 50 { 51 super(); 52 } 53 54 public CustomerTO(String firstName, String lastName) 55 { 56 this(firstName, lastName, null); 57 } 58 59 public CustomerTO(String firstName, String lastName, AddressTO addressTO) 60 { 61 this.firstName = firstName; 62 this.lastName = lastName; 63 this.addressTO = addressTO; 64 } 65 66 public String getName() 67 { 68 69 String name = firstName; 70 String lastName = null; 71 if (this.lastName == null) 72 { 73 lastName = ""; 74 } 75 else 76 { 77 lastName = this.lastName; 78 } 79 return name + " " + lastName; 80 } 81 82 public void setFirstName(String firstName) 83 { 84 this.firstName = firstName; 85 } 86 87 public String getFirstName() 88 { 89 return firstName; 90 } 91 92 public void setLastName(String lastName) 93 { 94 this.lastName = lastName; 95 } 96 97 public String getLastName() 98 { 99 return lastName; 100 } 101 102 public void setAddress(AddressTO addressTO) 103 { 104 this.addressTO = addressTO; 105 } 106 107 public AddressTO getAddress() 108 { 109 return addressTO; 110 } 111 112 public Object clone() 113 { 114 Object clone = null; 115 try 116 { 117 clone = super.clone(); 118 if (null != addressTO) 119 { 120 ((CustomerTO)clone).setAddress((AddressTO)addressTO.clone()); 121 } 122 } 123 catch (CloneNotSupportedException cloneNotSupportedException) 124 { 125 } 127 return clone; 128 } 129 130 public String toString() 131 { 132 StringBuffer stringBuffer = new StringBuffer (); 133 if (this.firstName != null) 134 { 135 stringBuffer.append("[Name : " + getName() + "] "); 136 } 137 if (this.addressTO != null) 138 { 139 stringBuffer.append("Address -> " + addressTO); 140 } 141 return stringBuffer.toString(); 142 } 143 144 public static CustomerTO getRandomCustomer() 145 { 146 147 int index = new Double (Math.random() * 10).intValue(); 148 CustomerTO customerTO = (CustomerTO)((CustomerTO)CUSTOMERS.get(index)).clone(); 150 if (null == customerTO.getAddress()) 151 { 152 customerTO.setAddress(AddressTO.getRandomAddress()); 153 } 154 return customerTO; 155 } 156 157 } 158 | Popular Tags |