Project

General

Profile

Download (8.23 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.Language;
22
import eu.etaxonomy.cdm.model.term.EnumeratedTermVoc;
23
import eu.etaxonomy.cdm.model.term.IEnumTerm;
24

    
25
/**
26
 * The class for the five nomenclature codes (ICNP, 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

    
47
    //NonViral
48
    @XmlEnumValue("NonViral")
49
    NonViral(UUID.fromString("04f88497-a66a-41b1-9b98-0dd22df6307f"), "NonViral","TaxonName", null, null),
50

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

    
59
    //1
60
	/**
61
	 * International Code of Nomenclature of Bacteria
62
	 * => now International Code of Nomenclature of Prokaryotes
63
	*/
64
	@XmlEnumValue("ICNP")
65
	ICNP(UUID.fromString("ff4b0979-7abf-4b40-95c0-8b8b1e8a4d5e"), "ICNP","BacterialName","Q743780", NonViral),
66

    
67

    
68
	//2
69
	/**
70
	 * International Code of Cultivated Plants
71
	 */
72
	@XmlEnumValue("ICNCP")
73
	ICNCP(UUID.fromString("65a432b5-92b1-4c9a-8090-2a185e423d2e"),"ICNCP","CultivarPlantName","Q941761", NonViral),
74

    
75
	//3
76
	/**
77
	 * International Code of Zoological Nomenclature
78
	 */
79
	@XmlEnumValue("ICZN")
80
	ICZN(UUID.fromString("b584c2f8-dbe5-4454-acad-2b45e63ec11b"), "ICZN","ZoologicalName","Q13011", NonViral),
81

    
82
	//4
83
	/**
84
	 * International Code for Virus Classification and Nomenclature
85
	 */
86
	@XmlEnumValue("ICVCN")
87
	ICVCN(UUID.fromString("e9d6d6b4-ccb7-4f28-b828-0b1501f8c75a"), "ICVCN","ViralName","Q14920640", null),
88
//
89
//	//Any
90
//	@XmlEnumValue("Any")
91
//    Any(UUID.fromString("348f2a2f-366f-4c8c-bb15-c90b937886ca"), "Any taxon name","TaxonName"),
92

    
93

    
94
	//Fungi
95
    @XmlEnumValue("Fungus")
96
	Fungi(UUID.fromString("c6bb280d-2468-4738-bb29-973f74412100"), "Fungus", "BotanicalName", null, ICNAFP),
97

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

    
107
	private static final Logger logger = Logger.getLogger(NomenclaturalCode.class);
108

    
109
	@Deprecated
110
	private String dtype;
111

    
112
	private String wikiDataId;
113

    
114
	private NomenclaturalCode(UUID uuid, String titleCache, String dtype, String wikiDataId, NomenclaturalCode parent){
115
		delegateVocTerm = EnumeratedTermVoc.addTerm(getClass(), this, uuid, titleCache, titleCache, parent);
116
		this.dtype = dtype;
117
		this.wikiDataId = wikiDataId;
118
	}
119

    
120
    public String getTitleCache() {
121
        return getLabel();
122
    }
123

    
124
	@Override
125
	public String toString() {
126
		return this.name();
127
	}
128

    
129
    public boolean isNonViral() {
130
        return this != ICVCN;
131
    }
132
    public boolean isZoological() {
133
        return this == ICZN;
134
    }
135
    public boolean isBotanical() {
136
        return this == NomenclaturalCode.ICNAFP || this == ICNCP || this == Fungi;
137
    }
138
    public boolean isCultivar() {
139
        return this == NomenclaturalCode.ICNCP;
140
    }
141
    public boolean isBacterial() {
142
        return this == NomenclaturalCode.ICNP;
143
     }
144
     public boolean isViral() {
145
         return this == NomenclaturalCode.ICVCN;
146
     }
147
     public boolean isFungus() {
148
         return this == NomenclaturalCode.Fungi;
149
     }
150

    
151

    
152
	public static NomenclaturalCode fromString(String string){
153
		for(NomenclaturalCode code : NomenclaturalCode.values()){
154
			if(code.name().equalsIgnoreCase(string)) {
155
				return code;
156
			}
157
		}
158
		if ("ICBN".equals(string)){ //former name of the ICNAFP
159
			return ICNAFP;
160
		}
161
		return null;
162
	}
163

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

    
178

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

    
194
		switch (this){
195
		case ICNAFP: case ICZN: case ICNCP: case ICNP:
196
		case ICVCN: case NonViral: case Fungi:
197
			result = TaxonNameFactory.NewNameInstance(this, rank);
198
			break;
199
        default:
200
			logger.warn("Unhandled nomenclatural code: " + this.getUuid());
201
			result = null;
202
		}
203
		return result;
204
	}
205

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

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

    
238

    
239
// *************************** DELEGATE **************************************/
240

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

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

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

    
251
	@Override
252
    public String getLabel(){return delegateVocTerm.getLabel();}
253

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

    
257

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

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

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

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

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

    
273

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

    
277
}
(20-20/39)