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
;
68 protected boolean protectedNameCache
;
70 protected INameCacheStrategy cacheStrategy
;
73 // * Returns a TaxonNameBase instance
76 // abstract public static TaxonNameBase PARSED_NAME(String fullName);
78 // ************* CONSTRUCTORS *************/
79 public TaxonNameBase() {
82 public TaxonNameBase(Rank rank
) {
85 public TaxonNameBase(HomotypicalGroup homotypicalGroup
) {
86 this(null, homotypicalGroup
);
88 public TaxonNameBase(Rank rank
, HomotypicalGroup homotypicalGroup
) {
91 if (homotypicalGroup
== null){
92 homotypicalGroup
= new HomotypicalGroup();
94 homotypicalGroup
.addTypifiedName(this);
97 //********* METHODS **************************************/
99 protected String
generateNameCache(){
100 if (cacheStrategy
== null){
101 logger
.warn("No CacheStrategy defined for taxonName: " + this.toString());
104 return cacheStrategy
.getNameCache(this);
108 public String
getNameCache() {
109 if (protectedNameCache
){
110 return this.nameCache
;
112 // is title dirty, i.e. equal NULL?
113 if (nameCache
== null){
114 this.nameCache
= generateNameCache();
119 public void setNameCache(String nameCache
){
120 this.nameCache
= nameCache
;
121 // TODO this.setProtectedNameCache(true);
127 public abstract boolean isCodeCompliant();
131 public Set
<NameRelationship
> getNameRelations() {
132 Set
<NameRelationship
> rels
= new HashSet
<NameRelationship
>();
133 rels
.addAll(getRelationsFromThisName());
134 rels
.addAll(getRelationsToThisName());
138 * Add a name relationship to both names involved
141 public void addRelationshipToName(TaxonNameBase toName
, NameRelationshipType type
, String ruleConsidered
){
142 NameRelationship rel
= new NameRelationship(toName
, this, type
, ruleConsidered
);
144 public void addRelationshipFromName(TaxonNameBase fromName
, NameRelationshipType type
, String ruleConsidered
){
145 NameRelationship rel
= new NameRelationship(this, fromName
, type
, ruleConsidered
);
147 protected void addNameRelationship(NameRelationship rel
) {
148 if (rel
!=null && rel
.getToName().equals(this)){
149 this.relationsToThisName
.add(rel
);
150 }else if(rel
!=null && rel
.getFromName().equals(this)){
151 this.relationsFromThisName
.add(rel
);
153 //TODO: raise error???
156 public void removeNameRelationship(NameRelationship nameRelation
) {
157 this.relationsToThisName
.remove(nameRelation
);
158 this.relationsFromThisName
.remove(nameRelation
);
162 @OneToMany(mappedBy
="fromName")
163 @Cascade({CascadeType
.SAVE_UPDATE
})
164 public Set
<NameRelationship
> getRelationsFromThisName() {
165 return relationsFromThisName
;
167 private void setRelationsFromThisName(Set
<NameRelationship
> relationsFromThisName
) {
168 this.relationsFromThisName
= relationsFromThisName
;
171 @OneToMany(mappedBy
="toName")
172 @Cascade({CascadeType
.SAVE_UPDATE
})
173 public Set
<NameRelationship
> getRelationsToThisName() {
174 return relationsToThisName
;
176 private void setRelationsToThisName(Set
<NameRelationship
> relationsToThisName
) {
177 this.relationsToThisName
= relationsToThisName
;
183 @Cascade({CascadeType
.SAVE_UPDATE
})
184 public Set
<NomenclaturalStatus
> getStatus() {
187 protected void setStatus(Set
<NomenclaturalStatus
> nomStatus
) {
188 this.status
= nomStatus
;
190 public void addStatus(NomenclaturalStatus nomStatus
) {
191 this.status
.add(nomStatus
);
193 public void removeStatus(NomenclaturalStatus nomStatus
) {
194 this.status
.remove(nomStatus
);
199 public T
getBasionym(){
200 //TODO: pick the right name relationships...
203 public void setBasionym(T basionym
){
204 setBasionym(basionym
, null);
206 public void setBasionym(T basionym
, String ruleConsidered
){
207 basionym
.addRelationshipToName(this, NameRelationshipType
.BASIONYM(), null);
214 public INameCacheStrategy
getCacheStrategy() {
215 return cacheStrategy
;
217 public void setCacheStrategy(INameCacheStrategy cacheStrategy
) {
218 this.cacheStrategy
= cacheStrategy
;
222 //@Cascade({CascadeType.SAVE_UPDATE})
223 public Rank
getRank(){
226 public void setRank(Rank rank
){
231 @Cascade({CascadeType
.SAVE_UPDATE
})
232 public ReferenceBase
getNomenclaturalReference(){
233 return (ReferenceBase
) this.nomenclaturalReference
;
235 public void setNomenclaturalReference(INomenclaturalReference nomenclaturalReference
){
236 this.nomenclaturalReference
= nomenclaturalReference
;
240 public String
getAppendedPhrase(){
241 return this.appendedPhrase
;
243 public void setAppendedPhrase(String appendedPhrase
){
244 this.appendedPhrase
= appendedPhrase
;
247 public String
getNomenclaturalMicroReference(){
248 return this.nomenclaturalMicroReference
;
250 public void setNomenclaturalMicroReference(String nomenclaturalMicroReference
){
251 this.nomenclaturalMicroReference
= nomenclaturalMicroReference
;
254 public boolean getHasProblem(){
255 return this.hasProblem
;
257 public void setHasProblem(boolean hasProblem
){
258 this.hasProblem
= hasProblem
;
263 //TODO @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
264 @Cascade(CascadeType
.SAVE_UPDATE
)
265 public Set
<NameTypeDesignation
> getNameTypeDesignations() {
266 return nameTypeDesignations
;
268 protected void setNameTypeDesignations(Set
<NameTypeDesignation
> nameTypeDesignations
) {
269 this.nameTypeDesignations
= nameTypeDesignations
;
272 public void addTypeDesignation(TaxonNameBase typeSpecies
, ReferenceBase citation
, String citationMicroReference
, String originalNameString
, boolean isRejectedType
, boolean isConservedType
) {
273 NameTypeDesignation td
= new NameTypeDesignation(this, typeSpecies
, citation
, citationMicroReference
, originalNameString
, isRejectedType
, isConservedType
);
275 public void addTypeDesignation(Specimen typeSpecimen
, TypeDesignationStatus status
, ReferenceBase citation
, String citationMicroReference
, String originalNameString
) {
276 this.homotypicalGroup
.addTypeDesignation(typeSpecimen
, status
, citation
, citationMicroReference
, originalNameString
);
278 public void removeTypeDesignation(NameTypeDesignation typeDesignation
) {
279 this.nameTypeDesignations
.remove(typeDesignation
);
281 public void removeTypeDesignation(SpecimenTypeDesignation typeDesignation
) {
282 this.homotypicalGroup
.removeTypeDesignation(typeDesignation
);
287 @Cascade({CascadeType
.SAVE_UPDATE
})
288 public HomotypicalGroup
getHomotypicalGroup() {
289 return homotypicalGroup
;
291 public void setHomotypicalGroup(HomotypicalGroup newHomotypicalGroup
) {
292 if(this.homotypicalGroup
== newHomotypicalGroup
) return;
293 if (homotypicalGroup
!= null) {
294 homotypicalGroup
.typifiedNames
.remove(this);
296 if (newHomotypicalGroup
!= null) {
297 newHomotypicalGroup
.typifiedNames
.add(this);
299 this.homotypicalGroup
= newHomotypicalGroup
;
303 public StrictReferenceBase
getCitation(){
304 logger
.warn("getCitation not yet implemented");
309 public String
getCitationString(){
310 logger
.warn("getCitationString not yet implemented");
315 public String
[] getProblems(){
316 logger
.warn("getProblems not yet implemented");
321 * returns year of according nomenclatural reference, null if nomenclatural
322 * reference does not exist
325 public String
getReferenceYear(){
326 if (this.getNomenclaturalReference() != null ){
327 return this.getNomenclaturalReference().getYear();
333 @OneToMany(mappedBy
="name", fetch
= FetchType
.EAGER
)
334 public Set
<TaxonBase
> getTaxonBases() {
335 return this.taxonBases
;
337 protected void setTaxonBases(Set
<TaxonBase
> taxonBases
) {
338 if (taxonBases
== null){
339 taxonBases
= new HashSet
<TaxonBase
>();
341 this.taxonBases
= taxonBases
;
344 // public void addSynonym(Synonym synonym) {
345 // synonym.setName(this);
347 // public void removeSynonym(Synonym synonym) {
348 // synonym.setName(null);
352 * Return a set of taxa that use this name
356 public Set
<Taxon
> getTaxa(){
357 Set
<Taxon
> result
= new HashSet
<Taxon
>();
358 for (TaxonBase taxonBase
: this.taxonBases
){
359 if (taxonBase
instanceof Taxon
){
360 result
.add((Taxon
)taxonBase
);
367 * Return a set of synonyms that use this name
370 // TODO: implement this method via bidirectional TaxonBase-NameBase relation or use a DAO instead
374 public Set
<Synonym
> getSynonyms() {
375 Set
<Synonym
> result
= new HashSet
<Synonym
>();
376 for (TaxonBase taxonBase
: this.taxonBases
){
377 if (taxonBase
instanceof Synonym
){
378 result
.add((Synonym
)taxonBase
);
385 public Set
<SpecimenTypeDesignation
> getSpecimenTypeDesignations() {
386 return this.getHomotypicalGroup().getTypeDesignations();
389 // Rank comparison shortcuts
391 public boolean isSupraGeneric() {
392 return getRank().isSupraGeneric();
395 public boolean isGenus() {
396 return getRank().isGenus();
399 public boolean isInfraGeneric() {
400 return getRank().isInfraGeneric();
403 public boolean isSpecies() {
404 return getRank().isSpecies();
407 public boolean isInfraSpecific() {
408 return getRank().isInfraSpecific();