package eu.etaxonomy.cdm.model.agent;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ManyToOne;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlIDREF;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
-import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
-import eu.etaxonomy.cdm.model.location.Point;
-import eu.etaxonomy.cdm.model.common.VersionableEntity;
import org.apache.log4j.Logger;
-import javax.persistence.*;
+import org.hibernate.envers.Audited;
+
+import eu.etaxonomy.cdm.model.common.VersionableEntity;
+import eu.etaxonomy.cdm.model.location.Point;
+import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
/**
- * Representation of an atomized postal address.
- * <p>
- * See also the <a href="http://rs.tdwg.org/ontology/voc/ContactDetails#Address">TDWG Ontology</a>
+ * This class represents atomized postal addresses.
+ * <P>
+ * This class corresponds to: <ul>
+ * <li> Address according to the TDWG ontology
+ * <li> Address according to the TCS
+ * <li> Address according to the ABCD schema
+ * </ul>
*
* @author m.doering
* @version 1.0
* @created 08-Nov-2007 13:06:09
*/
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Address", propOrder = {
+ "pobox",
+ "street",
+ "postcode",
+ "locality",
+ "region",
+ "country",
+ "location"
+})
+@XmlRootElement(name = "Address")
@Entity
+@Audited
public class Address extends VersionableEntity {
- static Logger logger = Logger.getLogger(Address.class);
+ private static final long serialVersionUID = 682106303069088972L;
+ @SuppressWarnings("unused")
+ private static final Logger logger = Logger.getLogger(Address.class);
+
+ @XmlElement(name = "POBox")
private String pobox;
+
+ @XmlElement(name = "Street")
private String street;
+
+ @XmlElement(name = "Postcode")
private String postcode;
+
+ @XmlElement(name = "Locality", required = true)
private String locality;
+
+ @XmlElement(name = "Region")
private String region;
+
+ @XmlElement(name = "Country")
+ @XmlIDREF
+ @XmlSchemaType(name = "IDREF")
+ @ManyToOne(fetch = FetchType.LAZY)
private WaterbodyOrCountry country;
+
+ @XmlElement(name = "Location")
private Point location;
- //Bidirectional only private
- private Contact contact;
-
-
- /**
- * Returns the {@link Contact contact} (of a {@link Person person} or of an {@link Institution institution})
- * to which this address belongs.
- * Both kinds of agents cannot have more than one contact, but a contact may include
- * several postal addresses.
- *
- * @return the contact this postal address belongs to
- * @see Contact
- */
- @ManyToOne
- public Contact getContact() {
- return contact;
- }
-
-
- /**
- * Adds this postal address to the set of addresses of a {@link Contact contact}.
- * The same address instance cannot be assigned to different persons
- * or institutions (if they do have the same postal address several
- * address instances must be created). If this address already belongs to a
- * contact this method shifts it from this contact to a new one.
- * Therefore this address will be removed from the set of addresses of the old
- * contact and added to the set of the new one.
- *
- * @param newContact the new contact to which this postal address should belong
- * @see Contact#addAddress(Address)
- * @see Contact#removeAddress(Address)
- */
- protected void setContact(Contact newContact) {
- // Hibernate bidirectional cascade hack:
- // http://opensource.atlassian.com/projects/hibernate/browse/HHH-1054
- if(this.contact == newContact) return;
- if (contact != null) {
- contact.addresses.remove(this);
- }
- if (newContact!= null) {
- newContact.addresses.add(this);
- }
- this.contact = newContact;
- }
-
/**
- * Returns the {@link WaterbodyOrCountry country} involved in this postal address.
+ * Returns the {@link WaterbodyOrCountry country} involved in <i>this</i> postal address.
*
* @return the country
*/
- @ManyToOne
public WaterbodyOrCountry getCountry(){
return this.country;
}
}
/**
- * Returns the geophysical location (coordinates) of this postal address.
+ * Returns the geophysical {@link Point location} (coordinates) of <i>this</i> postal address.
+ * The location can be useful for instance to visualize the address on a map.
*
- * @return the point corresponding to this address
+ * @return the point corresponding to <i>this</i> address
* @see eu.etaxonomy.cdm.model.location.Point
*/
+ @XmlTransient
public Point getLocation(){
- //TODO do coordinates make sense for an address?
- logger.warn("do coordinates (point) make sense for an address?");
return this.location;
}
* @see #getLocation()
*/
public void setLocation(Point location){
- //TODO do coordinates make sense for an address?
- logger.warn("do coordinates (point) make sense for an address?");
this.location = location;
}
/**
* Returns a string corresponding to the post office box
- * involved in this postal address.
+ * involved in <i>this</i> postal address.
*
* @return the post office box string
*/
}
/**
- * Returns the street name and number involved in this postal address.
+ * Returns the street name and number involved in <i>this</i> postal address.
* Street numbers are part of the street string.
*
* @return the string composed of street name and number
}
/**
- * Returns the post code number involved in this postal address.
+ * Returns the post code number involved in <i>this</i> postal address.
*
* @return the post code number string
*/
}
/**
- * Returns the town (possibly with locality or suburb) involved in this postal address.
+ * Returns the town (possibly with locality or suburb) involved in <i>this</i> postal address.
*
* @return the string representing a town
*/
}
/**
- * Returns the region or state involved in this postal address.
+ * Returns the region or state involved in <i>this</i> postal address.
*
* @return the string representing a region or a state
*/