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
.SynonymRelationship
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
23 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
24 import eu
.etaxonomy
.cdm
.model
.common
.IReferencedEntity
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.hibernate
.annotations
.Cascade
;
27 import org
.hibernate
.annotations
.CascadeType
;
29 import eu
.etaxonomy
.cdm
.strategy
.INameCacheStrategy
;
30 import eu
.etaxonomy
.cdm
.strategy
.ITaxonNameParser
;
34 import javax
.persistence
.*;
37 * The upmost (abstract) class for scientific taxon names regardless of the any
38 * particular nomenclatural code. The scientific name including author strings and
39 * maybe year is stored in IdentifiableEntity.titleCache
43 * @created 08-Nov-2007 13:06:57
46 @Inheritance(strategy
=InheritanceType
.SINGLE_TABLE
)
47 public abstract class TaxonNameBase
<T
extends TaxonNameBase
> extends IdentifiableEntity
<TaxonNameBase
> implements IReferencedEntity
{
48 static Logger logger
= Logger
.getLogger(TaxonNameBase
.class);
49 //The scientific name without author strings and year
50 private String nameCache
;
51 //Non-atomised addition to a name not ruled by a nomenclatural code
52 private String appendedPhrase
;
53 //Details of the nomenclatural reference (protologue). These are mostly (implicitly) pages but can also be figures or
54 //tables or any other element of a publication. {only if a nomenclatural reference exists}
55 private String nomenclaturalMicroReference
;
56 //this flag will be set to true if the parseName method was unable to successfully parse the name
57 private boolean hasProblem
= false;
58 protected Set
<NameTypeDesignation
> nameTypeDesignations
= new HashSet();
59 private HomotypicalGroup homotypicalGroup
= new HomotypicalGroup();
60 private Set
<NameRelationship
> relationsFromThisName
= new HashSet();
61 private Set
<NameRelationship
> relationsToThisName
= new HashSet();
62 private Set
<NomenclaturalStatus
> status
= new HashSet();
64 //if set, the Reference.isNomenclaturallyRelevant flag should be set to true!
65 private INomenclaturalReference nomenclaturalReference
;
69 protected boolean protectedNameCache
;
71 protected INameCacheStrategy cacheStrategy
;
73 static protected ITaxonNameParser nameParser
;
76 // * Returns a TaxonNameBase instance
79 // abstract public static TaxonNameBase PARSED_NAME(String fullName);
81 // ************* CONSTRUCTORS *************/
82 public TaxonNameBase() {
85 public TaxonNameBase(Rank rank
) {
90 //********* METHODS **************************************/
92 protected String
generateNameCache(){
93 if (cacheStrategy
== null){
94 logger
.warn("No CacheStrategy defined for taxonName: " + this.toString());
97 return cacheStrategy
.getNameCache(this);
101 public String
getNameCache() {
102 if (protectedNameCache
){
103 return this.nameCache
;
105 // is title dirty, i.e. equal NULL?
106 if (nameCache
== null){
107 this.nameCache
= generateNameCache();
112 public void setNameCache(String nameCache
) {
113 this.nameCache
= nameCache
;
117 public abstract boolean isCodeCompliant();
121 public Set
<NameRelationship
> getNameRelations() {
122 Set
<NameRelationship
> rels
= new HashSet
<NameRelationship
>();
123 rels
.addAll(getRelationsFromThisName());
124 rels
.addAll(getRelationsToThisName());
128 * Add a name relationship to both names involved
131 public void addRelationshipToName(TaxonNameBase toName
, NameRelationshipType type
, String ruleConsidered
){
132 NameRelationship rel
= new NameRelationship(toName
, this, type
, ruleConsidered
);
134 public void addRelationshipFromName(TaxonNameBase fromName
, NameRelationshipType type
, String ruleConsidered
){
135 NameRelationship rel
= new NameRelationship(this, fromName
, type
, ruleConsidered
);
137 protected void addNameRelationship(NameRelationship rel
) {
138 if (rel
!=null && rel
.getToName().equals(this)){
139 this.relationsToThisName
.add(rel
);
140 }else if(rel
!=null && rel
.getFromName().equals(this)){
141 this.relationsFromThisName
.add(rel
);
143 //TODO: raise error???
146 public void removeNameRelationship(NameRelationship nameRelation
) {
147 this.relationsToThisName
.remove(nameRelation
);
148 this.relationsFromThisName
.remove(nameRelation
);
152 @OneToMany(mappedBy
="fromName")
153 @Cascade({CascadeType
.SAVE_UPDATE
})
154 public Set
<NameRelationship
> getRelationsFromThisName() {
155 return relationsFromThisName
;
157 private void setRelationsFromThisName(Set
<NameRelationship
> relationsFromThisName
) {
158 this.relationsFromThisName
= relationsFromThisName
;
161 @OneToMany(mappedBy
="toName")
162 @Cascade({CascadeType
.SAVE_UPDATE
})
163 public Set
<NameRelationship
> getRelationsToThisName() {
164 return relationsToThisName
;
166 private void setRelationsToThisName(Set
<NameRelationship
> relationsToThisName
) {
167 this.relationsToThisName
= relationsToThisName
;
173 @Cascade({CascadeType
.SAVE_UPDATE
})
174 public Set
<NomenclaturalStatus
> getStatus() {
177 protected void setStatus(Set
<NomenclaturalStatus
> status
) {
178 this.status
= status
;
180 public void addStatus(NomenclaturalStatus status
) {
181 this.status
.add(status
);
183 public void removeStatus(NomenclaturalStatus status
) {
184 this.status
.remove(status
);
189 public T
getBasionym(){
190 //TODO: pick the right name relationships...
193 public void setBasionym(T basionym
){
194 setBasionym(basionym
, null);
196 public void setBasionym(T basionym
, String ruleConsidered
){
197 basionym
.addRelationshipToName(this, NameRelationshipType
.BASIONYM(), null);
204 public INameCacheStrategy
getCacheStrategy() {
205 return cacheStrategy
;
207 public void setCacheStrategy(INameCacheStrategy cacheStrategy
) {
208 this.cacheStrategy
= cacheStrategy
;
212 //@Cascade({CascadeType.SAVE_UPDATE})
213 public Rank
getRank(){
216 public void setRank(Rank rank
){
221 @Cascade({CascadeType
.SAVE_UPDATE
})
222 public ReferenceBase
getNomenclaturalReference(){
223 return (ReferenceBase
) this.nomenclaturalReference
;
225 public void setNomenclaturalReference(INomenclaturalReference nomenclaturalReference
){
226 this.nomenclaturalReference
= nomenclaturalReference
;
230 public String
getAppendedPhrase(){
231 return this.appendedPhrase
;
233 public void setAppendedPhrase(String appendedPhrase
){
234 this.appendedPhrase
= appendedPhrase
;
237 public String
getNomenclaturalMicroReference(){
238 return this.nomenclaturalMicroReference
;
240 public void setNomenclaturalMicroReference(String nomenclaturalMicroReference
){
241 this.nomenclaturalMicroReference
= nomenclaturalMicroReference
;
244 public boolean getHasProblem(){
245 return this.hasProblem
;
247 public void setHasProblem(boolean hasProblem
){
248 this.hasProblem
= hasProblem
;
253 //TODO @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
254 @Cascade(CascadeType
.SAVE_UPDATE
)
255 public Set
<NameTypeDesignation
> getNameTypeDesignations() {
256 return nameTypeDesignations
;
258 protected void setNameTypeDesignations(Set
<NameTypeDesignation
> nameTypeDesignations
) {
259 this.nameTypeDesignations
= nameTypeDesignations
;
262 public void addTypeDesignation(TaxonNameBase typeSpecies
, ReferenceBase citation
, String citationMicroReference
, String originalNameString
, boolean isRejectedType
, boolean isConservedType
) {
263 NameTypeDesignation td
= new NameTypeDesignation(this, typeSpecies
, citation
, citationMicroReference
, originalNameString
, isRejectedType
, isConservedType
);
265 public void addTypeDesignation(Specimen typeSpecimen
, TypeDesignationStatus status
, ReferenceBase citation
, String citationMicroReference
, String originalNameString
) {
266 this.homotypicalGroup
.addTypeDesignation(typeSpecimen
, status
, citation
, citationMicroReference
, originalNameString
);
268 public void removeTypeDesignation(NameTypeDesignation typeDesignation
) {
269 this.nameTypeDesignations
.remove(typeDesignation
);
271 public void removeTypeDesignation(SpecimenTypeDesignation typeDesignation
) {
272 this.homotypicalGroup
.removeTypeDesignation(typeDesignation
);
277 @Cascade({CascadeType
.SAVE_UPDATE
})
278 public HomotypicalGroup
getHomotypicalGroup() {
279 return homotypicalGroup
;
281 public void setHomotypicalGroup(HomotypicalGroup newHomotypicalGroup
) {
282 if(this.homotypicalGroup
== newHomotypicalGroup
) return;
283 if (homotypicalGroup
!= null) {
284 homotypicalGroup
.typifiedNames
.remove(this);
286 if (newHomotypicalGroup
!= null) {
287 newHomotypicalGroup
.typifiedNames
.add(this);
289 this.homotypicalGroup
= newHomotypicalGroup
;
293 public StrictReferenceBase
getCitation(){
298 public String
getCitationString(){
303 public String
[] getProblems(){
308 * returns year of according nomenclatural reference, null if nomenclatural
309 * reference does not exist
312 public String
getYear(){
318 * Return a set of taxa that use this name
322 public Set
<Taxon
> getTaxa(){
323 // TODO: implement this method via bidirectional TaxonBase-NameBase relation or use a DAO instead
327 * Return a set of synonyms that use this name
331 public Set
<Synonym
> getSynonyms(){
332 // TODO: implement this method via bidirectional TaxonBase-NameBase relation or use a DAO instead
337 public Set
<SpecimenTypeDesignation
> getSpecimenTypeDesignations() {
338 return this.getHomotypicalGroup().getTypeDesignations();
341 // Rank comparison shortcuts
343 public boolean isSupraGeneric() {
344 return getRank().isSupraGeneric();
347 public boolean isGenus() {
348 return getRank().isGenus();
351 public boolean isInfraGeneric() {
352 return getRank().isInfraGeneric();
355 public boolean isSpecies() {
356 return getRank().isSpecies();
359 public boolean isInfraSpecific() {
360 return getRank().isInfraSpecific();
363 public boolean isSupraGeneric(Rank rank
) {
364 return getRank().isHigher(rank
);