(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / agent / Address.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.model.agent;
11
12
13 import javax.persistence.Entity;
14 import javax.persistence.ManyToOne;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
19 import javax.xml.bind.annotation.XmlTransient;
20 import javax.xml.bind.annotation.XmlType;
21
22 import org.apache.log4j.Logger;
23
24 import eu.etaxonomy.cdm.model.common.VersionableEntity;
25 import eu.etaxonomy.cdm.model.location.Point;
26 import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
27
28 /**
29 * Representation of an atomized postal address.
30 * <p>
31 * See also the <a href="http://rs.tdwg.org/ontology/voc/ContactDetails#Address">TDWG Ontology</a>
32 *
33 * @author m.doering
34 * @version 1.0
35 * @created 08-Nov-2007 13:06:09
36 */
37 @XmlAccessorType(XmlAccessType.FIELD)
38 @XmlType(name = "", propOrder = {
39 "pobox",
40 "street",
41 "postcode",
42 "locality",
43 "region",
44 "country",
45 "location",
46 "contact"
47 })
48 @XmlRootElement(name = "Address")
49 @Entity
50 public class Address extends VersionableEntity {
51
52 static Logger logger = Logger.getLogger(Address.class);
53
54 @XmlElement(name = "POBox")
55 private String pobox;
56
57 @XmlElement(name = "Street")
58 private String street;
59
60 @XmlElement(name = "Postcode")
61 private String postcode;
62
63 @XmlElement(name = "Locality", required = true)
64 private String locality;
65
66 @XmlElement(name = "Region")
67 private String region;
68
69 @XmlElement(name = "Country")
70 private WaterbodyOrCountry country;
71
72 @XmlElement(name = "Location")
73 private Point location;
74
75 //Bidirectional only private
76 @XmlElement(name = "Contact")
77 private Contact contact;
78
79
80 /**
81 * Returns the {@link Contact contact} (of a {@link Person person} or of an {@link Institution institution})
82 * to which <i>this</i> address belongs.
83 * Both kinds of agents cannot have more than one contact, but a contact may include
84 * several postal addresses.
85 *
86 * @return the contact <i>this</i> postal address belongs to
87 * @see Contact
88 */
89 @ManyToOne
90 public Contact getContact() {
91 return contact;
92 }
93
94
95 /**
96 * Adds <i>this</i> postal address to the set of addresses of a {@link Contact contact}.
97 * The same address instance cannot be assigned to different persons
98 * or institutions (if they do have the same postal address several
99 * address instances must be created). If <i>this</i> address already belongs to a
100 * contact this method shifts it from this contact to a new one.
101 * Therefore <i>this</i> address will be removed from the set of addresses of the old
102 * contact and added to the set of the new one.
103 *
104 * @param newContact the new contact to which <i>this</i> postal address should belong
105 * @see Contact#addAddress(Address)
106 * @see Contact#removeAddress(Address)
107 */
108 protected void setContact(Contact newContact) {
109 this.contact = newContact;
110 }
111
112
113 /**
114 * Returns the {@link WaterbodyOrCountry country} involved in <i>this</i> postal address.
115 *
116 * @return the country
117 */
118 @ManyToOne
119 public WaterbodyOrCountry getCountry(){
120 return this.country;
121 }
122
123 /**
124 * @see #getCountry()
125 */
126 public void setCountry(WaterbodyOrCountry country){
127 this.country = country;
128 }
129
130 /**
131 * Returns the geophysical {@link Point location} (coordinates) of <i>this</i> postal address.
132 * The location can be useful for instance to visualize the address on a map.
133 *
134 * @return the point corresponding to <i>this</i> address
135 * @see eu.etaxonomy.cdm.model.location.Point
136 */
137 @XmlTransient
138 public Point getLocation(){
139 return this.location;
140 }
141
142 /**
143 * @see #getLocation()
144 */
145 public void setLocation(Point location){
146 this.location = location;
147 }
148
149 /**
150 * Returns a string corresponding to the post office box
151 * involved in <i>this</i> postal address.
152 *
153 * @return the post office box string
154 */
155 public String getPobox(){
156 return this.pobox;
157 }
158
159 /**
160 * @see #getPobox()
161 */
162 public void setPobox(String pobox){
163 this.pobox = pobox;
164 }
165
166 /**
167 * Returns the street name and number involved in <i>this</i> postal address.
168 * Street numbers are part of the street string.
169 *
170 * @return the string composed of street name and number
171 */
172 public String getStreet(){
173 return this.street;
174 }
175
176 /**
177 * @see #getStreet()
178 */
179 public void setStreet(String street){
180 this.street = street;
181 }
182
183 /**
184 * Returns the post code number involved in <i>this</i> postal address.
185 *
186 * @return the post code number string
187 */
188 public String getPostcode(){
189 return this.postcode;
190 }
191
192 /**
193 * @see #getPostcode()
194 */
195 public void setPostcode(String postcode){
196 this.postcode = postcode;
197 }
198
199 /**
200 * Returns the town (possibly with locality or suburb) involved in <i>this</i> postal address.
201 *
202 * @return the string representing a town
203 */
204 public String getLocality(){
205 return this.locality;
206 }
207
208 /**
209 * @see #getLocality()
210 */
211 public void setLocality(String locality){
212 this.locality = locality;
213 }
214
215 /**
216 * Returns the region or state involved in <i>this</i> postal address.
217 *
218 * @return the string representing a region or a state
219 */
220 public String getRegion(){
221 return this.region;
222 }
223
224 /**
225 * @see #getRegion()
226 */
227 public void setRegion(String region){
228 this.region = region;
229 }
230
231 }