Project

General

Profile

Download (3.27 KB) Statistics
| Branch: | Tag: | Revision:
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

    
26
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
27
import eu.etaxonomy.cdm.model.common.TermType;
28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
29

    
30
/**
31
 * Controlled vocabulary to differentiate categories of areas
32
 * @author m.doering
33
 * @since 08-Nov-2007 13:06:37
34
 */
35
@XmlAccessorType(XmlAccessType.FIELD)
36
@XmlType(name = "NamedAreaType")
37
@XmlRootElement(name = "NamedAreaType")
38
@Entity
39
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
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
// *********************** CONSTRUCTOR ******************************/
62

    
63
	//for hibernate use only
64
	@Deprecated
65
	protected NamedAreaType(){
66
		super(TermType.NamedAreaType);
67
	}
68

    
69
	private NamedAreaType(String term, String label, String labelAbbrev) {
70
		super(TermType.NamedAreaType, term, label, labelAbbrev);
71
	}
72

    
73
//************************** METHODS ********************************
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 NamedAreaType getTermByUuid(UUID uuid){
86
	    if (termMap == null || termMap.isEmpty()){
87
            return getTermByClassAndUUID(NamedAreaType.class, uuid);
88
        } else {
89
            return termMap.get(uuid);
90
        }
91
	}
92

    
93
	/**
94
	 * The boundaries are given by natural factors (mountains, valleys, climate, etc.)
95
	 */
96
	public static final NamedAreaType NATURAL_AREA(){
97
		return getTermByUuid(uuidNaturalArea);
98
	}
99

    
100
	/**
101
	 * The boundaries depend on administration (county, state, reserve, etc.)
102
	 */
103
	public static final NamedAreaType ADMINISTRATION_AREA(){
104
		return getTermByUuid(uuidAdministrationArea);
105
	}
106

    
107
	@Override
108
	protected void setDefaultTerms(TermVocabulary<NamedAreaType> termVocabulary) {
109
		termMap = new HashMap<UUID, NamedAreaType>();
110
		for (NamedAreaType term : termVocabulary.getTerms()){
111
			termMap.put(term.getUuid(), term);
112
		}
113
	}
114

    
115
}
(4-4/8)