Project

General

Profile

Download (7.91 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.Set;
13
import java.util.UUID;
14

    
15
import javax.persistence.Transient;
16
import javax.xml.bind.annotation.XmlEnum;
17
import javax.xml.bind.annotation.XmlEnumValue;
18
import javax.xml.bind.annotation.XmlType;
19

    
20
import org.apache.log4j.Logger;
21

    
22
import eu.etaxonomy.cdm.model.common.EnumeratedTermVoc;
23
import eu.etaxonomy.cdm.model.common.IEnumTerm;
24
import eu.etaxonomy.cdm.model.common.Language;
25

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

    
45
@XmlType(name = "NomenclaturalCode")
46
@XmlEnum
47
public enum NomenclaturalCode implements IEnumTerm<NomenclaturalCode> {
48
	//0
49
	/**
50
	 * International Code of Nomenclature of Bacteria
51
	*/
52
	@XmlEnumValue("ICNB")
53
	ICNB(UUID.fromString("ff4b0979-7abf-4b40-95c0-8b8b1e8a4d5e"), "ICNB","BacterialName"),
54

    
55
	//1
56
	/**
57
	 * International Code of Nomenclature for algae, fungi, and plants
58
	 * Former International Code of Botanical Nomenclature
59
	 */
60
	@XmlEnumValue("ICNAFP")
61
	ICNAFP(UUID.fromString("540fc02a-8a8e-4813-89d2-581dad4dd482"), "ICNAFP","BotanicalName"),
62

    
63
	//2
64
	/**
65
	 * International Code of Cultivated Plants
66
	 */
67
	@XmlEnumValue("ICNCP")
68
	ICNCP(UUID.fromString("65a432b5-92b1-4c9a-8090-2a185e423d2e"),"ICNCP","CultivarPlantName"),
69

    
70
	//3
71
	/**
72
	 * International Code of Zoological Nomenclature
73
	 */
74
	@XmlEnumValue("ICZN")
75
	ICZN(UUID.fromString("b584c2f8-dbe5-4454-acad-2b45e63ec11b"), "ICZN","ZoologicalName"),
76

    
77
	//4
78
	/**
79
	 * International Code for Virus Classification and Nomenclature
80
	 */
81
	@XmlEnumValue("ICVCN") ICVCN(UUID.fromString("e9d6d6b4-ccb7-4f28-b828-0b1501f8c75a"), "ICVCN","ViralName");
82

    
83
	private static final Logger logger = Logger.getLogger(NomenclaturalCode.class);
84

    
85
	private String dtype;
86

    
87
	private NomenclaturalCode(UUID uuid, String titleCache, String dtype){
88
		delegateVocTerm = EnumeratedTermVoc.addTerm(getClass(), this, uuid, titleCache, titleCache, null);
89
		this.dtype = dtype;
90
	}
91

    
92
    public String getTitleCache() {
93
        return getMessage();
94
    }
95

    
96

    
97
	@Override
98
	public String toString() {
99
		return "NomenclaturalCode" + " <" + getUuid() + "> " + this.name();
100
	}
101

    
102
	public static NomenclaturalCode fromString(String string){
103
		for(NomenclaturalCode code : NomenclaturalCode.values()){
104
			if(code.name().equalsIgnoreCase(string)) {
105
				return code;
106
			}
107
		}
108
		if ("ICBN".equals(string)){ //former name of the ICNAFP
109
			return ICNAFP;
110
		}
111
		return null;
112
	}
113

    
114
    public static NomenclaturalCode fromDtype(String string){
115
        for(NomenclaturalCode code : NomenclaturalCode.values()){
116
            if(code.dtype.equalsIgnoreCase(string)) {
117
                return code;
118
            }
119
        }
120
        return null;
121
    }
122

    
123

    
124
	/**
125
	 * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological,
126
	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
127
	 * nomenclature code only containing the given {@link Rank rank}.
128
	 *
129
	 * @param	rank	the rank of the new taxon name instance
130
	 * @see 			BotanicalName#NewInstance(Rank)
131
	 * @see 			ZoologicalName#NewInstance(Rank)
132
	 * @see 			CultivarPlantName#NewInstance(Rank)
133
	 * @see 			BacterialName#NewInstance(Rank)
134
	 * @see 			ViralName#NewInstance(Rank)
135
	 */
136
	public TaxonNameBase<?,?> getNewTaxonNameInstance(Rank rank){
137
		TaxonNameBase<?,?> result;
138

    
139
		switch (this){
140
		case ICNAFP:
141
			result = BotanicalName.NewInstance(rank);
142
			break;
143
		case ICZN:
144
			result = ZoologicalName.NewInstance(rank);
145
			break;
146
		case ICNCP:
147
			result = CultivarPlantName.NewInstance(rank);
148
			break;
149
		case ICNB:
150
			result = BacterialName.NewInstance(rank);
151
			break;
152
		case ICVCN:
153
			result = ViralName.NewInstance(rank);
154
			break;
155
		default:
156
			logger.warn("Unknown nomenclatural code: " + this.getUuid());
157
			result = null;
158
		}
159
		return result;
160
	}
161

    
162
	/**
163
	 * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological,
164
	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
165
	 * nomenclature code only containing the given {@link Rank rank}.
166
	 *
167
	 * @param	rank	the rank of the new taxon name instance
168
	 * @see 			BotanicalName#NewInstance(Rank)
169
	 * @see 			ZoologicalName#NewInstance(Rank)
170
	 * @see 			CultivarPlantName#NewInstance(Rank)
171
	 * @see 			BacterialName#NewInstance(Rank)
172
	 * @see 			ViralName#NewInstance(Rank)
173
	 */
174
	@Transient
175
	public <T extends TaxonNameBase> Class<? extends T> getCdmClass(){
176
		Class<? extends T> result;
177
		switch (this){
178
		case ICNAFP:
179
			result = (Class<T>)BotanicalName.class;
180
			break;
181
		case ICZN:
182
			result = (Class<T>)ZoologicalName.class;
183
			break;
184
		case ICNCP:
185
			result = (Class<T>)CultivarPlantName.class;
186
			break;
187
		case ICNB:
188
			result = (Class<T>)BacterialName.class;
189
			break;
190
		case ICVCN:
191
			result = (Class<T>)ViralName.class;
192
			break;
193
		default:
194
			logger.warn("Unknown nomenclatural code: " + this.getUuid());
195
			result = null;
196
		}
197
		return result;
198
	}
199

    
200
	/**
201
	 * Returns the recommended value for the accepted taxon status according to
202
	 * http://code.google.com/p/darwincore/wiki/Taxon#taxonomicStatus
203
	 */
204
	public String acceptedTaxonStatusLabel(){
205
		switch(this){
206
		case ICNAFP:
207
			return "accepted";
208
		case ICZN:
209
			return "valid";
210
		default:
211
			logger.error("Not implemented yet");
212
			return "accepted";
213
		}
214
	}
215

    
216
	/**
217
	 * Returns the recommended value for the accepted taxon status according to
218
	 * http://code.google.com/p/darwincore/wiki/Taxon#taxonomicStatus
219
	 */
220
	public String synonymStatusLabel(){
221
		switch(this){
222
		case ICNAFP:
223
			return "synonym";
224
		case ICZN:
225
			return "invalid";
226
		default:
227
			logger.error("Not implemented yet");
228
			return "synonym";
229
		}
230
	}
231

    
232

    
233
    /**
234
     * @return the dtype of the according CDM class
235
     */
236
    public String getDtype() {
237
        return dtype;
238
    }
239

    
240
// *************************** DELEGATE **************************************/
241

    
242
	private static EnumeratedTermVoc<NomenclaturalCode> delegateVoc;
243
	private IEnumTerm<NomenclaturalCode> delegateVocTerm;
244

    
245
	static {
246
		delegateVoc = EnumeratedTermVoc.getVoc(NomenclaturalCode.class);
247
	}
248

    
249
	@Override
250
	public String getKey(){return delegateVocTerm.getKey();}
251

    
252
	@Override
253
    public String getMessage(){return delegateVocTerm.getMessage();}
254

    
255
	@Override
256
    public String getMessage(Language language){return delegateVocTerm.getMessage(language);}
257

    
258

    
259
	@Override
260
    public UUID getUuid() {return delegateVocTerm.getUuid();}
261

    
262
	@Override
263
    public NomenclaturalCode getKindOf() {return delegateVocTerm.getKindOf();}
264

    
265
	@Override
266
    public Set<NomenclaturalCode> getGeneralizationOf() {return delegateVocTerm.getGeneralizationOf();}
267

    
268
	@Override
269
	public boolean isKindOf(NomenclaturalCode ancestor) {return delegateVocTerm.isKindOf(ancestor);	}
270

    
271
	@Override
272
    public Set<NomenclaturalCode> getGeneralizationOf(boolean recursive) {return delegateVocTerm.getGeneralizationOf(recursive);}
273

    
274

    
275
	public static NomenclaturalCode getByKey(String key){return delegateVoc.getByKey(key);}
276
    public static NomenclaturalCode getByUuid(UUID uuid) {return delegateVoc.getByUuid(uuid);}
277

    
278

    
279
}
(13-13/28)