Major changes to the cdmlib default term loading and initialization, plus indexing...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / Distribution.java
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 import javax.persistence.Entity;
13 import javax.persistence.FetchType;
14 import javax.persistence.ManyToOne;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlIDREF;
19 import javax.xml.bind.annotation.XmlRootElement;
20 import javax.xml.bind.annotation.XmlSchemaType;
21 import javax.xml.bind.annotation.XmlType;
22
23 import org.apache.log4j.Logger;
24 import org.hibernate.annotations.Cascade;
25 import org.hibernate.annotations.CascadeType;
26
27 import eu.etaxonomy.cdm.model.location.NamedArea;
28 import eu.etaxonomy.cdm.model.taxon.Taxon;
29
30 /**
31 * This class represents elementary distribution data for a {@link Taxon taxon}.
32 * Only {@link TaxonDescription taxon descriptions} may contain distributions.
33 * A distribution instance consist of a {@link NamedArea named area} and of a {@link PresenceAbsenceTermBase status}
34 * describing the absence or the presence of a taxon (like "extinct"
35 * or "introduced") in this named area.
36 * <P>
37 * This class corresponds partially to: <ul>
38 * <li> CodedDescriptionType according to the the SDD schema
39 * <li> Distribution according to the TDWG ontology
40 * </ul>
41 *
42 * @author m.doering
43 * @version 1.0
44 * @created 08-Nov-2007 13:06:21
45 */
46 @XmlAccessorType(XmlAccessType.FIELD)
47 @XmlType(name = "Distribution", propOrder = {
48 "area",
49 "status"
50 })
51 @XmlRootElement(name = "Distribution")
52 @Entity
53 //@Audited
54 public class Distribution extends DescriptionElementBase {
55 private static final long serialVersionUID = 8366462435651559730L;
56 @SuppressWarnings("unused")
57 private static final Logger logger = Logger.getLogger(Distribution.class);
58
59 @XmlElement(name = "NamedArea")
60 @XmlIDREF
61 @XmlSchemaType(name = "IDREF")
62 private NamedArea area;
63
64 @XmlElement(name = "PresenceAbsenceStatus")
65 @XmlIDREF
66 @XmlSchemaType(name = "IDREF")
67 private PresenceAbsenceTermBase<?> status;
68
69
70 /**
71 * Class constructor: creates a new empty distribution instance.
72 * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
73 */
74 protected Distribution(){
75 super(Feature.DISTRIBUTION());
76 }
77
78
79 /**
80 * Creates an empty distribution instance. The corresponding {@link Feature feature}
81 * is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
82 *
83 * @see #NewInstance(NamedArea, PresenceAbsenceTermBase)
84 */
85 public static Distribution NewInstance(){
86 Distribution result = new Distribution();
87 return result;
88 }
89
90 /**
91 * Creates a distribution instance with the given {@link NamedArea named area} and {@link PresenceAbsenceTermBase status}.
92 * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
93 *
94 * @param area the named area for the new distribution
95 * @param status the presence or absence term for the new distribution
96 * @see #NewInstance()
97 */
98 public static Distribution NewInstance(NamedArea area, PresenceAbsenceTermBase<?> status){
99 Distribution result = new Distribution();
100 result.setArea(area);
101 result.setStatus(status);
102 return result;
103 }
104
105
106
107
108 /**
109 * Deprecated because {@link Feature feature} should always be {@link Feature#DISTRIBUTION() DISTRIBUTION}
110 * for all distribution instances.
111 */
112 /* (non-Javadoc)
113 * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
114 */
115 @Override
116 @Deprecated
117 public void setFeature(Feature feature) {
118 super.setFeature(feature);
119 }
120
121 /**
122 * Returns the {@link NamedArea named area} <i>this</i> distribution applies to.
123 */
124 @ManyToOne(fetch = FetchType.LAZY)
125 @Cascade({CascadeType.SAVE_UPDATE})
126 public NamedArea getArea(){
127 return this.area;
128 }
129 /**
130 * @see #getArea()
131 */
132 public void setArea(NamedArea area){
133 this.area = area;
134 }
135
136 /**
137 * Returns the {@link PresenceAbsenceTermBase presence or absence term} for <i>this</i> distribution.
138 */
139 @ManyToOne(fetch = FetchType.LAZY)
140 public PresenceAbsenceTermBase<?> getStatus(){
141 return this.status;
142 }
143 /**
144 * @see #getStatus()
145 */
146 public void setStatus(PresenceAbsenceTermBase<?> status){
147 this.status = status;
148 }
149
150 }