package eu.etaxonomy.cdm.model.agent;
-import eu.etaxonomy.cdm.model.common.VersionableEntity;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.Embeddable;
+import javax.persistence.FetchType;
+import javax.persistence.OneToMany;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlType;
+
import org.apache.log4j.Logger;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
-
-import java.util.*;
-import javax.persistence.*;
+import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.envers.Audited;
/**
- * Information on how to contact a {@link Person person} or an {@link Institution institution}.
- * It includes telecommunication data
- * and electronic as well as multiple postal addresses.
- * <p>
- * See also the <a href="http://rs.tdwg.org/ontology/voc/ContactDetails#ContactDetails">TDWG Ontology</a>
+ * The class for information on how to approach a {@link Person person} or an {@link Institution institution}.
+ * It includes telecommunication data and an electronic as well as
+ * multiple postal addresses.
+* <P>
+ * This class corresponds to: <ul>
+ * <li> ContactDetails according to the TDWG ontology
+ * <li> Contact (partially) according to the ABCD schema
+ * </ul>
*
* @author m.doering
* @version 1.0
* @created 08-Nov-2007 13:06:18
*/
-@Entity
-public class Contact extends VersionableEntity {
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Contact", propOrder = {
+ "emailAddresses",
+ "urls",
+ "phoneNumbers",
+ "faxNumbers",
+ "addresses"
+})
+@XmlRootElement(name = "Contact")
+@Embeddable
+@Audited
+public class Contact implements Serializable {
+ private static final long serialVersionUID = -1851305307069277625L;
+ private static final Logger logger = Logger.getLogger(Contact.class);
+
+
/**
* Class constructor.
*/
public Contact() {
super();
- // TODO Auto-generated constructor stub
+ logger.debug("Constructor call");
}
- static Logger logger = Logger.getLogger(Contact.class);
- private String email;
- private String url;
- private String phone;
- private String fax;
- protected Set<Address> addresses;
+ @XmlElementWrapper(name = "EmailAddresses")
+ @XmlElement(name = "EmailAddress")
+ @CollectionOfElements(fetch = FetchType.LAZY)
+ private List<String> emailAddresses = new ArrayList<String>();
+
+ @XmlElementWrapper(name = "URLs")
+ @XmlElement(name = "URL")
+ @XmlSchemaType(name = "anyURI")
+ @CollectionOfElements(fetch = FetchType.LAZY)
+ private List<String> urls = new ArrayList<String>();
+ @XmlElementWrapper(name = "PhoneNumbers")
+ @XmlElement(name = "PhoneNumber")
+ @CollectionOfElements(fetch = FetchType.LAZY)
+ private List<String> phoneNumbers = new ArrayList<String>();
- @OneToMany(mappedBy="contact")
- @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
+ @XmlElementWrapper(name = "FaxNumbers")
+ @XmlElement(name = "FaxNumber")
+ @CollectionOfElements(fetch = FetchType.LAZY)
+ private List<String> faxNumbers = new ArrayList<String>();
+
+ @XmlElementWrapper(name = "Addresses")
+ @XmlElement(name = "Address")
+ @OneToMany(fetch = FetchType.LAZY)
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE_ORPHAN})
+ protected Set<Address> addresses = new HashSet<Address>();
+
+
+ /**
+ * Returns the set of postal {@link Address addresses} belonging to <i>this</i> contact.
+ * A {@link Person person} or an {@link Institution institution} cannot have more than one contact,
+ * but a contact may include several postal addresses.
+ *
+ * @return the set of postal addresses
+ * @see Address
+ */
public Set<Address> getAddresses(){
return this.addresses;
}
- protected void setAddresses(Set<Address> addresses){
- this.addresses = addresses;
- }
+
/**
- * Adds a new postal address to the set of postal addresses of this contact.
+ * Adds a new postal {@link Address address} to the set of postal addresses of <i>this</i> contact.
*
- * @param address the address to be added to the the set of addresses
- * of postal addresses of this contact
+ * @param address the address to be added
+ * @see #getAddresses()
* @see Address
*/
public void addAddress(Address address){
- address.setContact(this);
+ if (address != null){
+ addresses.add(address);
+ }
}
+
/**
- * Removes one element from the set of postal addresses of this contact.
+ * Removes one element from the set of postal addresses of <i>this</i> contact.
*
- * @param address the postal address of this contact which should be deleted
- * @see #addAddress(Address)
+ * @param address the postal address of <i>this</i> contact which should be deleted
+ * @see #getAddresses()
*/
public void removeAddress(Address address){
- address.setContact(null);
+ addresses.remove(address);
}
- public String getEmail(){
- return this.email;
+ /**
+ * Returns the List of strings representing the electronic mail addresses
+ * included in <i>this</i> contact.
+ */
+ public List<String> getEmailAddresses(){
+ return this.emailAddresses;
}
/**
- * Assigns an email address to this contact.
- *
- * @param email string representing an electronic mail address
+ * @see #getEmailAddress()
+ */
+ public void addEmailAddress(String emailAddress){
+ this.emailAddresses.add(emailAddress);
+ }
+
+ /**
+ * Removes one element from the list of email addresses of <i>this</i> contact.
+ *
+ * @param emailAddress the email address of <i>this</i> contact which should be deleted
+ * @see #getEmailAddresses()
*/
- public void setEmail(String email){
- this.email = email;
+ public void removeEmailAddress(String emailAddress){
+ emailAddresses.remove(emailAddress);
}
- public String getUrl(){
- return this.url;
+ /**
+ * Returns the list of strings representing the "Uniform Resource Locators" (urls)
+ * included in <i>this</i> contact.
+ */
+ public List<String> getUrls(){
+ return this.urls;
}
/**
- * Assigns an url address to this contact.
- *
- * @param url string representing an "Uniform Resource Locator"
+ * @see #getUrls()
*/
- public void setUrl(String url){
- this.url = url;
+ public void addUrl(String url){
+ this.urls.add(url);
+ }
+
+ /**
+ * Removes one element from the list of urls of <i>this</i> contact.
+ *
+ * @param url the url of <i>this</i> contact which should be deleted
+ * @see #getUrls()
+ */
+ public void removeUrl(String url){
+ urls.remove(url);
}
- public String getPhone(){
- return this.phone;
+ /**
+ * Returns the list of strings representing the phone numbers
+ * included in <i>this</i> contact.
+ */
+ public List<String> getPhoneNumbers(){
+ return this.phoneNumbers;
}
/**
- * Assigns a phone number to this contact.
- *
- * @param phone string representing a phone number
+ * @see #getPhone()
*/
- public void setPhone(String phone){
- this.phone = phone;
+ public void addPhoneNumber(String phoneNumber){
+ this.phoneNumbers.add(phoneNumber);
+ }
+
+ /**
+ * Removes one element from the list of phone numbers of <i>this</i> contact.
+ *
+ * @param phoneNumber the phone number of <i>this</i> contact which should be deleted
+ * @see #getPhoneNumber()
+ */
+ public void removePhoneNumber(String phoneNumber){
+ phoneNumbers.remove(phoneNumber);
}
- public String getFax(){
- return this.fax;
+ /**
+ * Returns the list of strings representing the telefax numbers
+ * included in <i>this</i> contact.
+ */
+ public List<String> getFaxNumbers(){
+ return this.faxNumbers;
}
/**
- * Assigns a fax number to this contact.
- *
- * @param fax string representing a fax number
+ * @see #getFaxNumbers()
*/
- public void setFax(String fax){
- this.fax = fax;
+ public void addFaxNumber(String faxNumber){
+ this.faxNumbers.add(faxNumber);
}
+ /**
+ * Removes one element from the list of telefax numbers of <i>this</i> contact.
+ *
+ * @param faxNumber the telefax number of <i>this</i> contact which should be deleted
+ * @see #getFaxNumber()
+ */
+ public void removeFaxNumber(String faxNumber){
+ faxNumbers.remove(faxNumber);
+ }
}
\ No newline at end of file