(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / agent / Contact.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 import eu.etaxonomy.cdm.model.common.VersionableEntity;
13 import org.apache.log4j.Logger;
14 import org.hibernate.annotations.Cascade;
15 import org.hibernate.annotations.CascadeType;
16
17 import java.util.*;
18 import javax.persistence.*;
19 import javax.xml.bind.annotation.XmlAccessType;
20 import javax.xml.bind.annotation.XmlAccessorType;
21 import javax.xml.bind.annotation.XmlElement;
22 import javax.xml.bind.annotation.XmlElementWrapper;
23 import javax.xml.bind.annotation.XmlRootElement;
24 import javax.xml.bind.annotation.XmlSchemaType;
25 import javax.xml.bind.annotation.XmlType;
26
27 /**
28 * Information on how to approach a {@link Person person} or an {@link Institution institution}.
29 * It includes telecommunication data
30 * and electronic as well as multiple postal addresses.
31 * <p>
32 * See also the <a href="http://rs.tdwg.org/ontology/voc/ContactDetails#ContactDetails">TDWG Ontology</a>
33 *
34 * @author m.doering
35 * @version 1.0
36 * @created 08-Nov-2007 13:06:18
37 */
38 @XmlAccessorType(XmlAccessType.FIELD)
39 @XmlType(name = "", propOrder = {
40 "email",
41 "url",
42 "phone",
43 "fax",
44 "addresses"
45 })
46 @XmlRootElement(name = "Contact")
47 @Entity
48 public class Contact extends VersionableEntity {
49 /**
50 * Class constructor.
51 */
52 public Contact() {
53 super();
54 // TODO Auto-generated constructor stub
55 }
56
57 static Logger logger = Logger.getLogger(Contact.class);
58
59 @XmlElement(name = "EmailAddress")
60 private String email;
61
62 @XmlElement(name = "URL")
63 @XmlSchemaType(name = "anyURI")
64 private String url;
65
66 @XmlElement(name = "PhoneNumber")
67 private String phone;
68
69 @XmlElement(name = "FaxNumber")
70 private String fax;
71
72 @XmlElementWrapper(name = "Addresses")
73 @XmlElement(name = "Address")
74 protected Set<Address> addresses;
75
76
77 /**
78 * Returns the set of postal {@link Address addresses} belonging to <i>this</i> contact.
79 * A {@link Person person} or an {@link Institution institution} cannot have more than one contact,
80 * but a contact may include several postal addresses.
81 *
82 * @return the set of postal addresses
83 * @see Address
84 */
85 @OneToMany(mappedBy="contact")
86 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
87 public Set<Address> getAddresses(){
88 return this.addresses;
89 }
90 /**
91 * @see #getAddresses()
92 */
93 protected void setAddresses(Set<Address> addresses){
94 this.addresses = addresses;
95 }
96 /**
97 * Adds a new postal {@link Address address} to the set of postal addresses of <i>this</i> contact.
98 *
99 * @param address the address to be added
100 * @see #getAddresses()
101 * @see Address
102 */
103 public void addAddress(Address address){
104 if (address != null){
105 address.setContact(this);
106 addresses.add(address);
107 }
108 }
109 /**
110 * Removes one element from the set of postal addresses of <i>this</i> contact.
111 *
112 * @param address the postal address of <i>this</i> contact which should be deleted
113 * @see #getAddresses()
114 */
115 public void removeAddress(Address address){
116 address.setContact(null);
117 }
118
119
120 /**
121 * Returns the string representing the electronic mail address
122 * included in <i>this</i> contact.
123 */
124 public String getEmail(){
125 return this.email;
126 }
127
128 /**
129 * @see #getEmail()
130 */
131 public void setEmail(String email){
132 this.email = email;
133 }
134
135 /**
136 * Returns the string representing the "Uniform Resource Locator" (url)
137 * included in <i>this</i> contact.
138 */
139 public String getUrl(){
140 return this.url;
141 }
142
143 /**
144 * @see #getUrl()
145 */
146 public void setUrl(String url){
147 this.url = url;
148 }
149
150 /**
151 * Returns the string representing the phone number
152 * included in <i>this</i> contact.
153 */
154 public String getPhone(){
155 return this.phone;
156 }
157
158 /**
159 * @see #getPhone()
160 */
161 public void setPhone(String phone){
162 this.phone = phone;
163 }
164
165 /**
166 * Returns the string representing the telefax number
167 * included in <i>this</i> contact.
168 */
169 public String getFax(){
170 return this.fax;
171 }
172
173 /**
174 * @see #getFax()
175 */
176 public void setFax(String fax){
177 this.fax = fax;
178 }
179
180 }