KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > addressbook > address > AddressDO


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: AddressDO.java,v $
31  * Revision 1.4 2005/04/30 13:00:25 colinmacleod
32  * Added getId override for one-to-one relationship.
33  *
34  * Revision 1.3 2005/04/10 20:09:34 colinmacleod
35  * Added new themes.
36  * Changed id type to String.
37  * Changed i tag to em and b tag to strong.
38  * Improved PicoContainerFactory with NanoContainer scripts.
39  *
40  * Revision 1.2 2005/04/09 17:19:06 colinmacleod
41  * Changed copyright text to GPL v2 explicitly.
42  *
43  * Revision 1.1.1.1 2005/03/10 17:50:22 colinmacleod
44  * Restructured ivata op around Hibernate/PicoContainer.
45  * Renamed ivata groupware.
46  *
47  * Revision 1.3 2004/11/12 15:57:04 colinmacleod
48  * Removed dependencies on SSLEXT.
49  * Moved Persistence classes to ivata masks.
50  *
51  * Revision 1.2 2004/11/03 15:34:05 colinmacleod
52  * Changed relationship between person and address:
53  * each person for now has exactly one address.
54  *
55  * Revision 1.1 2004/07/13 19:41:13 colinmacleod
56  * Moved project to POJOs from EJBs.
57  * Applied PicoContainer to services layer (replacing session EJBs).
58  * Applied Hibernate to persistence layer (replacing entity EJBs).
59  * -----------------------------------------------------------------------------
60  */

61 package com.ivata.groupware.business.addressbook.address;
62
63 import com.ivata.groupware.business.addressbook.address.country.CountryDO;
64 import com.ivata.groupware.business.addressbook.person.PersonDO;
65 import com.ivata.groupware.container.persistence.BaseDO;
66
67 /**
68  * <p>Represents a street address within the system. The current model will allow
69  * each person to have multiple street addresses, though the JSP front-end is
70  * currently restricted to just one.</p>
71  *
72  * @author Colin MacLeod
73  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
74  * @since 2002-05-15
75  * @version $Revision: 1.4 $
76  *
77  * @hibernate.class
78  * table="address"
79  * @hibernate.cache
80  * usage="read-write"
81  */

