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
;
12 import java
.lang
.reflect
.Method
;
14 import javax
.persistence
.Entity
;
15 import javax
.persistence
.FetchType
;
16 import javax
.persistence
.JoinColumn
;
17 import javax
.persistence
.ManyToOne
;
18 import javax
.persistence
.Transient
;
19 import javax
.validation
.constraints
.NotNull
;
20 import javax
.xml
.bind
.annotation
.XmlAccessType
;
21 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
22 import javax
.xml
.bind
.annotation
.XmlAttribute
;
23 import javax
.xml
.bind
.annotation
.XmlElement
;
24 import javax
.xml
.bind
.annotation
.XmlIDREF
;
25 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
26 import javax
.xml
.bind
.annotation
.XmlType
;
28 import org
.apache
.log4j
.Logger
;
29 import org
.hibernate
.annotations
.Cascade
;
30 import org
.hibernate
.annotations
.CascadeType
;
31 import org
.hibernate
.annotations
.Index
;
32 import org
.hibernate
.annotations
.Table
;
33 import org
.hibernate
.envers
.Audited
;
34 import org
.hibernate
.search
.annotations
.IndexedEmbedded
;
36 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
37 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
38 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
40 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
41 import eu
.etaxonomy
.cdm
.validation
.Level2
;
42 import eu
.etaxonomy
.cdm
.validation
.Level3
;
43 import eu
.etaxonomy
.cdm
.validation
.annotation
.TaxonNameCannotBeAcceptedAndSynonym
;
46 * The upmost (abstract) class for the use of a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} in a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference}
47 * or within a taxonomic view/treatment either as a {@link Taxon taxon}
48 * ("accepted" respectively "correct" name) or as a (junior) {@link Synonym synonym}.
49 * Within a taxonomic view/treatment or a reference a taxon name can be used
50 * only in one of both described meanings. The reference using the taxon name
51 * is generally cited with "sec." (secundum, sensu). For instance:
52 * "<i>Juncus longirostris</i> Kuvaev sec. Kirschner, J. et al. 2002".
54 * This class corresponds to: <ul>
55 * <li> TaxonConcept according to the TDWG ontology
56 * <li> TaxonConcept according to the TCS
61 * @created 08-Nov-2007 13:06:56
63 @XmlAccessorType(XmlAccessType
.FIELD
)
64 @XmlType(name
= "TaxonBase", propOrder
= {
73 @Table(appliesTo
="TaxonBase", indexes
= { @Index(name
= "taxonBaseTitleCacheIndex", columnNames
= { "titleCache" }) })
74 @TaxonNameCannotBeAcceptedAndSynonym(groups
= Level3
.class)
75 public abstract class TaxonBase
<S
extends IIdentifiableEntityCacheStrategy
> extends IdentifiableEntity
<S
> {
76 private static final long serialVersionUID
= -3589185949928938529L;
77 private static final Logger logger
= Logger
.getLogger(TaxonBase
.class);
79 private static Method methodTaxonNameAddTaxonBase
;
83 methodTaxonNameAddTaxonBase
= TaxonNameBase
.class.getDeclaredMethod("addTaxonBase", TaxonBase
.class);
84 methodTaxonNameAddTaxonBase
.setAccessible(true);
85 } catch (Exception e
) {
87 for(StackTraceElement ste
: e
.getStackTrace()) {
93 //The assignment to the Taxon or to the Synonym class is not definitive
94 @XmlAttribute(name
= "isDoubtful")
95 private boolean doubtful
;
97 @XmlElement(name
= "Name", required
= true)
99 @XmlSchemaType(name
= "IDREF")
100 @ManyToOne(fetch
= FetchType
.LAZY
)
101 @JoinColumn(name
="taxonName_fk")
103 @Cascade(CascadeType
.SAVE_UPDATE
)
104 @NotNull(groups
= Level2
.class)
105 private TaxonNameBase name
;
107 // The concept reference
108 @XmlElement(name
= "Sec")
110 @XmlSchemaType(name
= "IDREF")
111 @ManyToOne(fetch
= FetchType
.LAZY
)
113 @Cascade(CascadeType
.SAVE_UPDATE
)
114 @NotNull(groups
= Level2
.class)
115 private ReferenceBase sec
;
118 @XmlElement(name
= "AppendedPhrase")
119 private String appendedPhrase
;
121 @XmlAttribute(name
= "UseNameCache")
122 private boolean useNameCache
= false;
125 // ************* CONSTRUCTORS *************/
127 * Class constructor: creates a new empty (abstract) taxon.
129 * @see #TaxonBase(TaxonNameBase, ReferenceBase)
131 protected TaxonBase(){
136 * Class constructor: creates a new (abstract) taxon with the
137 * {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used and the {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference}
140 * @param taxonNameBase the taxon name used
141 * @param sec the reference using the taxon name
144 protected TaxonBase(TaxonNameBase taxonNameBase
, ReferenceBase sec
){
146 if (taxonNameBase
!= null){
147 this.invokeSetMethod(methodTaxonNameAddTaxonBase
, taxonNameBase
);
152 //********* METHODS **************************************/
155 * Generates and returns the string with the full scientific name (including
156 * authorship) of the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used in <i>this</i>
157 * (abstract) taxon as well as the title of the {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference} using
158 * this taxon name. This string may be stored in the inherited
159 * {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} attribute.
160 * This method overrides the generic and inherited generateTitle() method
161 * from {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity IdentifiableEntity}.
163 * @return the string with the full scientific name of the taxon name
164 * and with the title of the reference involved in <i>this</i> (abstract) taxon
165 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
166 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
169 // public String generateTitle() {
171 // if (name != null && name.getTitleCache() != null){
172 // title = name.getTitleCache() + " sec. ";
174 // title += sec.getTitleCache();
179 // title = this.toString();
185 * Returns the {@link TaxonNameBase taxon name} used in <i>this</i> (abstract) taxon.
187 public TaxonNameBase
getName(){
194 public void setName(TaxonNameBase name
) {
196 name
.getTaxonBases().add(this);
202 * Returns the {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup homotypical group} of the
203 * {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used in <i>this</i> (abstract) taxon.
206 public HomotypicalGroup
getHomotypicGroup(){
207 if (this.getName() == null){
210 return this.getName().getHomotypicalGroup();
215 * Returns the boolean value indicating whether the assignment of <i>this</i>
216 * (abstract) taxon to the {@link Taxon Taxon} or to the {@link Synonym Synonym} class is definitive
217 * (false) or not (true). If this flag is set the use of <i>this</i> (abstract)
218 * taxon as an "accepted/correct" name or as a (junior) "synonym" might
219 * still change in the course of taxonomical working process.
221 public boolean isDoubtful(){
222 return this.doubtful
;
227 public void setDoubtful(boolean doubtful
){
228 this.doubtful
= doubtful
;
232 * Returns the {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference} of <i>this</i> (abstract) taxon.
233 * This is the reference or the treatment using the {@link TaxonNameBase taxon name}
234 * in <i>this</i> (abstract) taxon.
236 public ReferenceBase
getSec() {
243 public void setSec(ReferenceBase sec
) {
250 * An appended phrase is a phrase that is added to the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}
251 * 's title cache to be used just in this taxon. E.g. the phrase "sensu latu" may be added
252 * to the name to describe this taxon more precisely.
253 * If {@link #isUseNameCache()}
254 * @return the appendedPhrase
256 public String
getAppendedPhrase() {
257 return appendedPhrase
;
261 * @param appendedPhrase the appendedPhrase to set
263 public void setAppendedPhrase(String appendedPhrase
) {
264 this.appendedPhrase
= appendedPhrase
;
268 * @return the useNameCache
270 public boolean isUseNameCache() {
275 * @param useNameCache the useNameCache to set
277 public void setUseNameCache(boolean useNameCache
) {
278 this.useNameCache
= useNameCache
;
282 * Returns the boolean value indicating whether <i>this</i> (abstract) taxon
283 * might be saved (true) or not (false). An (abstract) taxon is meaningful
284 * as long as both its {@link #getName() taxon name} and its {@link #getSec() reference}
285 * exist (are not "null").
286 * FIXME This should be part of a more generic validation architecture
290 public boolean isSaveable(){
291 if ( (this.getName() == null) || (this.getSec() == null) ){