2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.description
;
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
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.hibernate
.envers
.Audited
;
26 import org
.hibernate
.search
.annotations
.Indexed
;
28 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 import eu
.etaxonomy
.cdm
.validation
.Level2
;
33 * This class represents elementary distribution data for a {@link Taxon taxon}.
34 * Only {@link TaxonDescription taxon descriptions} may contain distributions.
35 * A distribution instance consist of a {@link NamedArea named area} and of a {@link PresenceAbsenceTermBase status}
36 * describing the absence or the presence of a taxon (like "extinct"
37 * or "introduced") in this named area.
39 * This class corresponds partially to: <ul>
40 * <li> CodedDescriptionType according to the the SDD schema
41 * <li> Distribution according to the TDWG ontology
46 * @created 08-Nov-2007 13:06:21
48 @XmlAccessorType(XmlAccessType
.FIELD
)
49 @XmlType(name
= "Distribution", propOrder
= {
53 @XmlRootElement(name
= "Distribution")
56 @Indexed(index
= "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
57 public class Distribution
extends DescriptionElementBase
{
58 private static final long serialVersionUID
= 8366462435651559730L;
59 @SuppressWarnings("unused")
60 private static final Logger logger
= Logger
.getLogger(Distribution
.class);
62 @XmlElement(name
= "NamedArea")
64 @XmlSchemaType(name
= "IDREF")
65 @ManyToOne(fetch
= FetchType
.LAZY
)
66 @NotNull(groups
= Level2
.class)
67 private NamedArea area
;
69 @XmlElement(name
= "PresenceAbsenceStatus")
71 @XmlSchemaType(name
= "IDREF")
72 @ManyToOne(fetch
= FetchType
.LAZY
)
73 @NotNull(groups
= Level2
.class)
74 private PresenceAbsenceTermBase
<?
> status
;
78 * Class constructor: creates a new empty distribution instance.
79 * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
81 protected Distribution(){
87 * Creates an empty distribution instance. The corresponding {@link Feature feature}
88 * is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
90 * @see #NewInstance(NamedArea, PresenceAbsenceTermBase)
92 public static Distribution
NewInstance(){
93 Distribution result
= new Distribution();
94 result
.setFeature(Feature
.DISTRIBUTION());
99 * Creates a distribution instance with the given {@link NamedArea named area} and {@link PresenceAbsenceTermBase status}.
100 * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
102 * @param area the named area for the new distribution
103 * @param status the presence or absence term for the new distribution
104 * @see #NewInstance()
106 public static Distribution
NewInstance(NamedArea area
, PresenceAbsenceTermBase
<?
> status
){
107 Distribution result
= NewInstance();
108 result
.setArea(area
);
109 result
.setStatus(status
);
114 * @deprecated Deprecated because {@link Feature feature} should always be {@link Feature#DISTRIBUTION() DISTRIBUTION}
115 * for all distribution instances and therefore it should not be changed.
118 * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
122 public void setFeature(Feature feature
) {
123 super.setFeature(feature
);
127 * Returns the {@link NamedArea named area} <i>this</i> distribution applies to.
129 public NamedArea
getArea(){
135 public void setArea(NamedArea area
){
140 * Returns the {@link PresenceAbsenceTermBase presence or absence term} for <i>this</i> distribution.
142 public PresenceAbsenceTermBase
<?
> getStatus(){
148 public void setStatus(PresenceAbsenceTermBase
<?
> status
){
149 this.status
= status
;
153 * Special equal method for building an sorted distribution tree
157 public boolean equalsForTree(Distribution dist
){
158 boolean result
= false;
159 //same area level and area label
160 if (this.getArea().getLabel().compareTo(dist
.getArea().getLabel()) == 0 &&
161 this.getArea().getLevel().getLabel().compareTo(dist
.getArea().getLevel().getLabel()) == 0){
169 * Special function for building the sorted distribution tree. The function returns true
170 * if the sources of the two different objects are different
174 public boolean isDifferentSources(Distribution dist
){
175 boolean result
= false;
176 if(this.getSources().equals(dist
.getSources())){
183 * Implementation of the toString() function
185 public String
toString(){
186 String result
= "null";
187 if (this.area
!= null){
188 result
= area
.getLabel().toString();