Project

General

Profile

Download (9.53 KB) Statistics
| Branch: | Tag: | Revision:
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.taxon;
11

    
12
import java.lang.reflect.Method;
13

    
14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.ManyToOne;
17
import javax.persistence.Transient;
18
import javax.validation.constraints.NotNull;
19
import javax.xml.bind.annotation.XmlAccessType;
20
import javax.xml.bind.annotation.XmlAccessorType;
21
import javax.xml.bind.annotation.XmlAttribute;
22
import javax.xml.bind.annotation.XmlElement;
23
import javax.xml.bind.annotation.XmlIDREF;
24
import javax.xml.bind.annotation.XmlSchemaType;
25
import javax.xml.bind.annotation.XmlType;
26

    
27
import org.apache.log4j.Logger;
28
import org.hibernate.annotations.Cascade;
29
import org.hibernate.annotations.CascadeType;
30
import org.hibernate.annotations.Index;
31
import org.hibernate.annotations.Table;
32
import org.hibernate.envers.Audited;
33
import org.hibernate.search.annotations.IndexedEmbedded;
34

    
35
import org.springframework.security.access.prepost.PreFilter;
36

    
37
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
38
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
39
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
40
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
41
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
42
import eu.etaxonomy.cdm.model.reference.Reference;
43
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
44
import eu.etaxonomy.cdm.validation.Level2;
45
import eu.etaxonomy.cdm.validation.Level3;
46
import eu.etaxonomy.cdm.validation.annotation.TaxonNameCannotBeAcceptedAndSynonym;
47

    
48
/**
49
 * 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.Reference reference}
50
 * or within a taxonomic view/treatment either as a {@link Taxon taxon}
51
 * ("accepted" respectively "correct" name) or as a (junior) {@link Synonym synonym}.
52
 * Within a taxonomic view/treatment or a reference a taxon name can be used
53
 * only in one of both described meanings. The reference using the taxon name
54
 * is generally cited with "sec." (secundum, sensu). For instance:
55
 * "<i>Juncus longirostris</i> Kuvaev sec. Kirschner, J. et al. 2002".
56
 * <P>
57
 * This class corresponds to: <ul>
58
 * <li> TaxonConcept according to the TDWG ontology
59
 * <li> TaxonConcept according to the TCS
60
 * </ul>
61
 * 
62
 * @author m.doering
63
 * @version 1.0
64
 * @created 08-Nov-2007 13:06:56
65
 */
