root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/NamedAreaType.java

Revision 10455, 3.1 kB (checked in by a.mueller, 20 months ago)

reset for defined terms

  • Property svn:keywords set to Id
Line 
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
10package eu.etaxonomy.cdm.model.location;
11
12
13import java.util.HashMap;
14import java.util.Map;
15import java.util.UUID;
16
17import javax.persistence.Entity;
18import javax.xml.bind.annotation.XmlAccessType;
19import javax.xml.bind.annotation.XmlAccessorType;
20import javax.xml.bind.annotation.XmlRootElement;
21import javax.xml.bind.annotation.XmlType;
22
23import org.apache.log4j.Logger;
24import org.hibernate.envers.Audited;
25import org.hibernate.search.annotations.Indexed;
26
27import eu.etaxonomy.cdm.model.common.DefinedTermBase;
28import 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
42public 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}
Note: See TracBrowser for help on using the browser.