Project

General

Profile

Download (8.29 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.logging.log4j.LogManager;import org.apache.logging.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 Prokaryotes
62
	 * (former International Code of Nomenclature of Bacteria)
63
	*/
64
	@XmlEnumValue("ICNP")
65
	ICNP(UUID.fromString("ff4b0979-7abf-4b40-95c0-8b8b1e8a4d5e"), "ICNP","BacterialName","Q743780", NonViral),
66

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

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

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

    
92

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

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

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

    
108
	@Deprecated
109
	private String dtype;
110

    
111
	private String wikiDataId;
112

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

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

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

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

    
150

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

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

    
177

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

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

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

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

    
237

    
238
// *************************** DELEGATE **************************************/
239

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

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

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

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

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

    
256

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

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

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

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

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

    
272

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

    
276
}
(20-20/39)