Project

General

Profile

Download (6.36 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.description;
11

    
12
import javax.persistence.Entity;
13
import javax.persistence.FetchType;
14
import javax.persistence.ManyToOne;
15
import javax.validation.constraints.NotNull;
16
import javax.xml.bind.annotation.XmlAccessType;
17
import javax.xml.bind.annotation.XmlAccessorType;
18
import javax.xml.bind.annotation.XmlElement;
19
import javax.xml.bind.annotation.XmlIDREF;
20
import javax.xml.bind.annotation.XmlRootElement;
21
import javax.xml.bind.annotation.XmlSchemaType;
22
import javax.xml.bind.annotation.XmlType;
23

    
24
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
25
import org.hibernate.envers.Audited;
26
import org.hibernate.search.annotations.Indexed;
27
import org.hibernate.search.annotations.IndexedEmbedded;
28

    
29
import eu.etaxonomy.cdm.common.CdmUtils;
30
import eu.etaxonomy.cdm.model.location.NamedArea;
31
import eu.etaxonomy.cdm.model.taxon.Taxon;
32
import eu.etaxonomy.cdm.validation.Level2;
33

    
34
/**
35
 * This class represents elementary distribution data for a {@link Taxon taxon}.
36
 * Only {@link TaxonDescription taxon descriptions} may contain distributions.
37
 * A distribution instance consist of a {@link NamedArea named area} and of a {@link PresenceAbsenceTermBase status}
38
 * describing the absence or the presence of a taxon (like "extinct"
39
 * or "introduced") in this named area.
40
 * <P>
41
 * This class corresponds partially to: <ul>
42
 * <li> CodedDescriptionType according to the the SDD schema
43
 * <li> Distribution according to the TDWG ontology
44
 * </ul>
45
 *
46
 * @author m.doering
47
 * @since 08-Nov-2007 13:06:21
48
 */
49
@XmlAccessorType(XmlAccessType.FIELD)
50
@XmlType(name = "Distribution", propOrder = {
51
    "area",
52
    "status"
53
})
54
@XmlRootElement(name = "Distribution")
55
@Entity
56
@Audited
57
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
58
public class Distribution extends DescriptionElementBase implements Cloneable {
59
    private static final long serialVersionUID = 8366462435651559730L;
60

    
61
    private static final Logger logger = LogManager.getLogger(Distribution.class);
62

    
63
    @XmlElement(name = "NamedArea")
64
    @XmlIDREF
65
    @XmlSchemaType(name = "IDREF")
66
    @ManyToOne(fetch = FetchType.LAZY)
67
    @NotNull(groups = Level2.class)
68
    @IndexedEmbedded(depth=1)
69
    private NamedArea area;
70

    
71
    @XmlElement(name = "PresenceAbsenceStatus")
72
    @XmlIDREF
73
    @XmlSchemaType(name = "IDREF")
74
    @ManyToOne(fetch = FetchType.LAZY)
75
    @NotNull(groups = Level2.class)
76
    @IndexedEmbedded(depth=1)
77
    private PresenceAbsenceTerm status;
78

    
79

    
80
    /**
81
     * Class constructor: creates a new empty distribution instance.
82
     * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
83
     */
84
    protected Distribution(){
85
        super();
86
    }
87

    
88

    
89
    /**
90
     * Creates an empty distribution instance. The corresponding {@link Feature feature}
91
     * is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
92
     *
93
     * @see		#NewInstance(NamedArea, PresenceAbsenceTermBase)
94
     */
95
    public static Distribution NewInstance(){
96
        Distribution result = new Distribution();
97
        result.setFeature(Feature.DISTRIBUTION());
98
        return result;
99
    }
100

    
101
    /**
102
     * Creates a distribution instance with the given {@link NamedArea named area} and {@link PresenceAbsenceTermBase status}.
103
     * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
104
     *
105
     * @param	area	the named area for the new distribution
106
     * @param	status	the presence or absence term for the new distribution
107
     * @see				#NewInstance()
108
     */
109
    public static Distribution NewInstance(NamedArea area, PresenceAbsenceTerm status){
110
        Distribution result = NewInstance();
111
        result.setArea(area);
112
        result.setStatus(status);
113
        return result;
114
    }
115

    
116
    /**
117
     * @deprecated Deprecated because {@link Feature feature} should always be {@link Feature#DISTRIBUTION() DISTRIBUTION}
118
     * for all distribution instances and therefore it should not be changed.
119
     */
120
    @Override
121
    @Deprecated
122
    public void setFeature(Feature feature) {
123
        super.setFeature(feature);
124
    }
125

    
126
    /**
127
     * Returns the {@link NamedArea named area} <i>this</i> distribution applies to.
128
     */
129
    public NamedArea getArea(){
130
        return this.area;
131
    }
132
    /**
133
     * @see	#getArea()
134
     */
135
    public void setArea(NamedArea area){
136
        this.area = area;
137
    }
138

    
139
    /**
140
     * Returns the {@link PresenceAbsenceTerm presence or absence term} for <i>this</i> distribution.
141
     */
142
    public PresenceAbsenceTerm getStatus(){
143
        return this.status;
144
    }
145
    /**
146
     * @see	#getStatus()
147
     */
148
    public void setStatus(PresenceAbsenceTerm status){
149
        this.status = status;
150
    }
151

    
152
    /**
153
     * Special function for building the sorted distribution tree. The function returns true
154
     * if the sources of the two different objects are different
155
     * @param dist
156
     * @return
157
     */
158
    public boolean isDifferentSources(Distribution dist){
159
        boolean result = false;
160
        if(this.getSources().equals(dist.getSources())){
161
            result = true;
162
        }
163
        return result;
164
    }
165

    
166

    
167
//*********************************** CLONE *****************************************/
168

    
169
    /**
170
     * Clones <i>this</i> distribution. This is a shortcut that enables to create
171
     * a new instance that differs only slightly from <i>this</i> distribution by
172
     * modifying only some of the attributes.
173
     *
174
     * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
175
     * @see java.lang.Object#clone()
176
     */
177
    @Override
178
    public Distribution clone() {
179

    
180
        Distribution result = (Distribution)super.clone();
181

    
182
        return result;
183
        //no changes to: area, status
184
    }
185

    
186
// ************************* to String ***************************************************/
187

    
188
    /**
189
     * Implementation of the toString() function
190
     */
191
    @Override
192
    public String toString(){
193
        String result = "null";
194
        if (this.area != null){
195
            result = area.getTitleCache();
196
        }
197
        if (this.status != null){
198
            result = CdmUtils.concat(":", result, this.status.getTitleCache());
199
        }
200
        return result;
201
    }
202

    
203
}
(10-10/38)