Project

General

Profile

Download (5.8 KB) Statistics
| Branch: | Tag: | Revision:
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
package eu.etaxonomy.cdm.model.agent;
10

    
11
import javax.persistence.Entity;
12
import javax.persistence.FetchType;
13
import javax.persistence.ManyToOne;
14
import javax.xml.bind.annotation.XmlAccessType;
15
import javax.xml.bind.annotation.XmlAccessorType;
16
import javax.xml.bind.annotation.XmlElement;
17
import javax.xml.bind.annotation.XmlIDREF;
18
import javax.xml.bind.annotation.XmlRootElement;
19
import javax.xml.bind.annotation.XmlSchemaType;
20
import javax.xml.bind.annotation.XmlTransient;
21
import javax.xml.bind.annotation.XmlType;
22

    
23
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
24
import org.hibernate.envers.Audited;
25

    
26
import eu.etaxonomy.cdm.model.common.VersionableEntity;
27
import eu.etaxonomy.cdm.model.location.Country;
28
import eu.etaxonomy.cdm.model.location.Point;
29

    
30
/**
31
 * This class represents atomized postal addresses.
32
 * <P>
33
 * This class corresponds to: <ul>
34
 * <li> Address according to the TDWG ontology
35
 * <li> Address according to the TCS
36
 * <li> Address according to the ABCD schema
37
 * </ul>
38
 *
39
 * @author m.doering
40
 * @since 08-Nov-2007 13:06:09
41
 */
42
@XmlAccessorType(XmlAccessType.FIELD)
43
@XmlType(name = "Address", propOrder = {
44
    "pobox",
45
    "street",
46
    "postcode",
47
    "locality",
48
    "region",
49
    "country",
50
    "location"
51
})
52
@XmlRootElement(name = "Address")
53
@Entity
54
@Audited
55
public class Address extends VersionableEntity {
56
	private static final long serialVersionUID = 682106303069088972L;
57
	@SuppressWarnings("unused")
58
	private static final Logger logger = LogManager.getLogger(Address.class);
59

    
60
	public static Address NewInstance(){
61
		return new Address();
62
	}
63

    
64
    public static Address NewInstance(Country country,
65
			String locality, String pobox, String postcode,
66
			String region, String street, Point location) {
67
		return new Address(country, locality, location, pobox, postcode,
68
				region, street);
69
	}
70

    
71
    private Address(){
72

    
73
    }
74

    
75
	private Address(Country country, String locality, Point location,
76
			String pobox, String postcode, String region, String street) {
77
		super();
78
		this.country = country;
79
		this.locality = locality;
80
		this.location = location;
81
		this.pobox = pobox;
82
		this.postcode = postcode;
83
		this.region = region;
84
		this.street = street;
85
	}
86

    
87
	@XmlElement(name = "POBox")
88
	private String pobox;
89

    
90
    @XmlElement(name = "Street")
91
	private String street;
92

    
93
    @XmlElement(name = "Postcode")
94
	private String postcode;
95

    
96
    @XmlElement(name = "Locality", required = true)
97
	private String locality;
98

    
99
    @XmlElement(name = "Region")
100
	private String region;
101

    
102
    @XmlElement(name = "Country")
103
    @XmlIDREF
104
    @XmlSchemaType(name = "IDREF")
105
    @ManyToOne(fetch = FetchType.LAZY)
106
	private Country country;
107

    
108
    @XmlElement(name = "Location")
109
	private Point location;
110

    
111
	/**
112
	 * Returns the {@link Country country} involved in <i>this</i> postal address.
113
	 *
114
	 * @return	the country
115
	 */
116
	public Country getCountry(){
117
		return this.country;
118
	}
119

    
120
	/**
121
	 * @see			   #getCountry()
122
	 */
123
	public void setCountry(Country country){
124
		this.country = country;
125
	}
126

    
127
	/**
128
	 * Returns the geophysical {@link Point location} (coordinates) of <i>this</i> postal address.
129
	 * The location can be useful for instance to visualize the address on a map.
130
	 *
131
	 * @return  the point corresponding to <i>this</i> address
132
	 * @see		eu.etaxonomy.cdm.model.location.Point
133
	 */
134
	@XmlTransient
135
	public Point getLocation(){
136
		return this.location;
137
	}
138

    
139
	/**
140
	 * @see			#getLocation()
141
	 */
142
	public void setLocation(Point location){
143
		this.location = location;
144
	}
145

    
146
	/**
147
	 * Returns a string corresponding to the post office box
148
	 * involved in <i>this</i> postal address.
149
	 *
150
	 * @return	the post office box string
151
	 */
152
	public String getPobox(){
153
		return this.pobox;
154
	}
155

    
156
	/**
157
	 * @see			#getPobox()
158
	 */
159
	public void setPobox(String pobox){
160
		this.pobox = pobox == "" ? null : pobox;
161
	}
162

    
163
	/**
164
	 * Returns the street name and number involved in <i>this</i> postal address.
165
	 * Street numbers are part of the street string.
166
	 *
167
	 * @return	the string composed of street name and number
168
	 */
169
	public String getStreet(){
170
		return this.street;
171
	}
172

    
173
	/**
174
	 * @see			#getStreet()
175
	 */
176
	public void setStreet(String street){
177
		this.street = street == "" ? null : street;
178
	}
179

    
180
	/**
181
	 * Returns the post code number involved in <i>this</i> postal address.
182
	 *
183
	 * @return	the post code number string
184
	 */
185
	public String getPostcode(){
186
		return this.postcode;
187
	}
188

    
189
	/**
190
	 * @see			#getPostcode()
191
	 */
192
	public void setPostcode(String postcode){
193
		this.postcode = postcode == "" ? null : postcode;
194
	}
195

    
196
	/**
197
	 * Returns the town (possibly with locality or suburb) involved in <i>this</i> postal address.
198
	 *
199
	 * @return  the string representing a town
200
	 */
201
	public String getLocality(){
202
		return this.locality;
203
	}
204

    
205
	/**
206
	 * @see			#getLocality()
207
	 */
208
	public void setLocality(String locality){
209
		this.locality = locality == "" ? null: locality;
210
	}
211

    
212
	/**
213
	 * Returns the region or state involved in <i>this</i> postal address.
214
	 *
215
	 * @return  the string representing a region or a state
216
	 */
217
	public String getRegion(){
218
		return this.region;
219
	}
220

    
221
	/**
222
	 * @see			#getRegion()
223
	 */
224
	public void setRegion(String region){
225
		this.region = region == "" ? null: region;
226
	}
227

    
228
//************************ CLONE ************************ //
229
	/**
230
	 * Clones this Address.
231
	 * Set fields for nextVersion, previousVersion, updated, updatedBy and createdBy are set to <tt>null</tt>
232
	 * The id is set to 0.
233
	 * The uuid is created new.
234
	 * The createdWhen is set to the current date.
235
	 * @see java.lang.Object#clone()
236
	 */
237
	@Override
238
	public Address clone() throws CloneNotSupportedException{
239
		Address result = (Address)super.clone();
240

    
241
		//no changes to: -
242
		return result;
243
	}
244
}
(1-1/12)