(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
20 /**
21 * Information on how to approach a {@link Person person} or an {@link Institution institution}.
22 * It includes telecommunication data
23 * and electronic as well as multiple postal addresses.
24 * <p>
25 * See also the <a href="http://rs.tdwg.org/ontology/voc/ContactDetails#ContactDetails">TDWG Ontology</a>
26 *
27 * @author m.doering
28 * @version 1.0
29 * @created 08-Nov-2007 13:06:18
30 */
31 @Entity
32 public class Contact extends VersionableEntity {
33 /**
34 * Class constructor.
35 */
36 public Contact() {
37 super();
38 // TODO Auto-generated constructor stub
39 }
40
41 static Logger logger = Logger.getLogger(Contact.class);
42 private String email;
43 private String url;
44 private String phone;
45 private String fax;
46 protected Set<Address> addresses;
47
48
49 /**
50 * Returns the set of postal {@link Address addresses} belonging to this contact.
51 * A {@link Person person} or an {@link Institution institution} cannot have more than one contact,
52 * but a contact may include several postal addresses.
53 *
54 * @return the set of postal addresses
55 * @see Address
56 */
57 @OneToMany(mappedBy="contact")
58 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
59 public Set<Address> getAddresses(){
60 return this.addresses;
61 }
62 /**
63 * @see #getAddresses()
64 */
65 protected void setAddresses(Set<Address> addresses){
66 this.addresses = addresses;
67 }
68 /**
69 * Adds a new postal {@link Address address} to the set of postal addresses of this contact.
70 *
71 * @param address the address to be added
72 * @see #getAddresses()
73 * @see Address
74 */
75 public void addAddress(Address address){
76 if (address != null){
77 address.setContact(this);
78 addresses.add(address);
79 }
80 }
81 /**
82 * Removes one element from the set of postal addresses of this contact.
83 *
84 * @param address the postal address of this contact which should be deleted
85 * @see #getAddresses()
86 */
87 public void removeAddress(Address address){
88 address.setContact(null);
89 }
90
91
92 /**
93 * Returns the string representing the electronic mail address
94 * included in this contact.
95 */
96 public String getEmail(){
97 return this.email;
98 }
99
100 /**
101 * @see #getEmail()
102 */
103 public void setEmail(String email){
104 this.email = email;
105 }
106
107 /**
108 * Returns the string representing the "Uniform Resource Locator" (url)
109 * included in this contact.
110 */
111 public String getUrl(){
112 return this.url;
113 }
114
115 /**
116 * @see #getUrl()
117 */
118 public void setUrl(String url){
119 this.url = url;
120 }
121
122 /**
123 * Returns the string representing the phone number
124 * included in this contact.
125 */
126 public String getPhone(){
127 return this.phone;
128 }
129
130 /**
131 * @see #getPhone()
132 */
133 public void setPhone(String phone){
134 this.phone = phone;
135 }
136
137 /**
138 * Returns the string representing the telefax number
139 * included in this contact.
140 */
141 public String getFax(){
142 return this.fax;
143 }
144
145 /**
146 * @see #getFax()
147 */
148 public void setFax(String fax){
149 this.fax = fax;
150 }
151
152 }