View Javadoc

1   /*
2    * $Id: AddressTO.java 7963 2007-08-21 08:53:15Z 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  public class AddressTO implements Serializable, Cloneable
20  {
21      /**
22       * Serial version
23       */
24      private static final long serialVersionUID = 6721555269589989794L;
25  
26      private String houseNumber;
27      private String street;
28      private String city;
29  
30      private static final List ADDRESSES;
31  
32      static
33      {
34          ADDRESSES = new ArrayList();
35  
36          ADDRESSES.add(new AddressTO("123", "Koudiar Palace", "Trivandrum"));
37          ADDRESSES.add(new AddressTO("222", "Lake View", "Cochin"));
38          ADDRESSES.add(new AddressTO("345", "Spencer Town", "Chennai"));
39          ADDRESSES.add(new AddressTO("898", "Electronics City", "Bangalore"));
40          ADDRESSES.add(new AddressTO("554", "Kovalam Beach", "Trivandrum"));
41          ADDRESSES.add(new AddressTO("101", "Anzyl Grove", "Pune"));
42          ADDRESSES.add(new AddressTO("369", "Victoria Terminus", "Mumbai"));
43          ADDRESSES.add(new AddressTO("876", "Ponmudi Hills", "Trivandrum"));
44          ADDRESSES.add(new AddressTO("777", "White Field", "Bangalore"));
45          ADDRESSES.add(new AddressTO("908", "Varkala Palms", "Trivandrum"));
46  
47      }
48  
49      public AddressTO()
50      {
51          super();
52      }
53  
54      public AddressTO(String houseNumber, String street, String city)
55      {
56  
57          this.houseNumber = houseNumber;
58          this.street = street;
59          this.city = city;
60      }
61  
62      public void setHouseNumber(String houseNumber)
63      {
64          this.houseNumber = houseNumber;
65      }
66  
67      public String getHouseNumber()
68      {
69          return houseNumber;
70      }
71  
72      public void setStreet(String street)
73      {
74          this.street = street;
75      }
76  
77      public String getStreet()
78      {
79          return street;
80      }
81  
82      public void setCity(String city)
83      {
84          this.city = city;
85      }
86  
87      public String getCity()
88      {
89          return city;
90      }
91  
92      public Object clone()
93      {
94          Object clone = null;
95          try
96          {
97              clone = super.clone();
98          }
99          catch (CloneNotSupportedException cloneNotSupportedException)
100         {
101             // too bad
102         }
103         return clone;
104     }
105 
106     public String toString()
107     {
108         StringBuffer stringBuffer = new StringBuffer();
109         if (this.houseNumber != null)
110         {
111             stringBuffer.append(LocaleMessage.getHouseCaption(houseNumber));
112         }
113         if (this.street != null)
114         {
115             stringBuffer.append(LocaleMessage.getStreetCaption(street));
116         }
117         if (this.city != null)
118         {
119             stringBuffer.append(LocaleMessage.getCityCaption(city));
120         }
121         return stringBuffer.toString();
122     }
123 
124     public static AddressTO getRandomAddress()
125     {
126 
127         int index = new Double(Math.random() * 10).intValue();
128         // AddressTO addressTO = (AddressTO) ADDRESSES.get(index);
129         return (AddressTO)((AddressTO)ADDRESSES.get(index)).clone();
130     }
131 
132 }