2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.agent
;
13 import java
.util
.List
;
16 import javax
.persistence
.Embedded
;
17 import javax
.persistence
.Entity
;
18 import javax
.persistence
.Transient
;
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
.XmlType
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.hibernate
.annotations
.Cascade
;
26 import org
.hibernate
.annotations
.CascadeType
;
27 import org
.hibernate
.annotations
.Index
;
28 import org
.hibernate
.annotations
.Table
;
29 import org
.hibernate
.envers
.Audited
;
31 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
32 import eu
.etaxonomy
.cdm
.model
.location
.Country
;
33 import eu
.etaxonomy
.cdm
.model
.media
.IdentifiableMediaEntity
;
34 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
35 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchable
;
36 import eu
.etaxonomy
.cdm
.strategy
.match
.Match
;
37 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchMode
;
38 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
39 import eu
.etaxonomy
.cdm
.strategy
.merge
.Merge
;
40 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeMode
;
43 * The upmost (abstract) class for agents such as persons, teams or institutions.
44 * An agent is a conscious entity which can make decisions, act and create
45 * according to its own knowledge and goals and which may be approached.
46 * Agents can be authors for nomenclatural or bibliographical references as well
47 * as creators of pictures or field collectors or administrators of collections.
51 * @created 08-Nov-2007 13:06:57
53 @XmlAccessorType(XmlAccessType
.FIELD
)
54 @XmlType(name
= "AgentBase", propOrder
= {
59 @Table(appliesTo
="AgentBase", indexes
= { @Index(name
= "agentTitleCacheIndex", columnNames
= { "titleCache" }) })
60 public abstract class AgentBase
<S
extends IIdentifiableEntityCacheStrategy
> extends IdentifiableMediaEntity
<S
> implements IMergable
, IMatchable
, Cloneable
{
61 private static final long serialVersionUID
= 7732768617469448829L;
62 @SuppressWarnings("unused")
63 private static final Logger logger
= Logger
.getLogger(AgentBase
.class);
65 @XmlElement(name
= "Contact")
67 @Merge(MergeMode
.MERGE
)
68 @Match(MatchMode
.IGNORE
)
69 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.DELETE
})
70 private Contact contact
;
73 * Returns the {@link Contact contact} of <i>this</i> person.
74 * The contact contains several ways to approach <i>this</i> person.
78 public Contact
getContact(){
80 this.contact
= new Contact();
87 public void setContact(Contact contact
){
88 this.contact
= contact
;
93 * Returns the existing contact, or if it does not exists a new contact.
94 * If <code>create</code> is true the new contact will be set as this agent's
100 private Contact
getNewOrExistingContact(boolean create
){
101 if (contact
!= null){
104 Contact newContact
= Contact
.NewInstance();
106 contact
= newContact
;
107 this.setContact(contact
);
115 * Adds a new address to this agent
123 * @see eu.etaxonomy.cdm.model.agent.Contact#addAddress(java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.location.Country, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.location.Point)
125 public Address
addAddress(String street
, String postcode
, String locality
,
126 Country country
, String pobox
, String region
,
128 return getNewOrExistingContact(true).addAddress(street
, postcode
, locality
, country
, pobox
, region
,
133 * @see eu.etaxonomy.cdm.model.agent.Contact#addAddress(eu.etaxonomy.cdm.model.agent.Address)
135 public void addAddress(Address address
) {
136 getNewOrExistingContact(true).addAddress(address
);
139 * @param emailAddress
140 * @see eu.etaxonomy.cdm.model.agent.Contact#addEmailAddress(java.lang.String)
142 public void addEmailAddress(String emailAddress
) {
143 getNewOrExistingContact(true).addEmailAddress(emailAddress
);
147 * @see eu.etaxonomy.cdm.model.agent.Contact#addFaxNumber(java.lang.String)
149 public void addFaxNumber(String faxNumber
) {
150 getNewOrExistingContact(true).addFaxNumber(faxNumber
);
154 * @see eu.etaxonomy.cdm.model.agent.Contact#addPhoneNumber(java.lang.String)
156 public void addPhoneNumber(String phoneNumber
) {
157 getNewOrExistingContact(true).addPhoneNumber(phoneNumber
);
161 * @see eu.etaxonomy.cdm.model.agent.Contact#addUrl(java.lang.String)
163 public void addUrl(URI url
) {
164 getNewOrExistingContact(true).addUrl(url
);
168 * @see eu.etaxonomy.cdm.model.agent.Contact#getAddresses()
171 public Set
<Address
> getAddresses() {
172 return getNewOrExistingContact(false).getAddresses();
176 * @see eu.etaxonomy.cdm.model.agent.Contact#getEmailAddresses()
179 public List
<String
> getEmailAddresses() {
180 return getNewOrExistingContact(false).getEmailAddresses();
184 * @see eu.etaxonomy.cdm.model.agent.Contact#getFaxNumbers()
187 public List
<String
> getFaxNumbers() {
188 return getNewOrExistingContact(false).getFaxNumbers();
192 * @see eu.etaxonomy.cdm.model.agent.Contact#getPhoneNumbers()
195 public List
<String
> getPhoneNumbers() {
196 return getNewOrExistingContact(false).getPhoneNumbers();
200 * @see eu.etaxonomy.cdm.model.agent.Contact#getUrls()
203 public List
<URI
> getUrls() {
204 return getNewOrExistingContact(false).getUrls();
208 * @see eu.etaxonomy.cdm.model.agent.Contact#removeAddress(eu.etaxonomy.cdm.model.agent.Address)
210 public void removeAddress(Address address
) {
211 getNewOrExistingContact(false).removeAddress(address
);
214 * @param emailAddress
215 * @see eu.etaxonomy.cdm.model.agent.Contact#removeEmailAddress(java.lang.String)
217 public void removeEmailAddress(String emailAddress
) {
218 getNewOrExistingContact(false).removeEmailAddress(emailAddress
);
222 * @see eu.etaxonomy.cdm.model.agent.Contact#removeFaxNumber(java.lang.String)
224 public void removeFaxNumber(String faxNumber
) {
225 getNewOrExistingContact(false).removeFaxNumber(faxNumber
);
229 * @see eu.etaxonomy.cdm.model.agent.Contact#removePhoneNumber(java.lang.String)
231 public void removePhoneNumber(String phoneNumber
) {
232 getNewOrExistingContact(false).removePhoneNumber(phoneNumber
);
236 * @see eu.etaxonomy.cdm.model.agent.Contact#removeUrl(java.lang.String)
238 public void removeUrl(URI url
) {
239 getNewOrExistingContact(false).removeUrl(url
);