Project

General

Profile

Download (9.06 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.name;
11

    
12

    
13
import eu.etaxonomy.cdm.model.occurrence.Specimen;
14
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
15
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
16
import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;
17
import eu.etaxonomy.cdm.model.taxon.Synonym;
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
20
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
21
import eu.etaxonomy.cdm.model.common.IReferencedEntity;
22
import org.apache.log4j.Logger;
23
import org.hibernate.annotations.Cascade;
24
import org.hibernate.annotations.CascadeType;
25

    
26
import eu.etaxonomy.cdm.strategy.INameCacheStrategy;
27
import eu.etaxonomy.cdm.strategy.ITaxonNameParser;
28

    
29
import java.util.*;
30

    
31
import javax.persistence.*;
32

    
33
/**
34
 * The upmost (abstract) class for scientific taxon names regardless of the any
35
 * particular nomenclatural code. The scientific name including author strings and
36
 * maybe year is stored in IdentifiableEntity.titleCache
37
 * @author m.doering
38
 * @version 1.0
39
 * @created 08-Nov-2007 13:06:57
40
 */
41
@Entity
42
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
43
public abstract class TaxonNameBase extends IdentifiableEntity<TaxonNameBase> implements IReferencedEntity {
44
	static Logger logger = Logger.getLogger(TaxonNameBase.class);
45
	//The scientific name without author strings and year
46
	private String nameCache;
47
	//Non-atomised addition to a name not ruled by a nomenclatural code
48
	private String appendedPhrase;
49
	//Details of the nomenclatural reference (protologue). These are mostly (implicitly) pages but can also be figures or
50
	//tables or any other element of a publication. {only if a nomenclatural reference exists}
51
	private String nomenclaturalMicroReference;
52
	//this flag will be set to true if the parseName method was unable to successfully parse the name
53
	private boolean hasProblem = false;
54
	protected Set<NameTypeDesignation> nameTypeDesignations  = new HashSet();
55
	private HomotypicalGroup homotypicalGroup = new HomotypicalGroup();
56
	private Set<NameRelationship> nameRelations = new HashSet();
57
	private Set<NomenclaturalStatus> status = new HashSet();
58
	private Rank rank;
59
	//if set, the Reference.isNomenclaturallyRelevant flag should be set to true!
60
	private INomenclaturalReference nomenclaturalReference;
61
	private Set<TaxonNameBase> newCombinations = new HashSet();
62
	// bidrectional with newCombinations. Keep congruent
63
	private TaxonNameBase basionym;
64

    
65
	protected INameCacheStrategy cacheStrategy;
66

    
67
	static protected ITaxonNameParser nameParser;
68
	
69
//	/**
70
//	 * Returns a TaxonNameBase instance 
71
//	 * @param fullName
72
//	 */
73
//	abstract public static TaxonNameBase PARSED_NAME(String fullName);
74
	
75
	// CONSTRUCTORS	
76
	public TaxonNameBase() {
77
		super();
78
	}
79
	public TaxonNameBase(Rank rank) {
80
		super();
81
		this.setRank(rank);
82
	}
83

    
84
	
85
	public String getNameCache() {
86
		return nameCache;
87
	}
88
	public void setNameCache(String nameCache) {
89
		this.nameCache = nameCache;
90
	}
91

    
92

    
93
	@Transient
94
	public abstract boolean isCodeCompliant();
95
	
96

    
97
	@OneToMany
98
	@Cascade({CascadeType.SAVE_UPDATE})
99
	public Set<NameRelationship> getNameRelations() {
100
		return nameRelations;
101
	}
102
	protected void setNameRelations(Set<NameRelationship> nameRelations) {
103
		this.nameRelations = nameRelations;
104
	}
105
	public void addNameRelation(NameRelationship nameRelation) {
106
		// checks whether this is a normal relation or an inverse one 
107
		// and adds it to the appropiate set
108
		//this.inverseNameRelations
109
		this.nameRelations.add(nameRelation);
110
	}
111
	public void removeNameRelation(NameRelationship nameRelation) {
112
		// this.inverseNameRelations
113
		this.nameRelations.remove(nameRelation);
114
	}
115
	
116
	
117
	@Transient
118
	public Set<NameRelationship> getIncomingNameRelations() {
119
		// FIXME: filter relations
120
		return nameRelations;
121
	}
122
	@Transient
123
	public Set<NameRelationship> getOutgoingNameRelations() {
124
		// FIXME: filter relations
125
		return nameRelations;
126
	}
127

    
128
	
129

    
130
	@OneToMany
131
	@Cascade({CascadeType.SAVE_UPDATE})
132
	public Set<NomenclaturalStatus> getStatus() {
133
		return status;
134
	}
135
	protected void setStatus(Set<NomenclaturalStatus> status) {
136
		this.status = status;
137
	}
138
	public void addStatus(NomenclaturalStatus status) {
139
		this.status.add(status);
140
	}
141
	public void removeStatus(NomenclaturalStatus status) {
142
		this.status.remove(status);
143
	}
144

    
145

    
146

    
147
	@OneToMany
148
	@Cascade({CascadeType.SAVE_UPDATE})
149
	public Set<TaxonNameBase> getNewCombinations() {
150
		return newCombinations;
151
	}
152
	protected void setNewCombinations(Set<TaxonNameBase> newCombinations) {
153
		this.newCombinations = newCombinations;
154
	}
155
	public void addNewCombination(TaxonNameBase newCombination) {
156
		// TODO: add basionym relation too!
157
		this.newCombinations.add(newCombination);
158
	}
159
	public void removeNewCombination(TaxonNameBase newCombination) {
160
		this.newCombinations.remove(newCombination);
161
	}
162

    
163

    
164
	@ManyToOne
165
	@Cascade({CascadeType.SAVE_UPDATE})
166
	public TaxonNameBase getBasionym(){
167
		return this.basionym;
168
	}
169
	public void setBasionym(TaxonNameBase basionym){
170
		// TODO: add newCombination relation too!
171
		this.basionym = basionym;
172
	}
173

    
174

    
175

    
176
	//TODO for PROTOTYPE
177
	@Transient
178
	public INameCacheStrategy getCacheStrategy() {
179
		return cacheStrategy;
180
	}
181
	public void setCacheStrategy(INameCacheStrategy cacheStrategy) {
182
		this.cacheStrategy = cacheStrategy;
183
	}
184
	
185
	@ManyToOne
186
	@Cascade({CascadeType.SAVE_UPDATE})
187
	public Rank getRank(){
188
		return this.rank;
189
	}
190
	public void setRank(Rank rank){
191
		this.rank = rank;
192
	}
193

    
194
	@ManyToOne
195
	@Cascade({CascadeType.SAVE_UPDATE})
196
	public ReferenceBase getNomenclaturalReference(){
197
		return (ReferenceBase) this.nomenclaturalReference;
198
	}
199
	public void setNomenclaturalReference(INomenclaturalReference nomenclaturalReference){
200
		this.nomenclaturalReference = nomenclaturalReference;
201
	}
202

    
203

    
204
	public String getAppendedPhrase(){
205
		return this.appendedPhrase;
206
	}
207
	public void setAppendedPhrase(String appendedPhrase){
208
		this.appendedPhrase = appendedPhrase;
209
	}
210

    
211
	public String getNomenclaturalMicroReference(){
212
		return this.nomenclaturalMicroReference;
213
	}
214
	public void setNomenclaturalMicroReference(String nomenclaturalMicroReference){
215
		this.nomenclaturalMicroReference = nomenclaturalMicroReference;
216
	}
217

    
218
	public boolean getHasProblem(){
219
		return this.hasProblem;
220
	}
221
	public void setHasProblem(boolean hasProblem){
222
		this.hasProblem = hasProblem;
223
	}
224

    
225

    
226
	@OneToMany
227
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
228
	public Set<NameTypeDesignation> getNameTypeDesignations() {
229
		return nameTypeDesignations;
230
	}
231
	protected void setNameTypeDesignations(Set<NameTypeDesignation> nameTypeDesignations) {
232
		this.nameTypeDesignations = nameTypeDesignations;
233
	}
234
	
235
	public void addTypeDesignation(TaxonNameBase typeSpecies, ReferenceBase citation, String citationMicroReference, String originalNameString, boolean isRejectedType, boolean isConservedType) {
236
		NameTypeDesignation td = new NameTypeDesignation(this, typeSpecies, citation, citationMicroReference, originalNameString, isRejectedType, isConservedType);
237
	}
238
	public void addTypeDesignation(Specimen typeSpecimen, TypeDesignationStatus status, ReferenceBase citation, String citationMicroReference, String originalNameString) {
239
		this.homotypicalGroup.addTypeDesignation(typeSpecimen, status,  citation, citationMicroReference, originalNameString);
240
	}
241
	public void removeTypeDesignation(NameTypeDesignation typeDesignation) {
242
		this.nameTypeDesignations.remove(typeDesignation);
243
	}
244
	public void removeTypeDesignation(SpecimenTypeDesignation typeDesignation) {
245
		this.homotypicalGroup.removeTypeDesignation(typeDesignation);
246
	}
247

    
248

    
249
	@ManyToOne
250
	@Cascade({CascadeType.SAVE_UPDATE})
251
	public HomotypicalGroup getHomotypicalGroup() {
252
		return homotypicalGroup;
253
	}
254
	public void setHomotypicalGroup(HomotypicalGroup newHomotypicalGroup) {
255
		if(this.homotypicalGroup == newHomotypicalGroup) return;
256
		if (homotypicalGroup != null) { 
257
			homotypicalGroup.typifiedNames.remove(this);
258
		}
259
		if (newHomotypicalGroup!= null) { 
260
			newHomotypicalGroup.typifiedNames.add(this);
261
		}
262
		this.homotypicalGroup = newHomotypicalGroup;		
263
	}
264

    
265
	@Transient
266
	public StrictReferenceBase getCitation(){
267
		return null;
268
	}
269

    
270
	@Transient
271
	public String getCitationString(){
272
		return null;
273
	}
274

    
275
	@Transient
276
	public String[] getProblems(){
277
		return null;
278
	}
279

    
280
	/**
281
	 * returns year of according nomenclatural reference, null if nomenclatural
282
	 * reference does not exist
283
	 */
284
	@Transient
285
	public String getYear(){
286
		return "";
287
	}
288

    
289
	
290
	/**
291
	 * Return a set of taxa that use this name
292
	 * @return
293
	 */
294
	@Transient
295
	public Set<Taxon> getTaxa(){
296
		// TODO: implement this method via bidirectional TaxonBase-NameBase relation or use a DAO instead
297
		return null;
298
	}
299
	/**
300
	 * Return a set of synonyms that use this name
301
	 * @return
302
	 */
303
	@Transient
304
	public Set<Synonym> getSynonyms(){
305
		// TODO: implement this method via bidirectional TaxonBase-NameBase relation or use a DAO instead
306
		return null;
307
	}
308
	
309
	@Transient
310
	public Set<SpecimenTypeDesignation> getSpecimenTypeDesignations() {
311
		return this.getHomotypicalGroup().getTypeDesignations();
312
	}
313
	
314
}
(15-15/18)