Project

General

Profile

Download (6.31 KB) Statistics
| Branch: | Tag: | Revision:
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 java.io.Serializable;
13
import java.util.ArrayList;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17

    
18
import javax.persistence.Embeddable;
19
import javax.persistence.FetchType;
20
import javax.persistence.OneToMany;
21
import javax.xml.bind.annotation.XmlAccessType;
22
import javax.xml.bind.annotation.XmlAccessorType;
23
import javax.xml.bind.annotation.XmlElement;
24
import javax.xml.bind.annotation.XmlElementWrapper;
25
import javax.xml.bind.annotation.XmlRootElement;
26
import javax.xml.bind.annotation.XmlSchemaType;
27
import javax.xml.bind.annotation.XmlType;
28

    
29
import org.apache.log4j.Logger;
30
import org.hibernate.annotations.Cascade;
31
import org.hibernate.annotations.CascadeType;
32
import org.hibernate.annotations.CollectionOfElements;
33
import org.hibernate.envers.Audited;
34

    
35
/**
36
 * The class for information on how to approach a {@link Person person} or an {@link Institution institution}.
37
 * It includes telecommunication data and an electronic as well as
38
 * multiple postal addresses.
39
* <P>
40
 * This class corresponds to: <ul>
41
 * <li> ContactDetails according to the TDWG ontology
42
 * <li> Contact (partially) according to the ABCD schema
43
 * </ul>
44
 * 
45
 * @author m.doering
46
 * @version 1.0
47
 * @created 08-Nov-2007 13:06:18
48
 */
