3a835aa8793b4031a1bce54b8d0fd68c84f500ca
[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 eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
14 import eu.etaxonomy.cdm.model.location.Point;
15 import eu.etaxonomy.cdm.model.common.VersionableEntity;
16 import org.apache.log4j.Logger;
17 import javax.persistence.*;
18
19 /**
20 * Representation of an atomized postal address.
21 * <p>
22 * See also the <a href="http://rs.tdwg.org/ontology/voc/ContactDetails#Address">TDWG Ontology</a>
23 *
24 * @author m.doering
25 * @version 1.0
26 * @created 08-Nov-2007 13:06:09
27 */
28 @Entity
29 public class Address extends VersionableEntity {
30 static Logger logger = Logger.getLogger(Address.class);
31 private String pobox;
32 private String street;
33 private String postcode;
34 private String locality;
35 private String region;
36 private WaterbodyOrCountry country;
37 private Point location;
38 //Bidirectional only private
39 private Contact contact;
40
41
42 /**
43 * Returns the {@link Contact contact} (of a {@link Person person} or of an {@link Institution institution})
44 * to which this address belongs.
45 * Both kinds of agents cannot have more than one contact, but a contact may include
46 * several postal addresses.
47 *
48 * @return the contact this postal address belongs to
49 * @see Contact
50 */
51 @ManyToOne
52 public Contact getContact() {
53 return contact;
54 }
55
56
57 /**
58 * Adds this postal address to the set of addresses of a {@link Contact contact}.
59 * The same address instance cannot be assigned to different persons
60 * or institutions (if they do have the same postal address several
61 * address instances must be created). If this address already belongs to a
62 * contact this method shifts it from this contact to a new one.
63 * Therefore this address will be removed from the set of addresses of the old
64 * contact and added to the set of the new one.
65 *
66 * @param newContact the new contact to which this postal address should belong
67 * @see Contact#addAddress(Address)
68 * @see Contact#removeAddress(Address)
69 */
70 protected void setContact(Contact newContact) {
71 // Hibernate bidirectional cascade hack:
72 // http://opensource.atlassian.com/projects/hibernate/browse/HHH-1054
73 if(this.contact == newContact) return;
74 if (contact != null) {
75 contact.addresses.remove(this);
76 }
77 if (newContact!= null) {
78 newContact.addresses.add(this);
79 }
80 this.contact = newContact;
81 }
82
83
84 /**
85 * Returns the {@link WaterbodyOrCountry country} involved in this postal address.
86 *
87 * @return the country
88 */
89 @ManyToOne
90 public WaterbodyOrCountry getCountry(){
91 return this.country;
92 }
93
94 /**
95 * @see #getCountry()
96 */
97 public void setCountry(WaterbodyOrCountry country){
98 this.country = country;
99 }
100
101 /**
102 * Returns the geophysical {@link Point location} (coordinates) of this postal address.
103 * The location can be useful for instance to visualize the address on a map.
104 *
105 * @return the point corresponding to this address
106 * @see eu.etaxonomy.cdm.model.location.Point
107 */
108 public Point getLocation(){
109 return this.location;
110 }
111
112 /**
113 * @see #getLocation()
114 */
115 public void setLocation(Point location){
116 this.location = location;
117 }
118
119 /**
120 * Returns a string corresponding to the post office box
121 * involved in this postal address.
122 *
123 * @return the post office box string
124 */
125 public String getPobox(){
126 return this.pobox;
127 }
128
129 /**
130 * @see #getPobox()
131 */
132 public void setPobox(String pobox){
133 this.pobox = pobox;
134 }
135
136 /**
137 * Returns the street name and number involved in this postal address.
138 * Street numbers are part of the street string.
139 *
140 * @return the string composed of street name and number
141 */
142 public String getStreet(){
143 return this.street;
144 }
145
146 /**
147 * @see #getStreet()
148 */
149 public void setStreet(String street){
150 this.street = street;
151 }
152
153 /**
154 * Returns the post code number involved in this postal address.
155 *
156 * @return the post code number string
157 */
158 public String getPostcode(){
159 return this.postcode;
160 }
161
162 /**
163 * @see #getPostcode()
164 */
165 public void setPostcode(String postcode){
166 this.postcode = postcode;
167 }
168
169 /**
170 * Returns the town (possibly with locality or suburb) involved in this postal address.
171 *
172 * @return the string representing a town
173 */
174 public String getLocality(){
175 return this.locality;
176 }
177
178 /**
179 * @see #getLocality()
180 */
181 public void setLocality(String locality){
182 this.locality = locality;
183 }
184
185 /**
186 * Returns the region or state involved in this postal address.
187 *
188 * @return the string representing a region or a state
189 */
190 public String getRegion(){
191 return this.region;
192 }
193
194 /**
195 * @see #getRegion()
196 */
197 public void setRegion(String region){
198 this.region = region;
199 }
200
201 }