| 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.description; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | import java.util.HashMap; |
|---|
| 14 | import java.util.Map; |
|---|
| 15 | import java.util.UUID; |
|---|
| 16 | |
|---|
| 17 | import javax.persistence.Entity; |
|---|
| 18 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 19 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 20 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 21 | import javax.xml.bind.annotation.XmlType; |
|---|
| 22 | |
|---|
| 23 | import org.apache.log4j.Logger; |
|---|
| 24 | import org.hibernate.envers.Audited; |
|---|
| 25 | import org.hibernate.search.annotations.Indexed; |
|---|
| 26 | |
|---|
| 27 | import eu.etaxonomy.cdm.model.common.Language; |
|---|
| 28 | import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|---|
| 29 | import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * The class representing the restriction concerning the sex for |
|---|
| 33 | * the applicability of {@link TaxonDescription taxon descriptions}. The sex of a |
|---|
| 34 | * {@link SpecimenOrObservationBase specimen or observation} |
|---|
| 35 | * does not belong to a {@link SpecimenDescription specimen description} but is an attribute of |
|---|
| 36 | * the specimen itself. |
|---|
| 37 | * |
|---|
| 38 | * @author m.doering |
|---|
| 39 | * @version 1.0 |
|---|
| 40 | * @created 08-Nov-2007 13:06:52 |
|---|
| 41 | */ |
|---|
| 42 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 43 | @XmlType(name = "Sex") |
|---|
| 44 | @XmlRootElement(name = "Sex") |
|---|
| 45 | @Entity |
|---|
| 46 | @Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase") |
|---|
| 47 | @Audited |
|---|
| 48 | public class Sex extends Scope { |
|---|
| 49 | private static final long serialVersionUID = 3463642992193419657L; |
|---|
| 50 | @SuppressWarnings("unused") |
|---|
| 51 | private static final Logger logger = Logger.getLogger(Sex.class); |
|---|
| 52 | |
|---|
| 53 | protected static Map<UUID, Sex> termMap = null; |
|---|
| 54 | |
|---|
| 55 | private static final UUID uuidMale = UUID.fromString("600a5212-cc02-431d-8a80-2bf595bd1eab"); |
|---|
| 56 | private static final UUID uuidFemale = UUID.fromString("b4cfe0cb-b35c-4f97-9b6b-2b3c096ea2c0"); |
|---|
| 57 | private static final UUID uuidHermaphrodite = UUID.fromString("0deddc65-2505-4c77-91a7-17d0de24afcc"); |
|---|
| 58 | private static final UUID uuidUnknown = UUID.fromString("4f5e4c51-a664-48ad-8238-2e9f49eaf8dd"); |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | * Creates a new empty sex instance. |
|---|
| 64 | * |
|---|
| 65 | * @see #Sex(String, String, String) |
|---|
| 66 | */ |
|---|
| 67 | public static Sex NewInstance(){ |
|---|
| 68 | return new Sex(); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | /** |
|---|
| 72 | * Creates a new sex instance with a description (in the {@link Language#DEFAULT() default language}), |
|---|
| 73 | * a label and a label abbreviation. |
|---|
| 74 | * |
|---|
| 75 | * @param term the string (in the default language) describing the |
|---|
| 76 | * new sex to be created |
|---|
| 77 | * @param label the string identifying the new sex to be created |
|---|
| 78 | * @param labelAbbrev the string identifying (in abbreviated form) the |
|---|
| 79 | * new sex to be created |
|---|
| 80 | * @see #NewInstance() |
|---|
| 81 | */ |
|---|
| 82 | public static Sex NewInstance(String term, String label, String labelAbbrev){ |
|---|
| 83 | return new Sex(term, label, labelAbbrev); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * Class constructor: creates a new empty sex instance. |
|---|
| 88 | * |
|---|
| 89 | * @see #Sex(String, String, String) |
|---|
| 90 | */ |
|---|
| 91 | public Sex() { |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Class constructor: creates a new sex instance with a description |
|---|
| 96 | * (in the {@link Language#DEFAULT() default language}), a label and a label abbreviation. |
|---|
| 97 | * |
|---|
| 98 | * @param term the string (in the default language) describing the |
|---|
| 99 | * new sex to be created |
|---|
| 100 | * @param label the string identifying the new sex to be created |
|---|
| 101 | * @param labelAbbrev the string identifying (in abbreviated form) the |
|---|
| 102 | * new sex to be created |
|---|
| 103 | * @see #Sex() |
|---|
| 104 | */ |
|---|
| 105 | public Sex(String term, String label, String labelAbbrev) { |
|---|
| 106 | super(term, label, labelAbbrev); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | //************************** METHODS ******************************** |
|---|
| 111 | |
|---|
| 112 | /* (non-Javadoc) |
|---|
| 113 | * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms() |
|---|
| 114 | */ |
|---|
| 115 | @Override |
|---|
| 116 | public void resetTerms(){ |
|---|
| 117 | termMap = null; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | protected static Sex getTermByUuid(UUID uuid){ |
|---|
| 122 | if (termMap == null){ |
|---|
| 123 | return null; //better return null then initialize the termMap in an unwanted way |
|---|
| 124 | } |
|---|
| 125 | return (Sex)termMap.get(uuid); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | public static Sex MALE(){ |
|---|
| 130 | return getTermByUuid(uuidMale); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | public static Sex FEMALE(){ |
|---|
| 134 | return getTermByUuid(uuidFemale); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | public static Sex HERMAPHRODITE(){ |
|---|
| 138 | return getTermByUuid(uuidHermaphrodite); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | public static Sex UNKNOWN(){ |
|---|
| 142 | return getTermByUuid(uuidUnknown); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | @Override |
|---|
| 146 | protected void setDefaultTerms(TermVocabulary<Modifier> termVocabulary) { |
|---|
| 147 | termMap = new HashMap<UUID, Sex>(); |
|---|
| 148 | for (Modifier term : termVocabulary.getTerms()){ |
|---|
| 149 | termMap.put(term.getUuid(), (Sex)term); |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | } |
|---|