(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / TaxonNameBase.java
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.common.IdentifiableEntity;
18 import eu.etaxonomy.cdm.model.common.IReferencedEntity;
19 import org.apache.log4j.Logger;
20 import org.hibernate.annotations.Cascade;
21 import org.hibernate.annotations.CascadeType;
22
23 import eu.etaxonomy.cdm.strategy.INameCacheStrategy;
24
25 import java.util.*;
26
27 import javax.persistence.*;
28
29 /**
30 * The upmost (abstract) class for scientific taxon names regardless of the any
31 * particular nomenclatural code. The scientific name including author strings and
32 * maybe year is stored in IdentifiableEntity.titleCache
33 * @author m.doering
34 * @version 1.0
35 * @created 08-Nov-2007 13:06:57
36 */
37 @Entity
38 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
39 public abstract class TaxonNameBase extends IdentifiableEntity<TaxonNameBase> implements IReferencedEntity {
40 static Logger logger = Logger.getLogger(TaxonNameBase.class);
41 //The scientific name without author strings and year
42 private String nameCache;
43 //Non-atomised addition to a name not ruled by a nomenclatural code
44 private String appendedPhrase;
45 //Details of the nomenclatural reference (protologue). These are mostly (implicitly) pages but can also be figures or
46 //tables or any other element of a publication. {only if a nomenclatural reference exists}
47 private String nomenclaturalMicroReference;
48 //this flag will be set to true if the parseName method was unable to successfully parse the name
49 private boolean hasProblem = false;
50 protected Set<NameTypeDesignation> nameTypeDesignations = new HashSet();
51 private HomotypicalGroup homotypicalGroup = new HomotypicalGroup();
52 private Set<NameRelationship> nameRelations = new HashSet();
53 private Set<NomenclaturalStatus> status = new HashSet();
54 private Rank rank;
55 //if set, the Reference.isNomenclaturallyRelevant flag should be set to true!
56 private INomenclaturalReference nomenclaturalReference;
57 private Set<TaxonNameBase> newCombinations = new HashSet();
58 // bidrectional with newCombinations. Keep congruent
59 private TaxonNameBase basionym;
60
61 protected INameCacheStrategy cacheStrategy;
62
63
64 // CONSTRUCTORS
65 public TaxonNameBase() {
66 super();
67 }
68 public TaxonNameBase(Rank rank) {
69 super();
70 this.setRank(rank);
71 }
72
73
74 public String getNameCache() {
75 return nameCache;
76 }
77 public void setNameCache(String nameCache) {
78 this.nameCache = nameCache;
79 }
80
81
82 @Transient
83 public abstract boolean isCodeCompliant();
84
85
86 @OneToMany
87 @Cascade({CascadeType.SAVE_UPDATE})
88 public Set<NameRelationship> getNameRelations() {
89 return nameRelations;
90 }
91 protected void setNameRelations(Set<NameRelationship> nameRelations) {
92 this.nameRelations = nameRelations;
93 }
94 public void addNameRelation(NameRelationship nameRelation) {
95 // checks whether this is a normal relation or an inverse one
96 // and adds it to the appropiate set
97 //this.inverseNameRelations
98 this.nameRelations.add(nameRelation);
99 }
100 public void removeNameRelation(NameRelationship nameRelation) {
101 // this.inverseNameRelations
102 this.nameRelations.remove(nameRelation);
103 }
104
105
106 @Transient
107 public Set<NameRelationship> getIncomingNameRelations() {
108 // FIXME: filter relations
109 return nameRelations;
110 }
111 @Transient
112 public Set<NameRelationship> getOutgoingNameRelations() {
113 // FIXME: filter relations
114 return nameRelations;
115 }
116
117
118
119 @OneToMany
120 @Cascade({CascadeType.SAVE_UPDATE})
121 public Set<NomenclaturalStatus> getStatus() {
122 return status;
123 }
124 protected void setStatus(Set<NomenclaturalStatus> status) {
125 this.status = status;
126 }
127 public void addStatus(NomenclaturalStatus status) {
128 this.status.add(status);
129 }
130 public void removeStatus(NomenclaturalStatus status) {
131 this.status.remove(status);
132 }
133
134
135
136 @OneToMany
137 @Cascade({CascadeType.SAVE_UPDATE})
138 public Set<TaxonNameBase> getNewCombinations() {
139 return newCombinations;
140 }
141 protected void setNewCombinations(Set<TaxonNameBase> newCombinations) {
142 this.newCombinations = newCombinations;
143 }
144 public void addNewCombination(TaxonNameBase newCombination) {
145 // TODO: add basionym relation too!
146 this.newCombinations.add(newCombination);
147 }
148 public void removeNewCombination(TaxonNameBase newCombination) {
149 this.newCombinations.remove(newCombination);
150 }
151
152
153 @ManyToOne
154 @Cascade({CascadeType.SAVE_UPDATE})
155 public TaxonNameBase getBasionym(){
156 return this.basionym;
157 }
158 public void setBasionym(TaxonNameBase basionym){
159 // TODO: add newCombination relation too!
160 this.basionym = basionym;
161 }
162
163
164
165 //TODO for PROTOTYPE
166 @Transient
167 public INameCacheStrategy getCacheStrategy() {
168 return cacheStrategy;
169 }
170 public void setCacheStrategy(INameCacheStrategy cacheStrategy) {
171 this.cacheStrategy = cacheStrategy;
172 }
173
174 @ManyToOne
175 @Cascade({CascadeType.SAVE_UPDATE})
176 public Rank getRank(){
177 return this.rank;
178 }
179 public void setRank(Rank rank){
180 this.rank = rank;
181 }
182
183 @ManyToOne
184 @Cascade({CascadeType.SAVE_UPDATE})
185 public ReferenceBase getNomenclaturalReference(){
186 return (ReferenceBase) this.nomenclaturalReference;
187 }
188 public void setNomenclaturalReference(INomenclaturalReference nomenclaturalReference){
189 this.nomenclaturalReference = nomenclaturalReference;
190 }
191
192
193 public String getAppendedPhrase(){
194 return this.appendedPhrase;
195 }
196 public void setAppendedPhrase(String appendedPhrase){
197 this.appendedPhrase = appendedPhrase;
198 }
199
200 public String getNomenclaturalMicroReference(){
201 return this.nomenclaturalMicroReference;
202 }
203 public void setNomenclaturalMicroReference(String nomenclaturalMicroReference){
204 this.nomenclaturalMicroReference = nomenclaturalMicroReference;
205 }
206
207 public boolean getHasProblem(){
208 return this.hasProblem;
209 }
210 public void setHasProblem(boolean hasProblem){
211 this.hasProblem = hasProblem;
212 }
213
214
215 @OneToMany
216 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
217 public Set<NameTypeDesignation> getNameTypeDesignations() {
218 return nameTypeDesignations;
219 }
220 protected void setNameTypeDesignations(Set<NameTypeDesignation> nameTypeDesignations) {
221 this.nameTypeDesignations = nameTypeDesignations;
222 }
223
224 public void addTypeDesignation(TaxonNameBase typeSpecies, ReferenceBase citation, String citationMicroReference, String originalNameString, boolean isRejectedType, boolean isConservedType) {
225 NameTypeDesignation td = new NameTypeDesignation(this, typeSpecies, citation, citationMicroReference, originalNameString, isRejectedType, isConservedType);
226 }
227 public void addTypeDesignation(Specimen typeSpecimen, TypeDesignationStatus status, ReferenceBase citation, String citationMicroReference, String originalNameString) {
228 this.homotypicalGroup.addTypeDesignation(typeSpecimen, status, citation, citationMicroReference, originalNameString);
229 }
230 public void removeTypeDesignation(NameTypeDesignation typeDesignation) {
231 this.nameTypeDesignations.remove(typeDesignation);
232 }
233 public void removeTypeDesignation(SpecimenTypeDesignation typeDesignation) {
234 this.homotypicalGroup.removeTypeDesignation(typeDesignation);
235 }
236
237
238 @ManyToOne
239 @Cascade({CascadeType.SAVE_UPDATE})
240 public HomotypicalGroup getHomotypicalGroup() {
241 return homotypicalGroup;
242 }
243 public void setHomotypicalGroup(HomotypicalGroup newHomotypicalGroup) {
244 if(this.homotypicalGroup == newHomotypicalGroup) return;
245 if (homotypicalGroup != null) {
246 homotypicalGroup.typifiedNames.remove(this);
247 }
248 if (newHomotypicalGroup!= null) {
249 newHomotypicalGroup.typifiedNames.add(this);
250 }
251 this.homotypicalGroup = newHomotypicalGroup;
252 }
253
254 @Transient
255 public StrictReferenceBase getCitation(){
256 return null;
257 }
258
259 @Transient
260 public String getCitationString(){
261 return null;
262 }
263
264 @Transient
265 public String[] getProblems(){
266 return null;
267 }
268
269 /**
270 * returns year of according nomenclatural reference, null if nomenclatural
271 * reference does not exist
272 */
273 @Transient
274 public String getYear(){
275 return "";
276 }
277
278 /**
279 *
280 * @param fullname fullname
281 */
282 public boolean parseName(String fullname){
283 return false;
284 }
285 }