66
@XmlAccessorType(XmlAccessType.FIELD)
67
@XmlType(name = "TaxonBase", propOrder = {
68
    "name",
69
    "sec",
70
    "doubtful",
71
    "appendedPhrase",
72
    "useNameCache"
73
})
74
@Entity
75
@Audited
76
//@PreFilter("hasPermission(filterObject, 'edit')")
77
@Table(appliesTo="TaxonBase", indexes = { @Index(name = "taxonBaseTitleCacheIndex", columnNames = { "titleCache" }) })
78
@TaxonNameCannotBeAcceptedAndSynonym(groups = Level3.class)
79
public abstract class TaxonBase<S extends IIdentifiableEntityCacheStrategy> extends IdentifiableEntity<S> implements Cloneable {
80
	private static final long serialVersionUID = -3589185949928938529L;
81
	private static final Logger logger = Logger.getLogger(TaxonBase.class);
82
	
83
	private static Method methodTaxonNameAddTaxonBase;
84
	
85
	static {
86
		try {
87
			methodTaxonNameAddTaxonBase = TaxonNameBase.class.getDeclaredMethod("addTaxonBase", TaxonBase.class);
88
			methodTaxonNameAddTaxonBase.setAccessible(true);
89
		} catch (Exception e) {
90
			logger.error(e);
91
			for(StackTraceElement ste : e.getStackTrace()) {
92
				logger.error(ste);
93
			}
94
		}
95
	}
96
	
97
	//The assignment to the Taxon or to the Synonym class is not definitive
98
    @XmlAttribute(name = "isDoubtful")
99
	private boolean doubtful;
100
	
101
    @XmlElement(name = "Name", required = true)
102
    @XmlIDREF
103
    @XmlSchemaType(name = "IDREF")
104
    @ManyToOne(fetch = FetchType.LAZY)
105
//	@JoinColumn(name="name_id")
106
	@IndexedEmbedded
107
	@Cascade(CascadeType.SAVE_UPDATE)
108
	@NotNull(groups = Level2.class)
109
	private TaxonNameBase name;
110
	
111
	// The concept reference
112
    @XmlElement(name = "Sec")
113
    @XmlIDREF
114
    @XmlSchemaType(name = "IDREF")
115
    @ManyToOne(fetch = FetchType.LAZY)
116
    @IndexedEmbedded
117
    @Cascade(CascadeType.SAVE_UPDATE)
118
    @NotNull(groups = Level2.class)
119
	private Reference sec;
120

    
121
	
122
	@XmlElement(name = "AppendedPhrase")
123
	private String appendedPhrase;
124

    
125
	@XmlAttribute(name= "UseNameCache")
126
	private boolean useNameCache = false;
127
    
128
	
129
// ************* CONSTRUCTORS *************/	
130
	/** 
131
	 * Class constructor: creates a new empty (abstract) taxon.
132
	 * 
133
	 * @see 	#TaxonBase(TaxonNameBase, Reference)
134
	 */
135
	protected TaxonBase(){
136
		super();
137
	}
138
	
139
	/** 
140
	 * Class constructor: creates a new (abstract) taxon with the
141
	 * {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used and the {@link eu.etaxonomy.cdm.model.reference.Reference reference}
142
	 * using it.
143
	 * 
144
	 * @param  taxonNameBase	the taxon name used
145
	 * @param  sec				the reference using the taxon name
146
	 * @see    #TaxonBase()
147
	 */
148
	protected TaxonBase(TaxonNameBase taxonNameBase, Reference sec){
149
		super();
150
		if (taxonNameBase != null){
151
			this.invokeSetMethod(methodTaxonNameAddTaxonBase, taxonNameBase);  
152
		}
153
		this.setSec(sec);
154
	}
155

    
156
//********* METHODS **************************************/
157

    
158
	/**
159
	 * Generates and returns the string with the full scientific name (including
160
	 * authorship) of the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used in <i>this</i>
161
	 * (abstract) taxon as well as the title of the {@link eu.etaxonomy.cdm.model.reference.Reference reference} using
162
	 * this taxon name. This string may be stored in the inherited
163
	 * {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} attribute.
164
	 * This method overrides the generic and inherited generateTitle() method
165
	 * from {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity IdentifiableEntity}.
166
	 *
167
	 * @return  the string with the full scientific name of the taxon name
168
	 *			and with the title of the reference involved in <i>this</i> (abstract) taxon
169
	 * @see  	eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
170
	 * @see  	eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
171
	 */
172
//	@Override
173
//	public String generateTitle() {
174
//		String title;
175
//		if (name != null && name.getTitleCache() != null){
176
//			title = name.getTitleCache() + " sec. ";
177
//			if (sec != null){
178
//				title += sec.getTitleCache();
179
//			}else{
180
//				title += "???";
181
//			}
182
//		}else{
183
//			title = this.toString();
184
//		}
185
//		return title;
186
//	}
187
	
188
	/** 
189
	 * Returns the {@link TaxonNameBase taxon name} used in <i>this</i> (abstract) taxon.
190
	 */
191
	public TaxonNameBase getName(){
192
		return this.name;
193
	}
194
	
195
	/* 
196
	 * @see #getName
197
	 */
198
	public void setName(TaxonNameBase name) {
199
		if(name != null) {
200
			name.getTaxonBases().add(this);
201
		}
202
		this.name = name;
203
	}
204
	
205
	/** 
206
	 * Returns the {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup homotypical group} of the
207
	 * {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} used in <i>this</i> (abstract) taxon.
208
	 */
209
	@Transient
210
	public HomotypicalGroup getHomotypicGroup(){
211
		if (this.getName() == null){
212
			return null;
213
		}else{
214
			return this.getName().getHomotypicalGroup();
215
		}
216
	}
217

    
218
	/**
219
	 * Returns the boolean value indicating whether the assignment of <i>this</i>
220
	 * (abstract) taxon to the {@link Taxon Taxon} or to the {@link Synonym Synonym} class is definitive
221
	 * (false) or not (true). If this flag is set the use of <i>this</i> (abstract)
222
	 * taxon as an "accepted/correct" name or as a (junior) "synonym" might
223
	 * still change in the course of taxonomical working process. 
224
	 */
225
	public boolean isDoubtful(){
226
		return this.doubtful;
227
	}
228
	/**
229
	 * @see  #isDoubtful()
230
	 */
231
	public void setDoubtful(boolean doubtful){
232
		this.doubtful = doubtful;
233
	}
234

    
235
	/** 
236
	 * Returns the {@link eu.etaxonomy.cdm.model.reference.Reference reference} of <i>this</i> (abstract) taxon.
237
	 * This is the reference or the treatment using the {@link TaxonNameBase taxon name}
238
	 * in <i>this</i> (abstract) taxon.
239
	 */
240
	public Reference getSec() {
241
		return sec;
242
	}
243

    
244
	/**
245
	 * @see  #getSec()
246
	 */
247
	public void setSec(Reference sec) {
248
		this.sec = sec;
249
	}
250
	
251
	
252
	
253
	/**
254
	 * An appended phrase is a phrase that is added to the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}
255
	 * 's title cache to be used just in this taxon. E.g. the phrase "sensu latu" may be added
256
	 * to the name to describe this taxon more precisely.
257
	 * If {@link #isUseNameCache()} 
258
	 * @return the appendedPhrase
259
	 */
260
	public String getAppendedPhrase() {
261
		return appendedPhrase;
262
	}
263

    
264
	/**
265
	 * @param appendedPhrase the appendedPhrase to set
266
	 */
267
	public void setAppendedPhrase(String appendedPhrase) {
268
		this.appendedPhrase = appendedPhrase;
269
	}
270

    
271
	/**
272
	 * @return the useNameCache
273
	 */
274
	public boolean isUseNameCache() {
275
		return useNameCache;
276
	}
277

    
278
	/**
279
	 * @param useNameCache the useNameCache to set
280
	 */
281
	public void setUseNameCache(boolean useNameCache) {
282
		this.useNameCache = useNameCache;
283
	}
284
//*********************** CLONE ********************************************************/
285
	
286
	/** 
287
	 * Clones <i>this</i> taxon. This is a shortcut that enables to create
288
	 * a new instance with empty taxon name and sec reference.
289
	 *  
290
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
291
	 * @see java.lang.Object#clone()
292
	 */
293
	@Override
294
	public Object clone() {
295
		TaxonBase result;
296
		try {
297
			result = (TaxonBase)super.clone();
298
			result.setSec(null);
299
			
300
			return result;
301
		} catch (CloneNotSupportedException e) {
302
			logger.warn("Object does not implement cloneable");
303
			e.printStackTrace();
304
			return null;
305
		}
306
		
307
		
308
	}
309

    
310
}
(9-9/16)