KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > samples > voipservice > to > CustomerTO


1 /*
2  * $Id: CustomerTO.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.samples.voipservice.to;
12
13 import java.io.Serializable JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * @author Binildas Christudas
19  */

20 public class CustomerTO implements Serializable JavaDoc, Cloneable JavaDoc
21 {
22     /**
23      * Serial version
24      */

25     private static final long serialVersionUID = -7760891283901332894L;
26
27     private String JavaDoc firstName;
28     private String JavaDoc lastName;
29     private AddressTO addressTO;
30
31     private static final List JavaDoc CUSTOMERS;
32
33     static
34     {
35         CUSTOMERS = new ArrayList JavaDoc();
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 JavaDoc firstName, String JavaDoc lastName)
55     {
56         this(firstName, lastName, null);
57     }
58
59     public CustomerTO(String JavaDoc firstName, String JavaDoc lastName, AddressTO addressTO)
60     {
61         this.firstName = firstName;
62         this.lastName = lastName;
63         this.addressTO = addressTO;
64     }
65
66     public String JavaDoc getName()
67     {
68
69         String JavaDoc name = firstName;
70         String JavaDoc 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 JavaDoc firstName)
83     {
84         this.firstName = firstName;
85     }
86
87     public String JavaDoc getFirstName()
88     {
89         return firstName;
90     }
91
92     public void setLastName(String JavaDoc lastName)
93     {
94         this.lastName = lastName;
95     }
96
97     public String JavaDoc 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 JavaDoc clone()
113     {
114         Object JavaDoc 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 JavaDoc cloneNotSupportedException)
124         {
125             // too bad
126
}
127         return clone;
128     }
129
130     public String JavaDoc toString()
131     {
132         StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
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 JavaDoc(Math.random() * 10).intValue();
148         // AddressTO addressTO = (AddressTO) ADDRESSES.get(index);
149
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