| 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.io.Serializable; |
|---|
| 13 | import java.net.URI; |
|---|
| 14 | import java.util.HashSet; |
|---|
| 15 | import java.util.List; |
|---|
| 16 | import java.util.Map; |
|---|
| 17 | import java.util.Set; |
|---|
| 18 | import java.util.UUID; |
|---|
| 19 | |
|---|
| 20 | import javax.persistence.Transient; |
|---|
| 21 | import javax.xml.bind.annotation.XmlEnum; |
|---|
| 22 | import javax.xml.bind.annotation.XmlEnumValue; |
|---|
| 23 | import javax.xml.bind.annotation.XmlType; |
|---|
| 24 | |
|---|
| 25 | import org.apache.log4j.Logger; |
|---|
| 26 | import org.joda.time.DateTime; |
|---|
| 27 | |
|---|
| 28 | import au.com.bytecode.opencsv.CSVWriter; |
|---|
| 29 | import eu.etaxonomy.cdm.model.common.Annotation; |
|---|
| 30 | import eu.etaxonomy.cdm.model.common.Credit; |
|---|
| 31 | import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|---|
| 32 | import eu.etaxonomy.cdm.model.common.Extension; |
|---|
| 33 | import eu.etaxonomy.cdm.model.common.IDefinedTerm; |
|---|
| 34 | import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
|---|
| 35 | import eu.etaxonomy.cdm.model.common.LSID; |
|---|
| 36 | import eu.etaxonomy.cdm.model.common.Language; |
|---|
| 37 | import eu.etaxonomy.cdm.model.common.Marker; |
|---|
| 38 | import eu.etaxonomy.cdm.model.common.Representation; |
|---|
| 39 | import eu.etaxonomy.cdm.model.common.User; |
|---|
| 40 | import eu.etaxonomy.cdm.model.media.Media; |
|---|
| 41 | import eu.etaxonomy.cdm.model.media.Rights; |
|---|
| 42 | import eu.etaxonomy.cdm.model.reference.Reference; |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * The class for the five nomenclature codes (ICNB, ICBN, ICNCP, ICZN and ICVCN) |
|---|
| 46 | * ruling {@link TaxonNameBase taxon names}. |
|---|
| 47 | * <P> |
|---|
| 48 | * The standard set of nomenclature code instances will be automatically created |
|---|
| 49 | * as the project starts. But this class allows to extend this standard set by |
|---|
| 50 | * creating new instances of additional nomenclature codes if unlikely needed. |
|---|
| 51 | * <P> |
|---|
| 52 | * This class corresponds to: <ul> |
|---|
| 53 | * <li> NomenclaturalCodeTerm according to the TDWG ontology |
|---|
| 54 | * <li> NomenclaturalCodesEnum according to the TCS |
|---|
| 55 | * <li> CodeOfNomenclatureEnum according to the ABCD schema |
|---|
| 56 | * </ul> |
|---|
| 57 | * |
|---|
| 58 | * @author a.mueller |
|---|
| 59 | * @created 19.05.2008 |
|---|
| 60 | * @version 2.0 |
|---|
| 61 | */ |
|---|
| 62 | |
|---|
| 63 | @XmlType(name = "NomenclaturalCode") |
|---|
| 64 | @XmlEnum |
|---|
| 65 | public enum NomenclaturalCode implements IDefinedTerm<NomenclaturalCode>, Serializable { |
|---|
| 66 | /** |
|---|
| 67 | * International Code of Nomenclature of Bacteria |
|---|
| 68 | */ |
|---|
| 69 | @XmlEnumValue("ICNB") ICNB(UUID.fromString("ff4b0979-7abf-4b40-95c0-8b8b1e8a4d5e"), "ICNB"), |
|---|
| 70 | /** |
|---|
| 71 | * International Code of Botanical Nomenclature |
|---|
| 72 | */ |
|---|
| 73 | @XmlEnumValue("ICBN") ICBN(UUID.fromString("540fc02a-8a8e-4813-89d2-581dad4dd482"), "ICBN"), |
|---|
| 74 | /** |
|---|
| 75 | * International Code of Cultivated Plants |
|---|
| 76 | */ |
|---|
| 77 | @XmlEnumValue("ICNCP") ICNCP(UUID.fromString("65a432b5-92b1-4c9a-8090-2a185e423d2e"),"ICNCP"), |
|---|
| 78 | /** |
|---|
| 79 | * International Code of Zoological Nomenclature |
|---|
| 80 | */ |
|---|
| 81 | @XmlEnumValue("ICZN") ICZN(UUID.fromString("b584c2f8-dbe5-4454-acad-2b45e63ec11b"), "ICZN"), |
|---|
| 82 | /** |
|---|
| 83 | * International Code for Virus Classification and Nomenclature |
|---|
| 84 | */ |
|---|
| 85 | @XmlEnumValue("ICVCN") ICVCN(UUID.fromString("e9d6d6b4-ccb7-4f28-b828-0b1501f8c75a"), "ICVCN"); |
|---|
| 86 | |
|---|
| 87 | private static final Logger logger = Logger.getLogger(NomenclaturalCode.class); |
|---|
| 88 | |
|---|
| 89 | private UUID uuid; |
|---|
| 90 | |
|---|
| 91 | private String titleCache; |
|---|
| 92 | |
|---|
| 93 | public String getTitleCache() { |
|---|
| 94 | return titleCache; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | private NomenclaturalCode(UUID uuid, String titleCache){ |
|---|
| 98 | this.uuid = uuid; |
|---|
| 99 | this.titleCache = titleCache; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | /* (non-Javadoc) |
|---|
| 105 | * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getUuid() |
|---|
| 106 | */ |
|---|
| 107 | public UUID getUuid(){ |
|---|
| 108 | return this.uuid; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /* (non-Javadoc) |
|---|
| 112 | * @see java.lang.Enum#toString() |
|---|
| 113 | */ |
|---|
| 114 | @Override |
|---|
| 115 | public String toString() { |
|---|
| 116 | return "NomenclaturalCode" + " <" + uuid + "> " + this.name(); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | public static NomenclaturalCode fromString(String string){ |
|---|
| 120 | for(NomenclaturalCode code : NomenclaturalCode.values()){ |
|---|
| 121 | if(code.name().equals(string)) { |
|---|
| 122 | return code; |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | return null; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /* (non-Javadoc) |
|---|
| 129 | * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getByUuid(java.util.UUID) |
|---|
| 130 | */ |
|---|
| 131 | public NomenclaturalCode getByUuid(UUID uuid) { |
|---|
| 132 | for (NomenclaturalCode nomCode : NomenclaturalCode.values()){ |
|---|
| 133 | if (nomCode.getUuid().equals(uuid)){ |
|---|
| 134 | return nomCode; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | return null; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | /* (non-Javadoc) |
|---|
| 141 | * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getGeneralizationOf() |
|---|
| 142 | */ |
|---|
| 143 | public Set<NomenclaturalCode> getGeneralizationOf() { |
|---|
| 144 | return new HashSet<NomenclaturalCode>(); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | /* (non-Javadoc) |
|---|
| 148 | * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getIncludes() |
|---|
| 149 | */ |
|---|
| 150 | public Set<NomenclaturalCode> getIncludes() { |
|---|
| 151 | return new HashSet<NomenclaturalCode>(); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | /* (non-Javadoc) |
|---|
| 155 | * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getKindOf() |
|---|
| 156 | */ |
|---|
| 157 | public NomenclaturalCode getKindOf() { |
|---|
| 158 | return null; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /* (non-Javadoc) |
|---|
| 163 | * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getPartOf() |
|---|
| 164 | */ |
|---|
| 165 | public NomenclaturalCode getPartOf() { |
|---|
| 166 | return null; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | /* (non-Javadoc) |
|---|
| 170 | * @see eu.etaxonomy.cdm.model.common.IDefinedTerm#getMedia() |
|---|
| 171 | */ |
|---|
| 172 | public Set<Media> getMedia() { |
|---|
| 173 | // TODO add links to codes |
|---|
| 174 | return new HashSet<Media>(); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | /* (non-Javadoc) |
|---|
| 179 | * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#readCsvLine(java.lang.Class, java.util.List, java.util.Map) |
|---|
| 180 | */ |
|---|
| 181 | public NomenclaturalCode readCsvLine(Class<NomenclaturalCode> termClass, |
|---|
| 182 | List<String> csvLine, Map<UUID, DefinedTermBase> terms) { |
|---|
| 183 | return null; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | /* (non-Javadoc) |
|---|
| 187 | * @see eu.etaxonomy.cdm.model.common.ILoadableTerm#writeCsvLine(au.com.bytecode.opencsv.CSVWriter, eu.etaxonomy.cdm.model.common.IDefinedTerm) |
|---|
| 188 | */ |
|---|
| 189 | public void writeCsvLine(CSVWriter writer, NomenclaturalCode term) { |
|---|
| 190 | logger.warn("write csvLine not yet implemented"); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | /** |
|---|
| 194 | * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological, |
|---|
| 195 | * cultivar plant, bacterial or viral name) instance depending on <i>this</i> |
|---|
| 196 | * nomenclature code only containing the given {@link Rank rank}. |
|---|
| 197 | * |
|---|
| 198 | * @param rank the rank of the new taxon name instance |
|---|
| 199 | * @see BotanicalName#NewInstance(Rank) |
|---|
| 200 | * @see ZoologicalName#NewInstance(Rank) |
|---|
| 201 | * @see CultivarPlantName#NewInstance(Rank) |
|---|
| 202 | * @see BacterialName#NewInstance(Rank) |
|---|
| 203 | * @see ViralName#NewInstance(Rank) |
|---|
| 204 | */ |
|---|
| 205 | public TaxonNameBase<?,?> getNewTaxonNameInstance(Rank rank){ |
|---|
| 206 | TaxonNameBase<?,?> result; |
|---|
| 207 | NomenclaturalCode nomCode = this; |
|---|
| 208 | |
|---|
| 209 | switch (this){ |
|---|
| 210 | case ICBN: |
|---|
| 211 | result = BotanicalName.NewInstance(rank); |
|---|
| 212 | break; |
|---|
| 213 | case ICZN: |
|---|
| 214 | result = ZoologicalName.NewInstance(rank); |
|---|
| 215 | break; |
|---|
| 216 | case ICNCP: |
|---|
| 217 | result = CultivarPlantName.NewInstance(rank); |
|---|
| 218 | break; |
|---|
| 219 | case ICNB: |
|---|
| 220 | result = BacterialName.NewInstance(rank); |
|---|
| 221 | break; |
|---|
| 222 | case ICVCN: |
|---|
| 223 | result = ViralName.NewInstance(rank); |
|---|
| 224 | break; |
|---|
| 225 | default: |
|---|
| 226 | logger.warn("Unknown nomenclatural code: " + this.getUuid()); |
|---|
| 227 | result = null; |
|---|
| 228 | } |
|---|
| 229 | return result; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | /** |
|---|
| 233 | * Creates a new particular {@link TaxonNameBase taxon name} (botanical, zoological, |
|---|
| 234 | * cultivar plant, bacterial or viral name) instance depending on <i>this</i> |
|---|
| 235 | * nomenclature code only containing the given {@link Rank rank}. |
|---|
| 236 | * |
|---|
| 237 | * @param rank the rank of the new taxon name instance |
|---|
| 238 | * @see BotanicalName#NewInstance(Rank) |
|---|
| 239 | * @see ZoologicalName#NewInstance(Rank) |
|---|
| 240 | * @see CultivarPlantName#NewInstance(Rank) |
|---|
| 241 | * @see BacterialName#NewInstance(Rank) |
|---|
| 242 | * @see ViralName#NewInstance(Rank) |
|---|
| 243 | */ |
|---|
| 244 | @Transient |
|---|
| 245 | public <T extends TaxonNameBase> Class<? extends T> getCdmClass(){ |
|---|
| 246 | Class<? extends T> result; |
|---|
| 247 | switch (this){ |
|---|
| 248 | case ICBN: |
|---|
| 249 | result = (Class<T>)BotanicalName.class; |
|---|
| 250 | break; |
|---|
| 251 | case ICZN: |
|---|
| 252 | result = (Class<T>)ZoologicalName.class; |
|---|
| 253 | break; |
|---|
| 254 | case ICNCP: |
|---|
| 255 | result = (Class<T>)CultivarPlantName.class; |
|---|
| 256 | break; |
|---|
| 257 | case ICNB: |
|---|
| 258 | result = (Class<T>)BacterialName.class; |
|---|
| 259 | break; |
|---|
| 260 | case ICVCN: |
|---|
| 261 | result = (Class<T>)ViralName.class; |
|---|
| 262 | break; |
|---|
| 263 | default: |
|---|
| 264 | logger.warn("Unknown nomenclatural code: " + this.getUuid()); |
|---|
| 265 | result = null; |
|---|
| 266 | } |
|---|
| 267 | return result; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | /** |
|---|
| 271 | * Returns the recommended value for the accepted taxon status according to |
|---|
| 272 | * http://code.google.com/p/darwincore/wiki/Taxon#taxonomicStatus |
|---|
| 273 | */ |
|---|
| 274 | public String acceptedTaxonStatusLabel(){ |
|---|
| 275 | switch(this){ |
|---|
| 276 | case ICBN: |
|---|
| 277 | return "accepted"; |
|---|
| 278 | case ICZN: |
|---|
| 279 | return "valid"; |
|---|
| 280 | default: |
|---|
| 281 | logger.error("Not implemented yet"); |
|---|
| 282 | return "accepted"; |
|---|
| 283 | } |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | /** |
|---|
| 287 | * Returns the recommended value for the accepted taxon status according to |
|---|
| 288 | * http://code.google.com/p/darwincore/wiki/Taxon#taxonomicStatus |
|---|
| 289 | */ |
|---|
| 290 | public String synonymStatusLabel(){ |
|---|
| 291 | switch(this){ |
|---|
| 292 | case ICBN: |
|---|
| 293 | return "synonym"; |
|---|
| 294 | case ICZN: |
|---|
| 295 | return "invalid"; |
|---|
| 296 | default: |
|---|
| 297 | logger.error("Not implemented yet"); |
|---|
| 298 | return "synonym"; |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | } |
|---|