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