Project

General

Profile

Download (16.1 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.name;
11

    
12

    
13
import java.util.Map;
14

    
15
import javax.persistence.Column;
16
import javax.persistence.Entity;
17
import javax.validation.constraints.Min;
18
import javax.xml.bind.annotation.XmlAccessType;
19
import javax.xml.bind.annotation.XmlAccessorType;
20
import javax.xml.bind.annotation.XmlElement;
21
import javax.xml.bind.annotation.XmlRootElement;
22
import javax.xml.bind.annotation.XmlType;
23

    
24
import org.apache.commons.lang.StringUtils;
25
import org.apache.log4j.Logger;
26
import org.hibernate.envers.Audited;
27
import org.hibernate.search.annotations.Analyze;
28
import org.hibernate.search.annotations.Field;
29
import org.hibernate.search.annotations.Indexed;
30
import org.springframework.beans.factory.annotation.Configurable;
31

    
32
import eu.etaxonomy.cdm.common.CdmUtils;
33
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
34
import eu.etaxonomy.cdm.model.common.CdmBase;
35
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
36
import eu.etaxonomy.cdm.strategy.cache.name.CacheUpdate;
37
import eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy;
38
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
39
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
40
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
41

    
42
/**
43
 * The taxon name class for animals.
44
 * <P>
45
 * This class corresponds to: NameZoological according to the ABCD schema.
46
 *
47
 * @author m.doering
48
 * @version 1.0
49
 * @created 08-Nov-2007 13:07:03
50
 * @see NonViralName
51
 */
52
@XmlAccessorType(XmlAccessType.FIELD)
53
@XmlType(name = "ZoologicalName", propOrder = {
54
    "breed",
55
    "publicationYear",
56
    "originalPublicationYear"
57
})
58
@XmlRootElement(name = "ZoologicalName")
59
@Entity
60
@Indexed(index = "eu.etaxonomy.cdm.model.name.TaxonNameBase")
61
@Audited
62
@Configurable
63
public class ZoologicalName extends NonViralName<ZoologicalName> implements Cloneable{
64
	private static final long serialVersionUID = 845745609734814484L;
65
	@SuppressWarnings("unused")
66
	private static final Logger logger = Logger.getLogger(ZoologicalName.class);
67

    
68
	//Name of the breed of an animal
69
	@XmlElement(name = "Breed")
70
	@Field
71
	@NullOrNotEmpty
72
	@Column(length=255)
73
	private String breed;
74

    
75
	@XmlElement(name = "PublicationYear")
76
	@Field(analyze = Analyze.NO)
77
	@CacheUpdate(value ="authorshipCache")
78
	@Min(0)
79
    private Integer publicationYear;
80

    
81
	@XmlElement(name = "OriginalPublicationYear")
82
	@Field(analyze = Analyze.NO)
83
	@CacheUpdate(value ="authorshipCache")
84
	@Min(0)
85
    private Integer originalPublicationYear;
86

    
87
	static private INonViralNameParser nameParser = new NonViralNameParserImpl();
88

    
89

    
90
	// ************* CONSTRUCTORS *************/
91
	/**
92
	 * Class constructor: creates a new zoological taxon name instance
93
	 * only containing the {@link eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy default cache strategy}.
94
	 *
95
	 * @see #ZoologicalName(Rank, HomotypicalGroup)
96
	 * @see #ZoologicalName(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
97
	 * @see eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy
98
	 */
99
	protected ZoologicalName() {
100
		this.cacheStrategy = ZooNameDefaultCacheStrategy.NewInstance();
101
	}
102

    
103
	/**
104
	 * Class constructor: creates a new zoological taxon name instance
105
	 * only containing its {@link Rank rank},
106
	 * its {@link HomotypicalGroup homotypical group} and
107
	 * the {@link eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy default cache strategy}.
108
	 * The new zoological taxon name instance will be also added to the set of
109
	 * zoological taxon names belonging to the given homotypical group.
110
	 *
111
	 * @param	rank  the rank to be assigned to <i>this</i> zoological taxon name
112
	 * @param	homotypicalGroup  the homotypical group to which <i>this</i> zoological taxon name belongs
113
	 * @see 	#ZoologicalName()
114
	 * @see 	#ZoologicalName(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
115
	 * @see 	eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy
116
	 */
117
	protected ZoologicalName(Rank rank, HomotypicalGroup homotypicalGroup) {
118
		super(rank, homotypicalGroup);
119
		this.cacheStrategy = ZooNameDefaultCacheStrategy.NewInstance();
120
	}
121

    
122
	/**
123
	 * Class constructor: creates a new zoological taxon name instance
124
	 * containing its {@link Rank rank},
125
	 * its {@link HomotypicalGroup homotypical group},
126
	 * its scientific name components, its {@link eu.etaxonomy.cdm.agent.TeamOrPersonBase author(team)},
127
	 * its {@link eu.etaxonomy.cdm.reference.INomenclaturalReference nomenclatural reference} and
128
	 * the {@link eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy default cache strategy}.
129
	 * The new zoological taxon name instance will be also added to the set of
130
	 * zoological taxon names belonging to the given homotypical group.
131
	 *
132
	 * @param	rank  the rank to be assigned to <i>this</i> zoological taxon name
133
	 * @param	genusOrUninomial the string for <i>this</i> zoological taxon name
134
	 * 			if its rank is genus or higher or for the genus part
135
	 * 			if its rank is lower than genus
136
	 * @param	infraGenericEpithet  the string for the first epithet of
137
	 * 			<i>this</i> zoological taxon name if its rank is lower than genus
138
	 * 			and higher than species aggregate
139
	 * @param	specificEpithet  the string for the first epithet of
140
	 * 			<i>this</i> zoological taxon name if its rank is species aggregate or lower
141
	 * @param	infraSpecificEpithet  the string for the second epithet of
142
	 * 			<i>this</i> zoological taxon name if its rank is lower than species
143
	 * @param	combinationAuthorship  the author or the team who published <i>this</i> zoological taxon name
144
	 * @param	nomenclaturalReference  the nomenclatural reference where <i>this</i> zoological taxon name was published
145
	 * @param	nomenclMicroRef  the string with the details for precise location within the nomenclatural reference
146
	 * @param	homotypicalGroup  the homotypical group to which <i>this</i> zoological taxon name belongs
147
	 * @see 	#ZoologicalName()
148
	 * @see 	#ZoologicalName(Rank, HomotypicalGroup)
149
	 * @see		#NewInstance(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
150
	 * @see 	eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy
151
	 * @see 	eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy
152
	 * @see 	eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy
153
	 */
154
	protected ZoologicalName (Rank rank, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorship, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
155
		super(rank, genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet, combinationAuthorship, nomenclaturalReference, nomenclMicroRef, homotypicalGroup);
156
		this.cacheStrategy = ZooNameDefaultCacheStrategy.NewInstance();
157
	}
158

    
159

    
160
	//********* METHODS **************************************/
161

    
162
	/**
163
	 * Creates a new zoological taxon name instance
164
	 * only containing its {@link Rank rank} and
165
	 * the {@link eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy default cache strategy}.
166
	 *
167
	 * @param	rank	the rank to be assigned to <i>this</i> zoological taxon name
168
	 * @see 			#ZoologicalName(Rank, HomotypicalGroup)
169
	 * @see 			#NewInstance(Rank, HomotypicalGroup)
170
	 * @see 			#NewInstance(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
171
	 * @see 			eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy
172
	 */
173
	public static ZoologicalName NewInstance(Rank rank){
174
		return new ZoologicalName(rank, null);
175
	}
176

    
177
	/**
178
	 * Creates a new zoological taxon name instance
179
	 * only containing its {@link Rank rank},
180
	 * its {@link HomotypicalGroup homotypical group} and
181
 	 * the {@link eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy default cache strategy}.
182
	 * The new zoological taxon name instance will be also added to the set of
183
	 * zoological taxon names belonging to the given homotypical group.
184
	 *
185
	 * @param  rank  the rank to be assigned to <i>this</i> zoological taxon name
186
	 * @param  homotypicalGroup  the homotypical group to which <i>this</i> zoological taxon name belongs
187
	 * @see    #NewInstance(Rank)
188
	 * @see    #NewInstance(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
189
	 * @see    #ZoologicalName(Rank, HomotypicalGroup)
190
	 * @see    eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy
191
	 */
192
	public static ZoologicalName NewInstance(Rank rank, HomotypicalGroup homotypicalGroup){
193
		return new ZoologicalName(rank, homotypicalGroup);
194
	}
195
	/**
196
	 * Creates a new zoological taxon name instance
197
	 * containing its {@link Rank rank},
198
	 * its {@link HomotypicalGroup homotypical group},
199
	 * its scientific name components, its {@link eu.etaxonomy.cdm.agent.TeamOrPersonBase author(team)},
200
	 * its {@link eu.etaxonomy.cdm.reference.INomenclaturalReference nomenclatural reference} and
201
	 * the {@link eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy default cache strategy}.
202
	 * The new zoological taxon name instance will be also added to the set of
203
	 * zoological taxon names belonging to the given homotypical group.
204
	 *
205
	 * @param	rank  the rank to be assigned to <i>this</i> zoological taxon name
206
	 * @param	genusOrUninomial the string for <i>this</i> zoological taxon name
207
	 * 			if its rank is genus or higher or for the genus part
208
	 * 			if its rank is lower than genus
209
	 * @param	infraGenericEpithet  the string for the first epithet of
210
	 * 			<i>this</i> zoological taxon name if its rank is lower than genus
211
	 * 			and higher than species aggregate
212
	 * @param	specificEpithet  the string for the first epithet of
213
	 * 			<i>this</i> zoological taxon name if its rank is species aggregate or lower
214
	 * @param	infraSpecificEpithet  the string for the second epithet of
215
	 * 			<i>this</i> zoological taxon name if its rank is lower than species
216
	 * @param	combinationAuthorship  the author or the team who published <i>this</i> zoological taxon name
217
	 * @param	nomenclaturalReference  the nomenclatural reference where <i>this</i> zoological taxon name was published
218
	 * @param	nomenclMicroRef  the string with the details for precise location within the nomenclatural reference
219
	 * @param	homotypicalGroup  the homotypical group to which <i>this</i> zoological taxon name belongs
220
	 * @see 	#NewInstance(Rank)
221
	 * @see 	#NewInstance(Rank, HomotypicalGroup)
222
	 * @see		#ZoologicalName(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
223
	 * @see 	eu.etaxonomy.cdm.strategy.cache.name.ZooNameDefaultCacheStrategy
224
	 */
225
	public static ZoologicalName NewInstance(Rank rank, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorship, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
226
		return new ZoologicalName(rank, genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet, combinationAuthorship, nomenclaturalReference, nomenclMicroRef, homotypicalGroup);
227
	}
228

    
229

    
230
	/**
231
	 * Returns a zoological taxon name based on parsing a string representing
232
	 * all elements (according to the {@link NomenclaturalCode#ICZN() ICZN}) of a zoological taxon name (where
233
	 * the scientific name is an uninomial) including authorship but without
234
	 * nomenclatural reference.
235
	 *
236
	 * @param	fullNameString  the string to be parsed
237
	 * @return					the new zoological taxon name
238
	 */
239
	public static ZoologicalName PARSED_NAME(String fullNameString){
240
		return PARSED_NAME(fullNameString, Rank.GENUS());
241
	}
242

    
243
	/**
244
	 * Returns a zoological taxon name based on parsing a string representing
245
	 * all elements (according to the {@link NomenclaturalCode#ICZN() ICZN})) of a zoological taxon name including
246
	 * authorship but without nomenclatural reference. The parsing result
247
	 * depends on the given rank of the zoological taxon name to be created.
248
	 *
249
	 * @param 	fullNameString  the string to be parsed
250
	 * @param   rank			the rank of the taxon name
251
	 * @return					the new zoological taxon name
252
	 */
253
	public static ZoologicalName PARSED_NAME(String fullNameString, Rank rank){
254
		if (nameParser == null){
255
			nameParser  = new NonViralNameParserImpl();
256
		}
257
		return (ZoologicalName)nameParser.parseFullName(fullNameString, NomenclaturalCode.ICZN, rank);
258
	}
259

    
260
	/**
261
	 * Returns the {@link NomenclaturalCode nomenclatural code} that governs
262
	 * the construction of <i>this</i> zoological taxon name, that is the
263
	 * International Code of Zoological Nomenclature. This method overrides
264
	 * the getNomenclaturalCode method from {@link NonViralName NonViralName}.
265
	 *
266
	 * @return  the nomenclatural code for animals
267
	 * @see  	NonViralName#isCodeCompliant()
268
	 * @see  	NonViralName#getNomenclaturalCode()
269
	 * @see  	TaxonNameBase#getHasProblem()
270
	 */
271
	@Override
272
	public NomenclaturalCode getNomenclaturalCode(){
273
		return NomenclaturalCode.ICZN;
274
	}
275

    
276
//*************** ***************************
277

    
278
	private static Map<String, java.lang.reflect.Field> allFields = null;
279
	@Override
280
    protected Map<String, java.lang.reflect.Field> getAllFields(){
281
    	if (allFields == null){
282
			allFields = CdmUtils.getAllFields(this.getClass(), CdmBase.class, false, false, false, true);
283
		}
284
    	return allFields;
285
    }
286

    
287
/* ***************** GETTER / SETTER ***************************/
288

    
289

    
290

    
291
	/**
292
	 * Returns the breed name string for <i>this</i> animal (zoological taxon name).
293
	 *
294
	 * @return  the string containing the breed name for <i>this</i> zoological taxon name
295
	 */
296
	public String getBreed(){
297
		return this.breed;
298
	}
299
	/**
300
	 * @see  #getBreed()
301
	 */
302
	public void setBreed(String breed){
303
		this.breed = StringUtils.isBlank(breed) ? null : breed;
304
	}
305

    
306
	/**
307
	 * Returns the publication year (as an integer) for <i>this</i> zoological taxon
308
	 * name. If the publicationYear attribute is null and a nomenclatural
309
	 * reference exists the year could be computed from the
310
	 * {@link eu.etaxonomy.cdm.reference.INomenclaturalReference nomenclatural reference}.
311
	 *
312
	 * @return  the integer representing the publication year for <i>this</i> zoological taxon name
313
	 * @see  	#getOriginalPublicationYear()
314
	 */
315
	public Integer getPublicationYear() {
316
		return publicationYear;
317
	}
318
	/**
319
	 * @see  #getPublicationYear()
320
	 */
321
	public void setPublicationYear(Integer publicationYear) {
322
		this.publicationYear = publicationYear;
323
	}
324

    
325
	/**
326
	 * Returns the publication year (as an integer) of the original validly
327
	 * published species epithet for <i>this</i> zoological taxon name. This only
328
	 * applies for zoological taxon names that are no {@link TaxonNameBase#isOriginalCombination() original combinations}.
329
	 * If the originalPublicationYear attribute is null the year could be taken
330
	 * from the publication year of the corresponding original name (basionym)
331
	 * or from the {@link eu.etaxonomy.cdm.reference.INomenclaturalReference nomenclatural reference} of the basionym
332
	 * if it exists.
333
	 *
334
	 * @return  the integer representing the publication year of the original
335
	 * 			species epithet corresponding to <i>this</i> zoological taxon name
336
	 * @see  	#getPublicationYear()
337
	 */
338
	public Integer getOriginalPublicationYear() {
339
		return originalPublicationYear;
340
	}
341
	/**
342
	 * @see  #getOriginalPublicationYear()
343
	 */
344
	public void setOriginalPublicationYear(Integer originalPublicationYear) {
345
		this.originalPublicationYear = originalPublicationYear;
346
	}
347

    
348

    
349
//*********************** CLONE ********************************************************/
350

    
351
	/**
352
	 * Clones <i>this</i> zoological name. This is a shortcut that enables to create
353
	 * a new instance that differs only slightly from <i>this</i> zoological name by
354
	 * modifying only some of the attributes.
355
	 *
356
	 * @see eu.etaxonomy.cdm.model.name.NonViralName#clone()
357
	 * @see java.lang.Object#clone()
358
	 */
359
	@Override
360
	public Object clone() {
361
		ZoologicalName result = (ZoologicalName)super.clone();
362
		//no changes to: breed, publicationYear, originalPublicationYear
363
		return result;
364
	}
365
}
(26-26/28)