82 public class AddressDO extends BaseDO {
83     /**
84      * <p>
85      * Used to separate all the values in the display value.
86      * </p>
87      */

88     private final static String JavaDoc DISPLAY_VALUE_SEPERATOR = ", ";
89     /**
90      * Country this address is in.
91      */

92     private CountryDO country;
93     /**
94      * <p>
95      * In this version of ivata groupware, each address is associated with a single
96      * person.
97      * </p>
98      */

99     private PersonDO person;
100     /**
101      * Zipcode or postcode. Can be aphanumeric in some countries (UK/CA).
102      */

103     private String JavaDoc postCode;
104     /**
105      * <p>
106      * State or county/region within country.
107      * </p>
108      */

109     private String JavaDoc region;
110     /**
111      * <p>
112      * House name/house number, street and district.
113      * </p>
114      */

115     private String JavaDoc streetAddress;
116     /**
117      * <p>
118      * Town or city.
119      * </p>
120      */

121     private String JavaDoc town;
122
123     /**
124      * <p>
125      * Get the country of an address.
126      * </p>
127      *
128      * @return country for this address bean.
129      * @hibernate.many-to-one
130      * column="address_country"
131      */

132     public final CountryDO getCountry() {
133         return country;
134     }
135
136     /**
137      * <p>
138      * For this class, shows the whole address.
139      * </p>
140      *
141      * @see com.ivata.mask.valueobject.ValueObject#getDisplayValue()
142      */

143     public final String JavaDoc getDisplayValue() {
144         StringBuffer JavaDoc displayValue = new StringBuffer JavaDoc();
145         if (streetAddress != null) {
146             displayValue.append(streetAddress);
147         }
148         if (town != null) {
149             if (displayValue.length() > 0) {
150                 displayValue.append(DISPLAY_VALUE_SEPERATOR);
151             }
152             displayValue.append(town);
153         }
154         if (postCode != null) {
155             if (displayValue.length() > 0) {
156                 displayValue.append(DISPLAY_VALUE_SEPERATOR);
157             }
158             displayValue.append(postCode);
159         }
160         if (region != null) {
161             if (displayValue.length() > 0) {
162                 displayValue.append(DISPLAY_VALUE_SEPERATOR);
163             }
164             displayValue.append(region);
165         }
166         if (country != null) {
167             if (displayValue.length() > 0) {
168                 displayValue.append(DISPLAY_VALUE_SEPERATOR);
169             }
170             displayValue.append(country.getDisplayValue());
171         }
172         return displayValue.toString();
173     }
174     /**
175      * @return Returns the person.
176      * @hibernate.one-to-one
177      */

178     public PersonDO getPerson() {
179         return person;
180     }
181
182     /**
183      * <p>
184      * Get the zipcode or postcode. Can be aphanumeric in some countries (UK/CA).
185      * </p>
186      *
187      * @return zipcode or postcode. Can be aphanumeric in some countries
188      * (UK/CA).
189      * @hibernate.property
190      * column="post_code"
191      */

192     public final String JavaDoc getPostCode() {
193         return postCode;
194     }
195
196     /**
197      * <p>
198      * Get the state or county/region within country.
199      * </p>
200      *
201      * @return state or county/region within country.
202      * @hibernate.property
203      */

204     public final String JavaDoc getRegion() {
205         return region;
206     }
207     /**
208      * <p>Get the house name/house number, street and district.</p>
209      *
210      * @return the house name/house number, street and district.
211      * @hibernate.property
212      * column="street_address"
213      */

214     public final String JavaDoc getStreetAddress() {
215         return streetAddress;
216     }
217     /**
218      * <p>Get the town or city.</p>
219      *
220      * @return the town or city.
221      * @hibernate.property
222      */

223     public final String JavaDoc getTown() {
224         return town;
225     }
226
227     /**
228      * <p>Set the country of an address.</p>
229      *
230      * @param country the new country for this address bean.
231      */

232     public final void setCountry(final CountryDO country) {
233         this.country = country;
234     }
235     /**
236      * @param person The person to set.
237      */

238     public final void setPerson(final PersonDO person) {
239         this.person = person;
240     }
241
242     /**
243      * <p>Set the zipcode or postcode. Can be aphanumeric in some countries
244      * (UK/CA).</p>
245      *
246      * @param postCode zipcode or postcode. Can be aphanumeric in some countries
247      * (UK/CA).
248      */

249     public final void setPostCode(final String JavaDoc postCode) {
250         this.postCode = postCode;
251     }
252
253     /**
254      * <p>Set the state or county/region within country.</p>
255      *
256      * @param region state or county/region within country.
257      */

258     public final void setRegion(final String JavaDoc region) {
259         this.region = region;
260     }
261
262     /**
263      * <p>Set the house name/house number, street and district.</p>
264      *
265      * @param streetAddress house name/house number, street and district.
266      */

267     public final void setStreetAddress(final String JavaDoc streetAddress) {
268         this.streetAddress = streetAddress;
269     }
270     /**
271      * <p>Set the town or city.</p>
272      *
273      * @param town or city.
274      */

275     public final void setTown(final String JavaDoc town) {
276         this.town = town;
277     }
278     /**
279      * Overridden to set the id type.
280      * @see com.ivata.groupware.container.persistence.BaseDO#getId()
281      * @return current identifier.
282      * @hibernate.id
283      * generator-class="foreign"
284      * @hibernate.generator-param
285      * name="property"
286      * value="person"
287      */

288     public Integer JavaDoc getId() {
289         return super.getId();
290     }
291 }
292
Popular Tags