| 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.agent; |
|---|
| 11 | |
|---|
| 12 | import java.util.HashMap; |
|---|
| 13 | import java.util.Map; |
|---|
| 14 | import java.util.UUID; |
|---|
| 15 | |
|---|
| 16 | import javax.persistence.Entity; |
|---|
| 17 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 18 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 19 | import javax.xml.bind.annotation.XmlType; |
|---|
| 20 | |
|---|
| 21 | import org.apache.log4j.Logger; |
|---|
| 22 | import org.hibernate.envers.Audited; |
|---|
| 23 | import org.hibernate.search.annotations.Indexed; |
|---|
| 24 | |
|---|
| 25 | import eu.etaxonomy.cdm.model.common.DefaultTermInitializer; |
|---|
| 26 | import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|---|
| 27 | import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * Represents an element of a controlled {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary} for different kinds of institutions. |
|---|
| 31 | * Each {@link DefinedTermBase element} belongs to one vocabulary. |
|---|
| 32 | * <p> |
|---|
| 33 | * This class corresponds to: InstitutionTypeTerm according to the TDWG ontology. |
|---|
| 34 | * |
|---|
| 35 | * @author m.doering |
|---|
| 36 | * @version 1.0 |
|---|
| 37 | * @created 08-Nov-2007 13:06:30 |
|---|
| 38 | */ |
|---|
| 39 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 40 | @XmlType(name = "InstitutionType") |
|---|
| 41 | @Entity |
|---|
| 42 | @Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase") |
|---|
| 43 | @Audited |
|---|
| 44 | public class InstitutionType extends DefinedTermBase<InstitutionType> { |
|---|
| 45 | private static final long serialVersionUID = 8714866112728127219L; |
|---|
| 46 | public static final Logger logger = Logger.getLogger(InstitutionType.class); |
|---|
| 47 | |
|---|
| 48 | protected static Map<UUID, InstitutionType> termMap = null; |
|---|
| 49 | |
|---|
| 50 | // ************* CONSTRUCTORS *************/ |
|---|
| 51 | /** |
|---|
| 52 | * Class constructor: creates a new empty institution type. |
|---|
| 53 | * |
|---|
| 54 | * @see #InstitutionType(String, String, String) |
|---|
| 55 | */ |
|---|
| 56 | public InstitutionType() { |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | * Class constructor using a description (in the {@link eu.etaxonomy.cdm.model.common.Language#DEFAULT() default language}), |
|---|
| 61 | * a label and a label abbreviation. |
|---|
| 62 | * |
|---|
| 63 | * @param term the string describing this new vocabulary element |
|---|
| 64 | * @param label the string which identifies this new vocabulary element |
|---|
| 65 | * @param labelAbbrev the string identifying (in abbreviated form) this |
|---|
| 66 | * new vocabulary element |
|---|
| 67 | * @see #InstitutionType() |
|---|
| 68 | * @see eu.etaxonomy.cdm.model.common.Representation |
|---|
| 69 | * @see eu.etaxonomy.cdm.model.common.TermBase#TermBase(String, String, String) |
|---|
| 70 | */ |
|---|
| 71 | public InstitutionType(String term, String label, String labelAbbrev) { |
|---|
| 72 | super(term, label, labelAbbrev); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | /* (non-Javadoc) |
|---|
| 77 | * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms() |
|---|
| 78 | */ |
|---|
| 79 | @Override |
|---|
| 80 | public void resetTerms(){ |
|---|
| 81 | termMap = null; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | protected static InstitutionType getTermByUuid(UUID uuid){ |
|---|
| 86 | if (termMap == null){ |
|---|
| 87 | DefaultTermInitializer vocabularyStore = new DefaultTermInitializer(); |
|---|
| 88 | vocabularyStore.initialize(); |
|---|
| 89 | } |
|---|
| 90 | return (InstitutionType)termMap.get(uuid); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | @Override |
|---|
| 96 | protected void setDefaultTerms(TermVocabulary<InstitutionType> termVocabulary){ |
|---|
| 97 | termMap = new HashMap<UUID, InstitutionType>(); |
|---|
| 98 | for (InstitutionType term : termVocabulary.getTerms()){ |
|---|
| 99 | termMap.put(term.getUuid(), term); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | } |
|---|