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 java
.util
.ArrayList
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
16 import javax
.persistence
.Entity
;
17 import javax
.persistence
.FetchType
;
18 import javax
.persistence
.ManyToMany
;
19 import javax
.xml
.bind
.annotation
.XmlAccessType
;
20 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
21 import javax
.xml
.bind
.annotation
.XmlElement
;
22 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
23 import javax
.xml
.bind
.annotation
.XmlRootElement
;
24 import javax
.xml
.bind
.annotation
.XmlType
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.hibernate
.annotations
.Cascade
;
28 import org
.hibernate
.annotations
.CascadeType
;
29 import org
.hibernate
.envers
.Audited
;
30 import org
.hibernate
.search
.annotations
.Indexed
;
31 import org
.hibernate
.search
.annotations
.IndexedEmbedded
;
32 import org
.hibernate
.validator
.constraints
.NotEmpty
;
34 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
35 import eu
.etaxonomy
.cdm
.validation
.Level2
;
38 * This class represents information pieces expressed in categorical type of
39 * data (in opposition to {@link QuantitativeData quantitative data} on one side and to literal data on
40 * the other side). Only {@link TaxonDescription taxon descriptions} and
41 * {@link SpecimenDescription specimen descriptions} may contain categorical data.<BR>
42 * The "color of petals" {@link Feature feature} for instance can be described with
43 * {@link State state terms} such as "blue" or "white". If the color of petals of a
44 * particular tree is described as "mostly blue" and "exceptionally white" two
45 * {@link StateData state data} instances must be assigned to an instance of the
46 * present class: the first one with the state "blue" and the {@link Modifier modifier}
47 * "mostly" and the second one with the state "white" and the modifier "exceptionally".
48 * Whenever more than one state data belongs to a categorical data they should be
49 * interpreted as being related by the inclusive disjunction "or".
51 * This class corresponds partially to CodedDescriptionType according to
56 * @created 08-Nov-2007 13:06:15
58 @XmlAccessorType(XmlAccessType
.FIELD
)
59 @XmlType(name
= "CategoricalData", propOrder
= {
63 @XmlRootElement(name
= "CategoricalData")
66 @Indexed(index
= "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
67 public class CategoricalData
extends DescriptionElementBase
implements Cloneable
{
68 private static final long serialVersionUID
= -6298361966947668998L;
69 private static final Logger logger
= Logger
.getLogger(CategoricalData
.class);
71 //whether the sequence of ordered states is important
72 @XmlElement(name
= "OrderRelevant")
73 private boolean orderRelevant
;
75 @XmlElementWrapper(name
= "States")
76 @XmlElement(name
= "State")
77 @ManyToMany(fetch
= FetchType
.LAZY
)
78 @Cascade({ CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
,CascadeType
.DELETE_ORPHAN
})
79 @IndexedEmbedded(depth
= 2)
80 @NotEmpty(groups
= Level2
.class)
81 private List
<StateData
> states
= new ArrayList
<StateData
>();
85 * Class constructor: creates a new empty categorical data instance.
87 protected CategoricalData() {
92 * Creates a new empty categorical data instance.
94 public static CategoricalData
NewInstance(){
95 logger
.debug("NewInstance");
96 return new CategoricalData();
100 * Returns the (ordered) list of {@link State states} describing the {@link Feature feature}
101 * corresponding to <i>this</i> categorical data.
104 public List
<StateData
> getStates(){
108 protected void setStates(List
<StateData
> states
){
109 this.states
= states
;
113 * Adds a {@link State state} to the list of {@link #getStates() states}
114 * describing the {@link Feature feature} corresponding to <i>this</i> categorical data.
116 * @param state the state to be added to <i>this</i> categorical data
119 public void addState(StateData state
){
120 this.states
.add(state
);
123 * Removes one element from the set of {@link #getStates() states}
124 * describing the {@link Feature feature} corresponding to <i>this</i> categorical data.
126 * @param state the state which should be removed
128 * @see #addState(State)
130 public void removeState(StateData state
){
131 this.states
.remove(state
);
134 //rename to isStateSequenceIntentional ??
136 * Returns the boolean value of the flag indicating whether the sequence of
137 * {@link StateData state data} belonging to <i>this</i> categorical data is intentional
138 * (true) and therefore relevant for interpretation or analysis or not (false).
139 * The use of this flag depends mostly on the {@link Feature feature} of <i>this</i> categorical data.
141 * @return the boolean value of the orderRelevant flag
143 public boolean getOrderRelevant(){
144 return this.orderRelevant
;
147 * @see #getOrderRelevant()
149 public void setOrderRelevant(boolean orderRelevant
){
150 this.orderRelevant
= orderRelevant
;
154 //*********************************** CLONE *****************************************/
157 * Clones <i>this</i> categorical data. This is a shortcut that enables to create
158 * a new instance that differs only slightly from <i>this</i> categorical data by
159 * modifying only some of the attributes.
161 * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
162 * @see java.lang.Object#clone()
165 public Object
clone() {
168 CategoricalData result
= (CategoricalData
)super.clone();
171 result
.states
= new ArrayList
<StateData
>();
172 for (StateData stateData
: getStates()){
173 //TODO do we need to clone here?
174 StateData newState
= (StateData
)stateData
.clone();
175 result
.states
.add(newState
);
179 //no changes to: orderRelevant
180 } catch (CloneNotSupportedException e
) {
181 logger
.warn("Object does not implement cloneable");