Project

General

Profile

Download (6.51 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.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.model.location.NamedArea;
30
import eu.etaxonomy.cdm.model.taxon.Taxon;
31
import eu.etaxonomy.cdm.validation.Level2;
32

    
33
/**
34
 * This class represents elementary distribution data for a {@link Taxon taxon}.
35
 * Only {@link TaxonDescription taxon descriptions} may contain distributions.
36
 * A distribution instance consist of a {@link NamedArea named area} and of a {@link PresenceAbsenceTermBase status}
37
 * describing the absence or the presence of a taxon (like "extinct"
38
 * or "introduced") in this named area.
39
 * <P>
40
 * This class corresponds partially to: <ul>
41
 * <li> CodedDescriptionType according to the the SDD schema
42
 * <li> Distribution according to the TDWG ontology
43
 * </ul>
44
 *
45
 * @author m.doering
46
 * @version 1.0
47
 * @created 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 = Logger.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
    /* (non-Javadoc)
121
     * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
122
     */
123
    @Override
124
    @Deprecated
125
    public void setFeature(Feature feature) {
126
        super.setFeature(feature);
127
    }
128

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

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

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

    
169

    
170
//*********************************** CLONE *****************************************/
171

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

    
183
        try {
184
            Distribution result = (Distribution)super.clone();
185

    
186
            return result;
187
            //no changes to: area, status
188
        } catch (CloneNotSupportedException e) {
189
            logger.warn("Object does not implement cloneable");
190
            e.printStackTrace();
191
            return null;
192
        }
193
    }
194

    
195
// ************************* to String ***************************************************/
196

    
197
    /**
198
     * Implementation of the toString() function
199
     */
200
    @Override
201
    public String toString(){
202
        String result = "null";
203
        if (this.area != null){
204
            result = area.getTitleCache();
205
        }
206
        return result;
207
    }
208

    
209
}
(8-8/37)