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
.name
;
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
;
26 import eu
.etaxonomy
.cdm
.strategy
.cache
.INameCacheStrategy
;
27 import eu
.etaxonomy
.cdm
.strategy
.parser
.ITaxonNameParser
;
31 import javax
.persistence
.*;
34 * The upmost (abstract) class for scientific taxon names regardless of any
35 * particular nomenclatural code. The scientific name including author strings and
36 * maybe year is stored in IdentifiableEntity.titleCache
40 * @created 08-Nov-2007 13:06:57
43 @Inheritance(strategy
=InheritanceType
.SINGLE_TABLE
)
44 public abstract class TaxonNameBase
<T
extends TaxonNameBase
> extends IdentifiableEntity
<TaxonNameBase
> implements IReferencedEntity
{
45 static Logger logger
= Logger
.getLogger(TaxonNameBase
.class);
46 //The scientific name without author strings and year
47 private String nameCache
;
48 //Non-atomised addition to a name not ruled by a nomenclatural code
49 private String appendedPhrase
;
50 //Details of the nomenclatural reference (protologue). These are mostly (implicitly) pages but can also be figures or
51 //tables or any other element of a publication. {only if a nomenclatural reference exists}
52 private String nomenclaturalMicroReference
;
53 //this flag will be set to true if the parseName method was unable to successfully parse the name
54 private boolean hasProblem
= false;
55 protected Set
<NameTypeDesignation
> nameTypeDesignations
= new HashSet
<NameTypeDesignation
>();
56 private HomotypicalGroup homotypicalGroup
= new HomotypicalGroup();
57 private Set
<NameRelationship
> relationsFromThisName
= new HashSet
<NameRelationship
>();
58 private Set
<NameRelationship
> relationsToThisName
= new HashSet
<NameRelationship
>();
59 private Set
<NomenclaturalStatus
> status
= new HashSet
<NomenclaturalStatus
>();
60 private Set
<TaxonBase
> taxonBases
= new HashSet
<TaxonBase
>();
63 //if set, the Reference.isNomenclaturallyRelevant flag should be set to true!
64 private INomenclaturalReference nomenclaturalReference
;
66 //this flag shows if the getNameCache should return generated value(false) or the given String(true)
67 protected boolean protectedNameCache
;
69 protected INameCacheStrategy
<T
> cacheStrategy
;
72 // * Returns a TaxonNameBase instance
75 // abstract public static TaxonNameBase PARSED_NAME(String fullName);
77 // ************* CONSTRUCTORS *************/
78 public TaxonNameBase() {
81 public TaxonNameBase(Rank rank
) {
84 public TaxonNameBase(HomotypicalGroup homotypicalGroup
) {
85 this(null, homotypicalGroup
);
87 public TaxonNameBase(Rank rank
, HomotypicalGroup homotypicalGroup
) {
90 if (homotypicalGroup
== null){
91 homotypicalGroup
= new HomotypicalGroup();
93 homotypicalGroup
.addTypifiedName(this);
96 //********* METHODS **************************************/
100 protected String
generateNameCache(){
101 if (cacheStrategy
== null){
102 logger
.warn("No CacheStrategy defined for taxonName: " + this.toString());
105 return cacheStrategy
.getNameCache((T
)this);
109 public String
getNameCache() {
110 if (protectedNameCache
){
111 return this.nameCache
;
113 // is title dirty, i.e. equal NULL?
114 if (nameCache
== null){
115 this.nameCache
= generateNameCache();
120 public void setNameCache(String nameCache
){
121 this.nameCache
= nameCache
;
122 // TODO this.setProtectedNameCache(true);
128 public abstract boolean isCodeCompliant();
132 public Set
<NameRelationship
> getNameRelations() {
133 Set
<NameRelationship
> rels
= new HashSet
<NameRelationship
>();
134 rels
.addAll(getRelationsFromThisName());
135 rels
.addAll(getRelationsToThisName());
139 * Add a name relationship to both names involved
142 public void addRelationshipToName(TaxonNameBase toName
, NameRelationshipType type
, String ruleConsidered
){
143 NameRelationship rel
= new NameRelationship(toName
, this, type
, ruleConsidered
);
145 public void addRelationshipFromName(TaxonNameBase fromName
, NameRelationshipType type
, String ruleConsidered
){
146 NameRelationship rel
= new NameRelationship(this, fromName
, type
, ruleConsidered
);
148 protected void addNameRelationship(NameRelationship rel
) {
149 if (rel
!=null && rel
.getToName().equals(this)){
150 this.relationsToThisName
.add(rel
);
151 }else if(rel
!=null && rel
.getFromName().equals(this)){
152 this.relationsFromThisName
.add(rel
);
154 //TODO: raise error???
157 public void removeNameRelationship(NameRelationship nameRelation
) {
158 this.relationsToThisName
.remove(nameRelation
);
159 this.relationsFromThisName
.remove(nameRelation
);
163 @OneToMany(mappedBy
="fromName")
164 @Cascade({CascadeType
.SAVE_UPDATE
})
165 public Set
<NameRelationship
> getRelationsFromThisName() {
166 return relationsFromThisName
;
168 private void setRelationsFromThisName(Set
<NameRelationship
> relationsFromThisName
) {
169 this.relationsFromThisName
= relationsFromThisName
;
172 @OneToMany(mappedBy
="toName")
173 @Cascade({CascadeType
.SAVE_UPDATE
})
174 public Set
<NameRelationship
> getRelationsToThisName() {
175 return relationsToThisName
;
177 private void setRelationsToThisName(Set
<NameRelationship
> relationsToThisName
) {
178 this.relationsToThisName
= relationsToThisName
;
184 @Cascade({CascadeType
.SAVE_UPDATE
})
185 public Set
<NomenclaturalStatus
> getStatus() {
188 protected void setStatus(Set
<NomenclaturalStatus
> nomStatus
) {
189 this.status
= nomStatus
;
191 public void addStatus(NomenclaturalStatus nomStatus
) {
192 this.status
.add(nomStatus
);
194 public void removeStatus(NomenclaturalStatus nomStatus
) {
195 this.status
.remove(nomStatus
);
200 public T
getBasionym(){
201 //TODO: pick the right name relationships...
204 public void setBasionym(T basionym
){
205 setBasionym(basionym
, null);
207 public void setBasionym(T basionym
, String ruleConsidered
){
208 basionym
.addRelationshipToName(this, NameRelationshipType
.BASIONYM(), null);
215 public INameCacheStrategy
<T
> getCacheStrategy() {
216 return cacheStrategy
;
218 public void setCacheStrategy(INameCacheStrategy cacheStrategy
) {
219 this.cacheStrategy
= cacheStrategy
;
223 //@Cascade({CascadeType.SAVE_UPDATE})
224 public Rank
getRank(){
227 public void setRank(Rank rank
){
232 @Cascade({CascadeType
.SAVE_UPDATE
})
233 public ReferenceBase
getNomenclaturalReference(){
234 return (ReferenceBase
) this.nomenclaturalReference
;
236 public void setNomenclaturalReference(INomenclaturalReference nomenclaturalReference
){
237 this.nomenclaturalReference
= nomenclaturalReference
;
241 public String
getAppendedPhrase(){
242 return this.appendedPhrase
;
244 public void setAppendedPhrase(String appendedPhrase
){
245 this.appendedPhrase
= appendedPhrase
;
248 public String
getNomenclaturalMicroReference(){
249 return this.nomenclaturalMicroReference
;
251 public void setNomenclaturalMicroReference(String nomenclaturalMicroReference
){
252 this.nomenclaturalMicroReference
= nomenclaturalMicroReference
;
255 public boolean getHasProblem(){
256 return this.hasProblem
;
258 public void setHasProblem(boolean hasProblem
){
259 this.hasProblem
= hasProblem
;
264 //TODO @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
265 @Cascade(CascadeType
.SAVE_UPDATE
)
266 public Set
<NameTypeDesignation
> getNameTypeDesignations() {
267 return nameTypeDesignations
;
269 protected void setNameTypeDesignations(Set
<NameTypeDesignation
> nameTypeDesignations
) {
270 this.nameTypeDesignations
= nameTypeDesignations
;
273 public void addTypeDesignation(TaxonNameBase typeSpecies
, ReferenceBase citation
, String citationMicroReference
, String originalNameString
, boolean isRejectedType
, boolean isConservedType
) {
274 NameTypeDesignation td
= new NameTypeDesignation(this, typeSpecies
, citation
, citationMicroReference
, originalNameString
, isRejectedType
, isConservedType
);
276 public void addTypeDesignation(Specimen typeSpecimen
, TypeDesignationStatus status
, ReferenceBase citation
, String citationMicroReference
, String originalNameString
) {
277 this.homotypicalGroup
.addTypeDesignation(typeSpecimen
, status
, citation
, citationMicroReference
, originalNameString
);
279 public void removeTypeDesignation(NameTypeDesignation typeDesignation
) {
280 this.nameTypeDesignations
.remove(typeDesignation
);
282 public void removeTypeDesignation(SpecimenTypeDesignation typeDesignation
) {
283 this.homotypicalGroup
.removeTypeDesignation(typeDesignation
);
288 @Cascade({CascadeType
.SAVE_UPDATE
})
289 public HomotypicalGroup
getHomotypicalGroup() {
290 return homotypicalGroup
;
292 public void setHomotypicalGroup(HomotypicalGroup newHomotypicalGroup
) {
293 if(this.homotypicalGroup
== newHomotypicalGroup
) return;
294 if (homotypicalGroup
!= null) {
295 homotypicalGroup
.typifiedNames
.remove(this);
297 if (newHomotypicalGroup
!= null) {
298 newHomotypicalGroup
.typifiedNames
.add(this);
300 this.homotypicalGroup
= newHomotypicalGroup
;
304 public StrictReferenceBase
getCitation(){
305 logger
.warn("getCitation not yet implemented");
310 public String
getCitationString(){
311 logger
.warn("getCitationString not yet implemented");
316 public String
[] getProblems(){
317 logger
.warn("getProblems not yet implemented");
322 * returns year of according nomenclatural reference, null if nomenclatural
323 * reference does not exist
326 public String
getReferenceYear(){
327 if (this.getNomenclaturalReference() != null ){
328 return this.getNomenclaturalReference().getYear();
334 @OneToMany(mappedBy
="name", fetch
= FetchType
.EAGER
)
335 public Set
<TaxonBase
> getTaxonBases() {
336 return this.taxonBases
;
338 protected void setTaxonBases(Set
<TaxonBase
> taxonBases
) {
339 if (taxonBases
== null){
340 taxonBases
= new HashSet
<TaxonBase
>();
342 this.taxonBases
= taxonBases
;
345 // public void addSynonym(Synonym synonym) {
346 // synonym.setName(this);
348 // public void removeSynonym(Synonym synonym) {
349 // synonym.setName(null);
353 * Return a set of taxa that use this name
357 public Set
<Taxon
> getTaxa(){
358 Set
<Taxon
> result
= new HashSet
<Taxon
>();
359 for (TaxonBase taxonBase
: this.taxonBases
){
360 if (taxonBase
instanceof Taxon
){
361 result
.add((Taxon
)taxonBase
);
368 * Return a set of synonyms that use this name
371 // TODO: implement this method via bidirectional TaxonBase-NameBase relation or use a DAO instead
375 public Set
<Synonym
> getSynonyms() {
376 Set
<Synonym
> result
= new HashSet
<Synonym
>();
377 for (TaxonBase taxonBase
: this.taxonBases
){
378 if (taxonBase
instanceof Synonym
){
379 result
.add((Synonym
)taxonBase
);
386 public Set
<SpecimenTypeDesignation
> getSpecimenTypeDesignations() {
387 return this.getHomotypicalGroup().getTypeDesignations();
390 // Rank comparison shortcuts
392 public boolean isSupraGeneric() {
393 return getRank().isSupraGeneric();
396 public boolean isGenus() {
397 return getRank().isGenus();
400 public boolean isInfraGeneric() {
401 return getRank().isInfraGeneric();
404 public boolean isSpecies() {
405 return getRank().isSpecies();
408 public boolean isInfraSpecific() {
409 return getRank().isInfraSpecific();