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
.annotations
.Cascade
;
26 import org
.hibernate
.annotations
.CascadeType
;
27 import org
.hibernate
.envers
.Audited
;
28 import org
.hibernate
.search
.annotations
.Indexed
;
30 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
32 import eu
.etaxonomy
.cdm
.validation
.Level2
;
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.
41 * This class corresponds partially to: <ul>
42 * <li> CodedDescriptionType according to the the SDD schema
43 * <li> Distribution according to the TDWG ontology
48 * @created 08-Nov-2007 13:06:21
50 @XmlAccessorType(XmlAccessType
.FIELD
)
51 @XmlType(name
= "Distribution", propOrder
= {
55 @XmlRootElement(name
= "Distribution")
58 @Indexed(index
= "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
59 public class Distribution
extends DescriptionElementBase
{
60 private static final long serialVersionUID
= 8366462435651559730L;
61 @SuppressWarnings("unused")
62 private static final Logger logger
= Logger
.getLogger(Distribution
.class);
64 @XmlElement(name
= "NamedArea")
66 @XmlSchemaType(name
= "IDREF")
67 @ManyToOne(fetch
= FetchType
.LAZY
)
68 @NotNull(groups
= Level2
.class)
69 private NamedArea area
;
71 @XmlElement(name
= "PresenceAbsenceStatus")
73 @XmlSchemaType(name
= "IDREF")
74 @ManyToOne(fetch
= FetchType
.LAZY
)
75 @NotNull(groups
= Level2
.class)
76 private PresenceAbsenceTermBase
<?
> status
;
80 * Class constructor: creates a new empty distribution instance.
81 * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
83 protected Distribution(){
89 * Creates an empty distribution instance. The corresponding {@link Feature feature}
90 * is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
92 * @see #NewInstance(NamedArea, PresenceAbsenceTermBase)
94 public static Distribution
NewInstance(){
95 Distribution result
= new Distribution();
96 result
.setType(Feature
.DISTRIBUTION());
101 * Creates a distribution instance with the given {@link NamedArea named area} and {@link PresenceAbsenceTermBase status}.
102 * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
104 * @param area the named area for the new distribution
105 * @param status the presence or absence term for the new distribution
106 * @see #NewInstance()
108 public static Distribution
NewInstance(NamedArea area
, PresenceAbsenceTermBase
<?
> status
){
109 Distribution result
= NewInstance();
110 result
.setArea(area
);
111 result
.setStatus(status
);
116 * Deprecated because {@link Feature feature} should always be {@link Feature#DISTRIBUTION() DISTRIBUTION}
117 * for all distribution instances.
120 * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
124 public void setFeature(Feature feature
) {
125 super.setFeature(feature
);
129 * Returns the {@link NamedArea named area} <i>this</i> distribution applies to.
131 public NamedArea
getArea(){
137 public void setArea(NamedArea area
){
142 * Returns the {@link PresenceAbsenceTermBase presence or absence term} for <i>this</i> distribution.
144 public PresenceAbsenceTermBase
<?
> getStatus(){
150 public void setStatus(PresenceAbsenceTermBase
<?
> status
){
151 this.status
= status
;
155 * Special equal method for building an sorted distribution tree
159 public boolean equalsForTree(Distribution dist
){
160 boolean result
= false;
161 //same area level and area label
162 if (this.getArea().getLabel().compareTo(dist
.getArea().getLabel()) == 0 &&
163 this.getArea().getLevel().getLabel().compareTo(dist
.getArea().getLevel().getLabel()) == 0){
171 * Special function for building the sorted distribution tree. The function returns true
172 * if the sources of the two different objects are different
176 public boolean isDifferentSources(Distribution dist
){
177 boolean result
= false;
178 if(this.getSources().equals(dist
.getSources())){
185 * Implementation of the toString() function
187 public String
toString(){
188 String result
= "null";
189 if (this.area
!= null){
190 result
= area
.getLabel().toString();