Project

General

Profile

Download (7.93 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.xml.bind.annotation.XmlEnum;
16
import javax.xml.bind.annotation.XmlEnumValue;
17
import javax.xml.bind.annotation.XmlType;
18

    
19
import org.apache.log4j.Logger;
20

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

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

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

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

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

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

    
75
	//4
76
	/**
77
	 * International Code for Virus Classification and Nomenclature
78
	 */
79
	@XmlEnumValue("ICVCN")
80
	ICVCN(UUID.fromString("e9d6d6b4-ccb7-4f28-b828-0b1501f8c75a"), "ICVCN","ViralName"),
81
//
82
//	//Any
83
//	@XmlEnumValue("Any")
84
//    Any(UUID.fromString("348f2a2f-366f-4c8c-bb15-c90b937886ca"), "Any taxon name","TaxonName"),
85

    
86

    
87
	//NonViral
88
    @XmlEnumValue("NonViral")
89
    NonViral(UUID.fromString("04f88497-a66a-41b1-9b98-0dd22df6307f"), "NonViral","TaxonName"),
90

    
91
	//Fungi
92
    @XmlEnumValue("Fungus")
93
	Fungi(UUID.fromString("c6bb280d-2468-4738-bb29-973f74412100"), "Fungus", "BotanicalName"),
94

    
95
//	//Plant
96
//    @XmlEnumValue("Plant")
97
//	Plant(UUID.fromString("9669c889-25c5-48ab-9f8e-fd47a6218f83"), "Plant", "BotanicalName"),
98
//
99
//	//Algae
100
//    @XmlEnumValue("Algae")
101
//	Algae(UUID.fromString("abc09250-ea76-449b-b292-90acd61f8659"), "Algae", "BotanicalName"),
102
    ;
103

    
104
	private static final Logger logger = Logger.getLogger(NomenclaturalCode.class);
105

    
106
	@Deprecated
107
	private String dtype;
108

    
109
	private NomenclaturalCode(UUID uuid, String titleCache, String dtype){
110
		delegateVocTerm = EnumeratedTermVoc.addTerm(getClass(), this, uuid, titleCache, titleCache, null);
111
		this.dtype = dtype;
112
	}
113

    
114
    public String getTitleCache() {
115
        return getMessage();
116
    }
117

    
118

    
119
	@Override
120
	public String toString() {
121
		return this.name();
122
	}
123

    
124
    public boolean isNonViral() {
125
        return this != ICVCN;
126
    }
127
    public boolean isZoological() {
128
        return this == ICZN;
129
    }
130
    public boolean isBotanical() {
131
        return this == NomenclaturalCode.ICNAFP || this == ICNCP || this == Fungi;
132
    }
133
    public boolean isCultivar() {
134
        return this == NomenclaturalCode.ICNCP;
135
    }
136
    public boolean isBacterial() {
137
        return this == NomenclaturalCode.ICNB;
138
     }
139
     public boolean isViral() {
140
         return this == NomenclaturalCode.ICVCN;
141
     }
142
     public boolean isFungus() {
143
         return this == NomenclaturalCode.Fungi;
144
     }
145

    
146

    
147
	public static NomenclaturalCode fromString(String string){
148
		for(NomenclaturalCode code : NomenclaturalCode.values()){
149
			if(code.name().equalsIgnoreCase(string)) {
150
				return code;
151
			}
152
		}
153
		if ("ICBN".equals(string)){ //former name of the ICNAFP
154
			return ICNAFP;
155
		}
156
		return null;
157
	}
158

    
159
	/**
160
	 * @deprecated not relevant anymore, used only by NomenclaturalCodeUpdater
161
	 * which is used for 4.0->4.1 schema update.
162
	 */
163
	@Deprecated
164
    public static NomenclaturalCode fromDtype(String string){
165
        for(NomenclaturalCode code : NomenclaturalCode.values()){
166
            if(code.dtype.equalsIgnoreCase(string)) {
167
                return code;
168
            }
169
        }
170
        return null;
171
    }
172

    
173

    
174
	/**
175
	 * Creates a new particular {@link TaxonName taxon name} (botanical, zoological,
176
	 * cultivar plant, bacterial or viral name) instance depending on <i>this</i>
177
	 * nomenclature code only containing the given {@link Rank rank}.
178
	 *
179
	 * @param	rank	the rank of the new taxon name instance
180
	 * @see 			TaxonName#NewBotanicalInstance(Rank)
181
	 * @see 			TaxonName#NewZoologicalInstance(Rank)
182
	 * @see 			TaxonName#NewCultivarInstance(Rank)
183
	 * @see 			TaxonName#NewBacterialInstance(Rank)
184
	 * @see 			TaxonName#NewViralInstance(Rank)
185
	 */
186
	public TaxonName getNewTaxonNameInstance(Rank rank){
187
		TaxonName result;
188

    
189
		switch (this){
190
		case ICNAFP: case ICZN: case ICNCP: case ICNB:
191
		case ICVCN: case NonViral: case Fungi:
192
			result = TaxonNameFactory.NewNameInstance(this, rank);
193
			break;
194
        default:
195
			logger.warn("Unhandled nomenclatural code: " + this.getUuid());
196
			result = null;
197
		}
198
		return result;
199
	}
200

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

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

    
233

    
234
// *************************** DELEGATE **************************************/
235

    
236
	private static EnumeratedTermVoc<NomenclaturalCode> delegateVoc;
237
	private IEnumTerm<NomenclaturalCode> delegateVocTerm;
238

    
239
	static {
240
		delegateVoc = EnumeratedTermVoc.getVoc(NomenclaturalCode.class);
241
	}
242

    
243
	@Override
244
	public String getKey(){return delegateVocTerm.getKey();}
245

    
246
	@Override
247
    public String getMessage(){return delegateVocTerm.getMessage();}
248

    
249
	@Override
250
    public String getMessage(Language language){return delegateVocTerm.getMessage(language);}
251

    
252

    
253
	@Override
254
    public UUID getUuid() {return delegateVocTerm.getUuid();}
255

    
256
	@Override
257
    public NomenclaturalCode getKindOf() {return delegateVocTerm.getKindOf();}
258

    
259
	@Override
260
    public Set<NomenclaturalCode> getGeneralizationOf() {return delegateVocTerm.getGeneralizationOf();}
261

    
262
	@Override
263
	public boolean isKindOf(NomenclaturalCode ancestor) {return delegateVocTerm.isKindOf(ancestor);	}
264

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

    
268

    
269
	public static NomenclaturalCode getByKey(String key){return delegateVoc.getByKey(key);}
270
    public static NomenclaturalCode getByUuid(UUID uuid) {return delegateVoc.getByUuid(uuid);}
271

    
272
}
(20-20/36)