| 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.location; |
|---|
| 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.DefinedTermBase; |
|---|
| 28 | import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * Controlled vocabulary to differentiate categories of areas |
|---|
| 32 | * @author m.doering |
|---|
| 33 | * @version 1.0 |
|---|
| 34 | * @created 08-Nov-2007 13:06:37 |
|---|
| 35 | */ |
|---|
| 36 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 37 | @XmlType(name = "NamedAreaType") |
|---|
| 38 | @XmlRootElement(name = "NamedAreaType") |
|---|
| 39 | @Entity |
|---|
| 40 | @Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase") |
|---|
| 41 | @Audited |
|---|
| 42 | public class NamedAreaType extends DefinedTermBase<NamedAreaType> { |
|---|
| 43 | private static final long serialVersionUID = 8280172429797206548L; |
|---|
| 44 | private static final Logger logger = Logger.getLogger(NamedAreaType.class); |
|---|
| 45 | |
|---|
| 46 | protected static Map<UUID, NamedAreaType> termMap = null; |
|---|
| 47 | |
|---|
| 48 | private static final UUID uuidNaturalArea = UUID.fromString("cc33167c-d366-4030-b984-6b14e4f5fd22"); |
|---|
| 49 | private static final UUID uuidAdministrationArea = UUID.fromString("1799f581-f425-40d6-a4db-ec2c638c0e92"); |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * Factory method |
|---|
| 54 | * @return |
|---|
| 55 | */ |
|---|
| 56 | public static NamedAreaType NewInstance(String term, String label, String labelAbbrev){ |
|---|
| 57 | logger.debug("NewInstance"); |
|---|
| 58 | return new NamedAreaType(term, label, labelAbbrev); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * Constructor |
|---|
| 63 | */ |
|---|
| 64 | public NamedAreaType(String term, String label, String labelAbbrev) { |
|---|
| 65 | super(term, label, labelAbbrev); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | public NamedAreaType(){ |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | //************************** METHODS ******************************** |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | /* (non-Javadoc) |
|---|
| 75 | * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms() |
|---|
| 76 | */ |
|---|
| 77 | @Override |
|---|
| 78 | public void resetTerms(){ |
|---|
| 79 | termMap = null; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | protected static NamedAreaType getTermByUuid(UUID uuid){ |
|---|
| 84 | if (termMap == null){ |
|---|
| 85 | return null; //better return null then initialize the termMap in an unwanted way |
|---|
| 86 | } |
|---|
| 87 | return (NamedAreaType)termMap.get(uuid); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | * The boundaries are given by natural factors (mountains, valleys, climate, etc.) |
|---|
| 92 | */ |
|---|
| 93 | public static final NamedAreaType NATURAL_AREA(){ |
|---|
| 94 | return getTermByUuid(uuidNaturalArea); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | /** |
|---|
| 98 | * The boundaries depend on administration (county, state, reserve, etc.) |
|---|
| 99 | */ |
|---|
| 100 | public static final NamedAreaType ADMINISTRATION_AREA(){ |
|---|
| 101 | return getTermByUuid(uuidAdministrationArea); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | @Override |
|---|
| 105 | protected void setDefaultTerms(TermVocabulary<NamedAreaType> termVocabulary) { |
|---|
| 106 | termMap = new HashMap<UUID, NamedAreaType>(); |
|---|
| 107 | for (NamedAreaType term : termVocabulary.getTerms()){ |
|---|
| 108 | termMap.put(term.getUuid(), (NamedAreaType)term); |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | } |
|---|