49
@XmlAccessorType(XmlAccessType.FIELD)
50
@XmlType(name = "Contact", propOrder = {
51
    "emailAddresses",
52
    "urls",
53
    "phoneNumbers",
54
    "faxNumbers",
55
    "addresses"
56
})
57
@XmlRootElement(name = "Contact")
58
@Embeddable
59
@Audited
60
public class Contact implements Serializable {
61
	private static final long serialVersionUID = -1851305307069277625L;
62
	private static final Logger logger = Logger.getLogger(Contact.class);
63
	
64

    
65
	/** 
66
	 * Class constructor.
67
	 */
68
	public Contact() {
69
		super();
70
		logger.debug("Constructor call");
71
	}
72

    
73
	@XmlElementWrapper(name = "EmailAddresses")
74
	@XmlElement(name = "EmailAddress")
75
	@CollectionOfElements(fetch = FetchType.LAZY)
76
	private List<String> emailAddresses = new ArrayList<String>();
77
	
78
	@XmlElementWrapper(name = "URLs")
79
	@XmlElement(name = "URL")
80
    @XmlSchemaType(name = "anyURI")
81
    @CollectionOfElements(fetch = FetchType.LAZY)
82
	private List<String> urls = new ArrayList<String>();
83
	
84
	@XmlElementWrapper(name = "PhoneNumbers")
85
	@XmlElement(name = "PhoneNumber")
86
	@CollectionOfElements(fetch = FetchType.LAZY)
87
	private List<String> phoneNumbers = new ArrayList<String>();
88
	
89
	@XmlElementWrapper(name = "FaxNumbers")
90
	@XmlElement(name = "FaxNumber")
91
	@CollectionOfElements(fetch = FetchType.LAZY)
92
	private List<String> faxNumbers = new ArrayList<String>();
93
	
94
    @XmlElementWrapper(name = "Addresses")
95
    @XmlElement(name = "Address")
96
    @OneToMany(fetch = FetchType.LAZY)
97
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
98
	protected Set<Address> addresses = new HashSet<Address>();
99
	
100
	
101
	/** 
102
	 * Returns the set of postal {@link Address addresses} belonging to <i>this</i> contact. 
103
	 * A {@link Person person} or an {@link Institution institution} cannot have more than one contact,
104
	 * but a contact may include several postal addresses. 
105
	 *
106
	 * @return	the set of postal addresses
107
	 * @see     Address
108
	 */
109
	public Set<Address> getAddresses(){
110
		return this.addresses;
111
	}
112
	
113
	/** 
114
	 * Adds a new postal {@link Address address} to the set of postal addresses of <i>this</i> contact.
115
	 *
116
	 * @param  address  the address to be added
117
	 * @see     		#getAddresses()
118
	 * @see 			Address
119
	 */
120
	public void addAddress(Address address){
121
		if (address != null){
122
			addresses.add(address);
123
		}
124
	}
125
	
126
	/** 
127
	 * Removes one element from the set of postal addresses of <i>this</i> contact.
128
	 *
129
	 * @param  address  the postal address of <i>this</i> contact which should be deleted
130
	 * @see     		#getAddresses()
131
	 */
132
	public void removeAddress(Address address){
133
		addresses.remove(address);
134
	}
135

    
136
	
137
	/**
138
	 * Returns the List of strings representing the electronic mail addresses
139
	 * included in <i>this</i> contact.
140
	 */
141
	public List<String> getEmailAddresses(){
142
		return this.emailAddresses;
143
	}
144

    
145
	/**
146
	 * @see  #getEmailAddress()
147
	 */
148
	public void addEmailAddress(String emailAddress){
149
		this.emailAddresses.add(emailAddress);
150
	}
151
	
152
	/** 
153
	 * Removes one element from the list of email addresses of <i>this</i> contact.
154
	 *
155
	 * @param  emailAddress  the email address of <i>this</i> contact which should be deleted
156
	 * @see     		#getEmailAddresses()
157
	 */
158
	public void removeEmailAddress(String emailAddress){
159
		emailAddresses.remove(emailAddress);
160
	}
161

    
162
	/**
163
	 * Returns the list of strings representing the "Uniform Resource Locators" (urls)
164
	 * included in <i>this</i> contact.
165
	 */
166
	public List<String> getUrls(){
167
		return this.urls;
168
	}
169

    
170
	/**
171
	 * @see  #getUrls()
172
	 */
173
	public void addUrl(String url){
174
		this.urls.add(url);
175
	}
176
	
177
	/** 
178
	 * Removes one element from the list of urls of <i>this</i> contact.
179
	 *
180
	 * @param  url  the url of <i>this</i> contact which should be deleted
181
	 * @see     		#getUrls()
182
	 */
183
	public void removeUrl(String url){
184
		urls.remove(url);
185
	}
186

    
187
	/**
188
	 * Returns the list of strings representing the phone numbers
189
	 * included in <i>this</i> contact.
190
	 */
191
	public List<String> getPhoneNumbers(){
192
		return this.phoneNumbers;
193
	}
194

    
195
	/**
196
	 * @see  #getPhone()
197
	 */
198
	public void addPhoneNumber(String phoneNumber){
199
		this.phoneNumbers.add(phoneNumber);
200
	}
201
	
202
	/** 
203
	 * Removes one element from the list of phone numbers of <i>this</i> contact.
204
	 *
205
	 * @param  phoneNumber  the phone number of <i>this</i> contact which should be deleted
206
	 * @see     		#getPhoneNumber()
207
	 */
208
	public void removePhoneNumber(String phoneNumber){
209
		phoneNumbers.remove(phoneNumber);
210
	}
211

    
212
	/**
213
	 * Returns the list of strings representing the telefax numbers
214
	 * included in <i>this</i> contact.
215
	 */
216
	public List<String> getFaxNumbers(){
217
		return this.faxNumbers;
218
	}
219

    
220
	/**
221
	 * @see  #getFaxNumbers()
222
	 */
223
	public void addFaxNumber(String faxNumber){
224
		this.faxNumbers.add(faxNumber);
225
	}
226

    
227
	/** 
228
	 * Removes one element from the list of telefax numbers of <i>this</i> contact.
229
	 *
230
	 * @param  faxNumber  the telefax number of <i>this</i> contact which should be deleted
231
	 * @see     		#getFaxNumber()
232
	 */
233
	public void removeFaxNumber(String faxNumber){
234
		faxNumbers.remove(faxNumber);
235
	}
236
}
(3-3/12)