Project

General

Profile

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

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

    
23
import org.apache.log4j.Logger;
24

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

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

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

    
63
	private static final Logger logger = Logger.getLogger(NomenclaturalCode.class);
64
	
65
	private UUID uuid;
66
	
67
	private NomenclaturalCode(UUID uuid){
68
		this.uuid = uuid;
69
	}
70
	
71
	
72
	
73
	/* (non-Javadoc)
74
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getUuid()
75
	 */
76
	public UUID getUuid(){
77
		return this.uuid;
78
	}
79
	
80
	/* (non-Javadoc)
81
	 * @see java.lang.Enum#toString()
82
	 */
83
	@Override
84
	public String toString() {
85
		return "NomenclaturalCode" + " <" + uuid + "> " + this.name();
86
	}
87

    
88
	public static NomenclaturalCode fromString(String string){
89

    
90
		for(NomenclaturalCode code : NomenclaturalCode.values()){
91
			if(code.name().equals(string)) return code;
92
		}
93
		
94
		return null;
95
	}
96
	
97
	/* (non-Javadoc)
98
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getByUuid(java.util.UUID)
99
	 */
100
	public NomenclaturalCode getByUuid(UUID uuid) {
101
		for (NomenclaturalCode nomCode : NomenclaturalCode.values()){
102
			if (nomCode.getUuid().equals(uuid)){
103
				return nomCode;
104
			}
105
		}
106
		return null;
107
	}
108

    
109
	/* (non-Javadoc)
110
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getGeneralizationOf()
111
	 */
112
	public Set<NomenclaturalCode> getGeneralizationOf() {
113
		return new HashSet<NomenclaturalCode>();
114
	}
115

    
116
	/* (non-Javadoc)
117
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getIncludes()
118
	 */
119
	public Set<NomenclaturalCode> getIncludes() {
120
		return new HashSet<NomenclaturalCode>();
121
	}
122

    
123
	/* (non-Javadoc)
124
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getKindOf()
125
	 */
126
	public NomenclaturalCode getKindOf() {
127
		return null;
128
	}
129

    
130

    
131
	/* (non-Javadoc)
132
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getPartOf()
133
	 */
134
	public NomenclaturalCode getPartOf() {
135
		return null;
136
	}
137
	
138
	/* (non-Javadoc)
139
	 * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getMedia()
140
	 */
141
	public Set<Media> getMedia() {
142
		// TODO add links to codes
143
		return new HashSet<Media>();
144
	}
145

    
146

    
147
	/* (non-Javadoc)
148
	 * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#readCsvLine(java.lang.Class, java.util.List, java.util.Map)
149
	 */
150
	public NomenclaturalCode readCsvLine(Class<NomenclaturalCode> termClass,
151
			List<String> csvLine, Map<UUID, DefinedTermBase> terms) {
152
		// TODO Auto-generated method stub
153
		return null;
154
	}
155

    
156
	/* (non-Javadoc)
157
	 * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#writeCsvLine(au.com.bytecode.opencsv.CSVWriter, eu.etaxonomy.cdm.model.common.IDefinedTerm)
158
	 */
159
	public void writeCsvLine(CSVWriter writer, NomenclaturalCode term) {
160
		// TODO Auto-generated method stub
161
		logger.warn("write csvLine not yet implemented");
162
	}
163

    
164
	/**
165
	 * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological,
166
	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
167
	 * nomenclature code only containing the given {@link Rank rank}.
168
	 * 
169
	 * @param	rank	the rank of the new taxon name instance
170
	 * @see 			BotanicalName#NewInstance(Rank)
171
	 * @see 			ZoologicalName#NewInstance(Rank)
172
	 * @see 			CultivarPlantName#NewInstance(Rank)
173
	 * @see 			BacterialName#NewInstance(Rank)
174
	 * @see 			ViralName#NewInstance(Rank)
175
	 */
176
	public TaxonNameBase<?,?> getNewTaxonNameInstance(Rank rank){
177
		TaxonNameBase<?,?> result;
178
		NomenclaturalCode nomCode = this;
179
		
180
		switch (this){
181
		case ICBN:
182
			result = BotanicalName.NewInstance(rank);
183
			break;
184
		case ICZN:
185
			result = ZoologicalName.NewInstance(rank);
186
			break;
187
		case ICNCP:
188
			result = CultivarPlantName.NewInstance(rank);
189
			break;
190
		case ICNB:
191
			result = BacterialName.NewInstance(rank);
192
			break;
193
		case ICVCN:
194
			result = ViralName.NewInstance(rank);
195
			break;
196
		default:
197
			logger.warn("Unknown nomenclatural code: " + this.getUuid());
198
			result = null;
199
		}
200
		return result;
201
	}
202
	
203
	/**
204
	 * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological,
205
	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
206
	 * nomenclature code only containing the given {@link Rank rank}.
207
	 * 
208
	 * @param	rank	the rank of the new taxon name instance
209
	 * @see 			BotanicalName#NewInstance(Rank)
210
	 * @see 			ZoologicalName#NewInstance(Rank)
211
	 * @see 			CultivarPlantName#NewInstance(Rank)
212
	 * @see 			BacterialName#NewInstance(Rank)
213
	 * @see 			ViralName#NewInstance(Rank)
214
	 */
215
	@Transient
216
	public <T extends TaxonNameBase> Class<? extends T> getCdmClass(){
217
		Class<? extends T> result;
218
		switch (this){
219
		case ICBN:
220
			result = (Class<T>)BotanicalName.class;
221
			break;
222
		case ICZN:
223
			result = (Class<T>)ZoologicalName.class;
224
			break;
225
		case ICNCP:
226
			result = (Class<T>)CultivarPlantName.class;
227
			break;
228
		case ICNB:
229
			result = (Class<T>)BacterialName.class;
230
			break;
231
		case ICVCN:
232
			result = (Class<T>)ViralName.class;
233
			break;
234
		default:
235
			logger.warn("Unknown nomenclatural code: " + this.getUuid());
236
			result = null;
237
		}
238
		return result;
239
	}	
240
}
241

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