| 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 | import javax.persistence.Entity; |
|---|
| 13 | import javax.persistence.FetchType; |
|---|
| 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.XmlIDREF; |
|---|
| 19 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 20 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 21 | import javax.xml.bind.annotation.XmlTransient; |
|---|
| 22 | import javax.xml.bind.annotation.XmlType; |
|---|
| 23 | |
|---|
| 24 | import org.apache.log4j.Logger; |
|---|
| 25 | import org.hibernate.envers.Audited; |
|---|
| 26 | |
|---|
| 27 | import eu.etaxonomy.cdm.model.common.VersionableEntity; |
|---|
| 28 | import eu.etaxonomy.cdm.model.location.Point; |
|---|
| 29 | import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry; |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * This class represents atomized postal addresses. |
|---|
| 33 | * <P> |
|---|
| 34 | * This class corresponds to: <ul> |
|---|
| 35 | * <li> Address according to the TDWG ontology |
|---|
| 36 | * <li> Address according to the TCS |
|---|
| 37 | * <li> Address according to the ABCD schema |
|---|
| 38 | * </ul> |
|---|
| 39 | * |
|---|
| 40 | * @author m.doering |
|---|
| 41 | * @version 1.0 |
|---|
| 42 | * @created 08-Nov-2007 13:06:09 |
|---|
| 43 | */ |
|---|
| 44 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 45 | @XmlType(name = "Address", propOrder = { |
|---|
| 46 | "pobox", |
|---|
| 47 | "street", |
|---|
| 48 | "postcode", |
|---|
| 49 | "locality", |
|---|
| 50 | "region", |
|---|
| 51 | "country", |
|---|
| 52 | "location" |
|---|
| 53 | }) |
|---|
| 54 | @XmlRootElement(name = "Address") |
|---|
| 55 | @Entity |
|---|
| 56 | @Audited |
|---|
| 57 | public class Address extends VersionableEntity implements Cloneable{ |
|---|
| 58 | private static final long serialVersionUID = 682106303069088972L; |
|---|
| 59 | @SuppressWarnings("unused") |
|---|
| 60 | private static final Logger logger = Logger.getLogger(Address.class); |
|---|
| 61 | |
|---|
| 62 | public static Address NewInstance(){ |
|---|
| 63 | return new Address(); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | public static Address NewInstance(WaterbodyOrCountry country, |
|---|
| 67 | String locality, String pobox, String postcode, |
|---|
| 68 | String region, String street, Point location) { |
|---|
| 69 | return new Address(country, locality, location, pobox, postcode, |
|---|
| 70 | region, street); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | private Address(){ |
|---|
| 74 | |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | private Address(WaterbodyOrCountry country, String locality, Point location, |
|---|
| 78 | String pobox, String postcode, String region, String street) { |
|---|
| 79 | super(); |
|---|
| 80 | this.country = country; |
|---|
| 81 | this.locality = locality; |
|---|
| 82 | this.location = location; |
|---|
| 83 | this.pobox = pobox; |
|---|
| 84 | this.postcode = postcode; |
|---|
| 85 | this.region = region; |
|---|
| 86 | this.street = street; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | @XmlElement(name = "POBox") |
|---|
| 90 | private String pobox; |
|---|
| 91 | |
|---|
| 92 | @XmlElement(name = "Street") |
|---|
| 93 | private String street; |
|---|
| 94 | |
|---|
| 95 | @XmlElement(name = "Postcode") |
|---|
| 96 | private String postcode; |
|---|
| 97 | |
|---|
| 98 | @XmlElement(name = "Locality", required = true) |
|---|
| 99 | private String locality; |
|---|
| 100 | |
|---|
| 101 | @XmlElement(name = "Region") |
|---|
| 102 | private String region; |
|---|
| 103 | |
|---|
| 104 | @XmlElement(name = "Country") |
|---|
| 105 | @XmlIDREF |
|---|
| 106 | @XmlSchemaType(name = "IDREF") |
|---|
| 107 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 108 | private WaterbodyOrCountry country; |
|---|
| 109 | |
|---|
| 110 | @XmlElement(name = "Location") |
|---|
| 111 | private Point location; |
|---|
| 112 | |
|---|
| 113 | /** |
|---|
| 114 | * Returns the {@link WaterbodyOrCountry country} involved in <i>this</i> postal address. |
|---|
| 115 | * |
|---|
| 116 | * @return the country |
|---|
| 117 | */ |
|---|
| 118 | public WaterbodyOrCountry getCountry(){ |
|---|
| 119 | return this.country; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | /** |
|---|
| 123 | * @see #getCountry() |
|---|
| 124 | */ |
|---|
| 125 | public void setCountry(WaterbodyOrCountry country){ |
|---|
| 126 | this.country = country; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | /** |
|---|
| 130 | * Returns the geophysical {@link Point location} (coordinates) of <i>this</i> postal address. |
|---|
| 131 | * The location can be useful for instance to visualize the address on a map. |
|---|
| 132 | * |
|---|
| 133 | * @return the point corresponding to <i>this</i> address |
|---|
| 134 | * @see eu.etaxonomy.cdm.model.location.Point |
|---|
| 135 | */ |
|---|
| 136 | @XmlTransient |
|---|
| 137 | public Point getLocation(){ |
|---|
| 138 | return this.location; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | * @see #getLocation() |
|---|
| 143 | */ |
|---|
| 144 | public void setLocation(Point location){ |
|---|
| 145 | this.location = location; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | /** |
|---|
| 149 | * Returns a string corresponding to the post office box |
|---|
| 150 | * involved in <i>this</i> postal address. |
|---|
| 151 | * |
|---|
| 152 | * @return the post office box string |
|---|
| 153 | */ |
|---|
| 154 | public String getPobox(){ |
|---|
| 155 | return this.pobox; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /** |
|---|
| 159 | * @see #getPobox() |
|---|
| 160 | */ |
|---|
| 161 | public void setPobox(String pobox){ |
|---|
| 162 | this.pobox = pobox; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | /** |
|---|
| 166 | * Returns the street name and number involved in <i>this</i> postal address. |
|---|
| 167 | * Street numbers are part of the street string. |
|---|
| 168 | * |
|---|
| 169 | * @return the string composed of street name and number |
|---|
| 170 | */ |
|---|
| 171 | public String getStreet(){ |
|---|
| 172 | return this.street; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | /** |
|---|
| 176 | * @see #getStreet() |
|---|
| 177 | */ |
|---|
| 178 | public void setStreet(String street){ |
|---|
| 179 | this.street = street; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | /** |
|---|
| 183 | * Returns the post code number involved in <i>this</i> postal address. |
|---|
| 184 | * |
|---|
| 185 | * @return the post code number string |
|---|
| 186 | */ |
|---|
| 187 | public String getPostcode(){ |
|---|
| 188 | return this.postcode; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | /** |
|---|
| 192 | * @see #getPostcode() |
|---|
| 193 | */ |
|---|
| 194 | public void setPostcode(String postcode){ |
|---|
| 195 | this.postcode = postcode; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | /** |
|---|
| 199 | * Returns the town (possibly with locality or suburb) involved in <i>this</i> postal address. |
|---|
| 200 | * |
|---|
| 201 | * @return the string representing a town |
|---|
| 202 | */ |
|---|
| 203 | public String getLocality(){ |
|---|
| 204 | return this.locality; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | /** |
|---|
| 208 | * @see #getLocality() |
|---|
| 209 | */ |
|---|
| 210 | public void setLocality(String locality){ |
|---|
| 211 | this.locality = locality; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | /** |
|---|
| 215 | * Returns the region or state involved in <i>this</i> postal address. |
|---|
| 216 | * |
|---|
| 217 | * @return the string representing a region or a state |
|---|
| 218 | */ |
|---|
| 219 | public String getRegion(){ |
|---|
| 220 | return this.region; |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | /** |
|---|
| 224 | * @see #getRegion() |
|---|
| 225 | */ |
|---|
| 226 | public void setRegion(String region){ |
|---|
| 227 | this.region = region; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | //************************ CLONE ************************ // |
|---|
| 231 | /** |
|---|
| 232 | * Clones this Address. |
|---|
| 233 | * Set fields for nextVersion, previousVersion, updated, updatedBy and createdBy are set to <tt>null</tt> |
|---|
| 234 | * The id is set to 0. |
|---|
| 235 | * The uuid is created new. |
|---|
| 236 | * The createdWhen is set to the current date. |
|---|
| 237 | * @see java.lang.Object#clone() |
|---|
| 238 | */ |
|---|
| 239 | @Override |
|---|
| 240 | public Object clone() throws CloneNotSupportedException{ |
|---|
| 241 | Address result = (Address)super.clone(); |
|---|
| 242 | |
|---|
| 243 | //no changes to: - |
|---|
| 244 | return result; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | } |
|---|