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
.taxon
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.hibernate
.annotations
.Cascade
;
15 import org
.hibernate
.annotations
.CascadeType
;
17 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
22 import javax
.persistence
.*;
27 * @created 08-Nov-2007 13:06:55
30 public class Synonym
extends TaxonBase
{
31 static Logger logger
= Logger
.getLogger(Synonym
.class);
33 private Set
<SynonymRelationship
> synonymRelations
= new HashSet
<SynonymRelationship
>();
36 public static Synonym
NewInstance(TaxonNameBase taxonName
, ReferenceBase sec
){
37 Synonym result
= new Synonym();
38 result
.setName(taxonName
);
43 //TODO should be private, but still produces Spring init errors
48 @OneToMany(mappedBy
="synonym")
49 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.DELETE
})
50 public Set
<SynonymRelationship
> getSynonymRelations() {
51 return synonymRelations
;
53 protected void setSynonymRelations(Set
<SynonymRelationship
> synonymRelations
) {
54 this.synonymRelations
= synonymRelations
;
56 protected void addSynonymRelation(SynonymRelationship synonymRelation
) {
57 this.synonymRelations
.add(synonymRelation
);
59 protected void removeSynonymRelation(SynonymRelationship synonymRelation
) {
60 synonymRelation
.setSynonym(null);
61 Taxon taxon
= synonymRelation
.getAcceptedTaxon();
63 synonymRelation
.setAcceptedTaxon(null);
64 taxon
.removeSynonymRelation(synonymRelation
);
66 this.synonymRelations
.remove(synonymRelation
);
71 public Set
<Taxon
> getAcceptedTaxa() {
72 Set
<Taxon
>taxa
=new HashSet
<Taxon
>();
73 for (SynonymRelationship rel
:getSynonymRelations()){
74 taxa
.add(rel
.getAcceptedTaxon());
80 * Return the synonymy relationship type for the relation to a given accepted taxon.
81 * If taxon is null or no relation exists to that taxon null is returned.
86 public SynonymRelationshipType
getRelationType(Taxon taxon
){
90 for (SynonymRelationship rel
:getSynonymRelations()){
91 Taxon acceptedTaxon
= rel
.getAcceptedTaxon();
92 if (taxon
.equals(acceptedTaxon
)){