View Javadoc

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