Project

General

Profile

Download (14.9 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
import java.io.Serializable;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.UUID;
18

    
19
import javax.persistence.Transient;
20
import javax.xml.bind.annotation.XmlEnum;
21
import javax.xml.bind.annotation.XmlEnumValue;
22
import javax.xml.bind.annotation.XmlType;
23

    
24
import org.apache.log4j.Logger;
25

    
26
import au.com.bytecode.opencsv.CSVWriter;
27
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
28
import eu.etaxonomy.cdm.model.common.IDefinedTerm;
29
import eu.etaxonomy.cdm.model.media.Media;
30

    
31
/**
32
 * The class for the five nomenclature codes (ICNB, ICBN, ICNCP, ICZN and ICVCN)
33
 * ruling {@link TaxonNameBase taxon names}.
34
 * <P>
35
 * The standard set of nomenclature code instances will be automatically created
36
 * as the project starts. But this class allows to extend this standard set by
37
 * creating new instances of additional nomenclature codes if unlikely needed. 
38
 * <P>
39
 * This class corresponds to: <ul>
40
 * <li> NomenclaturalCodeTerm according to the TDWG ontology
41
 * <li> NomenclaturalCodesEnum according to the TCS
42
 * <li> CodeOfNomenclatureEnum according to the ABCD schema
43
 * </ul>
44
 * 
45
 * @author a.mueller
46
 * @created 19.05.2008
47
 * @version 2.0
48
 */
49

    
50
@XmlType(name = "NomenclaturalCode")
51
@XmlEnum
52
public enum NomenclaturalCode implements IDefinedTerm<NomenclaturalCode>, Serializable {
53
	/**
54
	 * International Code of Nomenclature of Bacteria
55
	*/
56
	@XmlEnumValue("ICNB") ICNB(UUID.fromString("ff4b0979-7abf-4b40-95c0-8b8b1e8a4d5e"), "ICNB"), 
57
	/**
58
	 * International Code of Botanical Nomenclature
59
	 */
60
	@XmlEnumValue("ICBN") ICBN(UUID.fromString("540fc02a-8a8e-4813-89d2-581dad4dd482"), "ICBN"), 
61
	/**
62
	 * International Code of Cultivated Plants
63
	 */
64
	@XmlEnumValue("ICNCP") ICNCP(UUID.fromString("65a432b5-92b1-4c9a-8090-2a185e423d2e"),"ICNCP"), 
65
	/**
66
	 * International Code of Zoological Nomenclature
67
	 */
68
	@XmlEnumValue("ICZN") ICZN(UUID.fromString("b584c2f8-dbe5-4454-acad-2b45e63ec11b"), "ICZN"), 
69
	/**
70
	 * International Code for Virus Classification and Nomenclature
71
	 */
72
	@XmlEnumValue("ICVCN") ICVCN(UUID.fromString("e9d6d6b4-ccb7-4f28-b828-0b1501f8c75a"), "ICVCN");	
73

    
74
	private static final Logger logger = Logger.getLogger(NomenclaturalCode.class);
75
	
76
	private UUID uuid;
77

    
78
	private String titleCache;
79
	
80
	public String getTitleCache() {
81
		return titleCache;
82
	}
83
	
84
	private NomenclaturalCode(UUID uuid, String titleCache){
85
		this.uuid = uuid;
86
		this.titleCache = titleCache;
87
	}
88
	
89
	
90
	
91
	/* (non-Javadoc)
92
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getUuid()
93
	 */
94
	public UUID getUuid(){
95
		return this.uuid;
96
	}
97
	
98
	/* (non-Javadoc)
99
	 * @see java.lang.Enum#toString()
100
	 */
101
	@Override
102
	public String toString() {
103
		return "NomenclaturalCode" + " <" + uuid + "> " + this.name();
104
	}
105

    
106
	public static NomenclaturalCode fromString(String string){
107

    
108
		for(NomenclaturalCode code : NomenclaturalCode.values()){
109
			if(code.name().equals(string)) return code;
110
		}
111
		
112
		return null;
113
	}
114
	
115
	/* (non-Javadoc)
116
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getByUuid(java.util.UUID)
117
	 */
118
	public NomenclaturalCode getByUuid(UUID uuid) {
119
		for (NomenclaturalCode nomCode : NomenclaturalCode.values()){
120
			if (nomCode.getUuid().equals(uuid)){
121
				return nomCode;
122
			}
123
		}
124
		return null;
125
	}
126

    
127
	/* (non-Javadoc)
128
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getGeneralizationOf()
129
	 */
130
	public Set<NomenclaturalCode> getGeneralizationOf() {
131
		return new HashSet<NomenclaturalCode>();
132
	}
133

    
134
	/* (non-Javadoc)
135
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getIncludes()
136
	 */
137
	public Set<NomenclaturalCode> getIncludes() {
138
		return new HashSet<NomenclaturalCode>();
139
	}
140

    
141
	/* (non-Javadoc)
142
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getKindOf()
143
	 */
144
	public NomenclaturalCode getKindOf() {
145
		return null;
146
	}
147

    
148

    
149
	/* (non-Javadoc)
150
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getPartOf()
151
	 */
152
	public NomenclaturalCode getPartOf() {
153
		return null;
154
	}
155
	
156
	/* (non-Javadoc)
157
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getMedia()
158
	 */
159
	public Set<Media> getMedia() {
160
		// TODO add links to codes
161
		return new HashSet<Media>();
162
	}
163

    
164

    
165
	/* (non-Javadoc)
166
	 * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#readCsvLine(java.lang.Class, java.util.List, java.util.Map)
167
	 */
168
	public NomenclaturalCode readCsvLine(Class<NomenclaturalCode> termClass,
169
			List<String> csvLine, Map<UUID, DefinedTermBase> terms) {
170
		// TODO Auto-generated method stub
171
		return null;
172
	}
173

    
174
	/* (non-Javadoc)
175
	 * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#writeCsvLine(au.com.bytecode.opencsv.CSVWriter, eu.etaxonomy.cdm.model.common.IDefinedTerm)
176
	 */
177
	public void writeCsvLine(CSVWriter writer, NomenclaturalCode term) {
178
		// TODO Auto-generated method stub
179
		logger.warn("write csvLine not yet implemented");
180
	}
181

    
182
	/**
183
	 * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological,
184
	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
185
	 * nomenclature code only containing the given {@link Rank rank}.
186
	 * 
187
	 * @param	rank	the rank of the new taxon name instance
188
	 * @see 			BotanicalName#NewInstance(Rank)
189
	 * @see 			ZoologicalName#NewInstance(Rank)
190
	 * @see 			CultivarPlantName#NewInstance(Rank)
191
	 * @see 			BacterialName#NewInstance(Rank)
192
	 * @see 			ViralName#NewInstance(Rank)
193
	 */
194
	public TaxonNameBase<?,?> getNewTaxonNameInstance(Rank rank){
195
		TaxonNameBase<?,?> result;
196
		NomenclaturalCode nomCode = this;
197
		
198
		switch (this){
199
		case ICBN:
200
			result = BotanicalName.NewInstance(rank);
201
			break;
202
		case ICZN:
203
			result = ZoologicalName.NewInstance(rank);
204
			break;
205
		case ICNCP:
206
			result = CultivarPlantName.NewInstance(rank);
207
			break;
208
		case ICNB:
209
			result = BacterialName.NewInstance(rank);
210
			break;
211
		case ICVCN:
212
			result = ViralName.NewInstance(rank);
213
			break;
214
		default:
215
			logger.warn("Unknown nomenclatural code: " + this.getUuid());
216
			result = null;
217
		}
218
		return result;
219
	}
220
	
221
	/**
222
	 * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological,
223
	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
224
	 * nomenclature code only containing the given {@link Rank rank}.
225
	 * 
226
	 * @param	rank	the rank of the new taxon name instance
227
	 * @see 			BotanicalName#NewInstance(Rank)
228
	 * @see 			ZoologicalName#NewInstance(Rank)
229
	 * @see 			CultivarPlantName#NewInstance(Rank)
230
	 * @see 			BacterialName#NewInstance(Rank)
231
	 * @see 			ViralName#NewInstance(Rank)
232
	 */
233
	@Transient
234
	public <T extends TaxonNameBase> Class<? extends T> getCdmClass(){
235
		Class<? extends T> result;
236
		switch (this){
237
		case ICBN:
238
			result = (Class<T>)BotanicalName.class;
239
			break;
240
		case ICZN:
241
			result = (Class<T>)ZoologicalName.class;
242
			break;
243
		case ICNCP:
244
			result = (Class<T>)CultivarPlantName.class;
245
			break;
246
		case ICNB:
247
			result = (Class<T>)BacterialName.class;
248
			break;
249
		case ICVCN:
250
			result = (Class<T>)ViralName.class;
251
			break;
252
		default:
253
			logger.warn("Unknown nomenclatural code: " + this.getUuid());
254
			result = null;
255
		}
256
		return result;
257
	}	
258
	
259
	@Transient
260
	public TaxonNameBase valueOf(TaxonNameBase taxonNameBase){
261
		
262
		switch(this){
263
		case ICBN:
264
			return BotanicalName.valueOf(taxonNameBase);
265
		case ICZN:
266
			return ZoologicalName.valueOf(taxonNameBase);
267
		default:
268
			logger.error("Not implemented yet");
269
		}
270
				
271
		return taxonNameBase;
272
	}
273
}
274

    
275
//@XmlAccessorType(XmlAccessType.FIELD)
276
//@Entity
277
////@Audited
278
//public class NomenclaturalCode extends DefinedTermBase<NomenclaturalCode> {
279
//	/**
280
//	 * SerialVersionUID
281
//	 */
282
//	private static final long serialVersionUID = -1011240079962589681L;
283
//	private static final Logger logger = Logger.getLogger(NomenclaturalCode.class);
284
//
285
//	private static final UUID uuidIcnb = UUID.fromString("ff4b0979-7abf-4b40-95c0-8b8b1e8a4d5e");
286
//	private static final UUID uuidIcbn = UUID.fromString("540fc02a-8a8e-4813-89d2-581dad4dd482");
287
//	private static final UUID uuidIcncp = UUID.fromString("65a432b5-92b1-4c9a-8090-2a185e423d2e");
288
//	private static final UUID uuidIczn = UUID.fromString("b584c2f8-dbe5-4454-acad-2b45e63ec11b");
289
//	private static final UUID uuidIcvcn = UUID.fromString("e9d6d6b4-ccb7-4f28-b828-0b1501f8c75a");
290
//
291
//	private static NomenclaturalCode ICZN;
292
//
293
//	private static NomenclaturalCode ICVCN;
294
//
295
//	private static NomenclaturalCode ICNCP;
296
//
297
//	private static NomenclaturalCode ICBN;
298
//
299
//	private static NomenclaturalCode ICNB;
300
//
301
//	
302
//	protected static Map<UUID, NomenclaturalCode> termMap = null;		
303
//
304
//	protected static NomenclaturalCode getTermByUuid(UUID uuid){
305
//		if (termMap == null){
306
//			DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
307
//			vocabularyStore.initialize();
308
//		}
309
//		return (NomenclaturalCode)termMap.get(uuid);
310
//	}
311
//	
312
//	
313
//	// ************* CONSTRUCTORS *************/	
314
//	/** 
315
//	 * Class constructor: creates a new empty nomenclature code instance.
316
//	 * 
317
//	 * @see 	#NomenclaturalCode(String, String, String)
318
//	 */
319
//	public NomenclaturalCode() {
320
//		super();
321
//	}
322
//	
323
//	/** 
324
//	 * Class constructor: creates an additional nomenclature code instance with
325
//	 * a description (in the {@link eu.etaxonomy.cdm.model.common.Language#DEFAULT() default language}), a label and
326
//	 * a label abbreviation.
327
//	 * 
328
//	 * @param	term  		 the string (in the default language) describing the
329
//	 * 						 new nomenclature code to be created 
330
//	 * @param	label  		 the string identifying the new nomenclature code
331
//	 * 						 to be created
332
//	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
333
//	 * 						 new nomenclature code to be created
334
//	 * @see 				 #NomenclaturalCode()
335
//	 */
336
//	public NomenclaturalCode(String term, String label, String labelAbbrev) {
337
//		super(term, label, labelAbbrev);
338
//	}
339
//
340
//
341
//	//********* METHODS **************************************/
342
//
343
//	/**
344
//	 * Returns the International Code of Nomenclature of Bacteria
345
//	 */
346
//	public static final NomenclaturalCode ICNB(){
347
//		return getTermByUuid(uuidIcnb);
348
////		return ICNB;
349
//	}
350
//	
351
//	/**
352
//	 * Returns the International Code of Botanical Nomenclature
353
//	 */
354
//	public static final NomenclaturalCode ICBN(){
355
//		return getTermByUuid(uuidIcbn);
356
////		return  ICBN;
357
//	}
358
//	/**
359
//	 * Returns the International Code of Cultivated Plants
360
//	 */
361
//	public static final NomenclaturalCode ICNCP(){
362
//		return getTermByUuid(uuidIcncp);
363
////		return ICNCP; 
364
//	}
365
//
366
//	/**
367
//	 * Returns the International Code of Zoological Nomenclature
368
//	 */
369
//	public static final NomenclaturalCode ICZN(){
370
//		return getTermByUuid(uuidIczn);
371
////		return ICZN; 
372
//	}
373
//
374
//
375
//	/**
376
//	 * Returns the International Code for Virus Classification and Nomenclature
377
//	 */
378
//	public static final NomenclaturalCode ICVCN(){
379
//		return getTermByUuid(uuidIcvcn);
380
////		return ICVCN; // FIXME(uuidIcvcn);
381
//	}
382
//	
383
//	/**
384
//	 * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological,
385
//	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
386
//	 * nomenclature code only containing the given {@link Rank rank}.
387
//	 * 
388
//	 * @param	rank	the rank of the new taxon name instance
389
//	 * @see 			BotanicalName#NewInstance(Rank)
390
//	 * @see 			ZoologicalName#NewInstance(Rank)
391
//	 * @see 			CultivarPlantName#NewInstance(Rank)
392
//	 * @see 			BacterialName#NewInstance(Rank)
393
//	 * @see 			ViralName#NewInstance(Rank)
394
//	 */
395
//	@Transient
396
//	public TaxonNameBase<?,?> getNewTaxonNameInstance(Rank rank){
397
//		TaxonNameBase<?,?> result;
398
//		if (this.equals(NomenclaturalCode.ICBN())){
399
//			result = BotanicalName.NewInstance(rank);
400
//		}else if (this.equals(NomenclaturalCode.ICZN())){
401
//			result = ZoologicalName.NewInstance(rank);
402
//		}else if (this.equals(NomenclaturalCode.ICNCP())){
403
//			result = CultivarPlantName.NewInstance(rank);
404
//		}else if (this.equals(NomenclaturalCode.ICNB())){
405
//			result = BacterialName.NewInstance(rank);
406
//		}else if (this.equals(NomenclaturalCode.ICVCN())){
407
//			result = ViralName.NewInstance(rank);
408
//		}else {
409
//			logger.warn("Unknown nomenclatural code: " + this.getUuid());
410
//			result = null;
411
//		}
412
//		return result;
413
//	}
414
//	
415
//	/**
416
//	 * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological,
417
//	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
418
//	 * nomenclature code only containing the given {@link Rank rank}.
419
//	 * 
420
//	 * @param	rank	the rank of the new taxon name instance
421
//	 * @see 			BotanicalName#NewInstance(Rank)
422
//	 * @see 			ZoologicalName#NewInstance(Rank)
423
//	 * @see 			CultivarPlantName#NewInstance(Rank)
424
//	 * @see 			BacterialName#NewInstance(Rank)
425
//	 * @see 			ViralName#NewInstance(Rank)
426
//	 */
427
//	@Transient
428
//	public <T extends TaxonNameBase> Class<? extends T> getCdmClass(){
429
//		Class<? extends T> result;
430
//		if (this.equals(NomenclaturalCode.ICBN())){
431
//			result = (Class<T>)BotanicalName.class;
432
//		}else if (this.equals(NomenclaturalCode.ICZN())){
433
//			result = (Class<T>)ZoologicalName.class;
434
//		}else if (this.equals(NomenclaturalCode.ICNCP())){
435
//			result = (Class<T>)CultivarPlantName.class;
436
//		}else if (this.equals(NomenclaturalCode.ICNB())){
437
//			result = (Class<T>)BacterialName.class;
438
//		}else if (this.equals(NomenclaturalCode.ICVCN())){
439
//			result = (Class<T>)ViralName.class;
440
//		}else {
441
//			logger.warn("Unknown nomenclatural code: " + this.getUuid());
442
//			result = null;
443
//		}
444
//		return result;
445
//	}
446
//
447
//	@Override
448
//	protected void setDefaultTerms(TermVocabulary<NomenclaturalCode> termVocabulary) {
449
//		termMap = new HashMap<UUID, NomenclaturalCode>();
450
//		for (NomenclaturalCode term : termVocabulary.getTerms()){
451
//			termMap.put(term.getUuid(), term);
452
//		}
453
//		
454
////		termMap.put(uuidIcbn, termVocabulary.findTermByUuid(NomenclaturalCode.uuidIcbn));
455
////		termMap.put(uuidIcnb, termVocabulary.findTermByUuid(NomenclaturalCode.uuidIcnb));
456
////		termMap.put(uuidIcncp, termVocabulary.findTermByUuid(NomenclaturalCode.uuidIcncp));
457
////		termMap.put(uuidIcvcn, termVocabulary.findTermByUuid(NomenclaturalCode.uuidIcvcn));
458
////		termMap.put(uuidIczn, termVocabulary.findTermByUuid(NomenclaturalCode.uuidIczn));
459
//		
460
////		NomenclaturalCode.ICBN = termVocabulary.findTermByUuid(NomenclaturalCode.uuidIcbn);
461
////		NomenclaturalCode.ICNB = termVocabulary.findTermByUuid(NomenclaturalCode.uuidIcnb);
462
////		NomenclaturalCode.ICNCP = termVocabulary.findTermByUuid(NomenclaturalCode.uuidIcncp);
463
////		NomenclaturalCode.ICVCN = termVocabulary.findTermByUuid(NomenclaturalCode.uuidIcvcn);
464
////		NomenclaturalCode.ICZN = termVocabulary.findTermByUuid(NomenclaturalCode.uuidIczn);
465
//	}
466
//	
467
//	
468
//}
(12-12/26)