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
;
13 import java
.util
.HashMap
;
14 import java
.util
.HashSet
;
18 import javax
.persistence
.Entity
;
19 import javax
.persistence
.FetchType
;
20 import javax
.persistence
.ManyToMany
;
21 import javax
.persistence
.ManyToOne
;
22 import javax
.persistence
.OneToMany
;
23 import javax
.validation
.constraints
.NotNull
;
24 import javax
.xml
.bind
.annotation
.XmlAccessType
;
25 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
26 import javax
.xml
.bind
.annotation
.XmlElement
;
27 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
28 import javax
.xml
.bind
.annotation
.XmlIDREF
;
29 import javax
.xml
.bind
.annotation
.XmlRootElement
;
30 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
31 import javax
.xml
.bind
.annotation
.XmlType
;
32 import javax
.xml
.bind
.annotation
.adapters
.XmlJavaTypeAdapter
;
34 import org
.apache
.log4j
.Logger
;
35 import org
.hibernate
.annotations
.Cascade
;
36 import org
.hibernate
.annotations
.CascadeType
;
37 import org
.hibernate
.envers
.Audited
;
39 import eu
.etaxonomy
.cdm
.jaxb
.MultilanguageTextAdapter
;
40 import eu
.etaxonomy
.cdm
.model
.common
.IMultiLanguageTextHolder
;
41 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
42 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
43 import eu
.etaxonomy
.cdm
.model
.common
.MultilanguageText
;
44 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
45 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
48 * This class represents the assignment of values ({@link State state terms}) to {@link Feature features}
49 * corresponding to {@link CategoricalData categorical data}. A state data instance
50 * constitutes an atomized part of an information piece (categorical data) so
51 * that several state data instances may belong to one categorical data
54 * This class corresponds to CharacterStateDataType according to the SDD schema.
58 * @created 08-Nov-2007 13:06:53
60 @XmlAccessorType(XmlAccessType
.FIELD
)
61 @XmlType(name
= "StateData", propOrder
= {
66 @XmlRootElement(name
= "StateData")
69 public class StateData
extends VersionableEntity
implements IModifiable
, IMultiLanguageTextHolder
, Cloneable
{
70 private static final long serialVersionUID
= -4380314126624505415L;
71 private static final Logger logger
= Logger
.getLogger(StateData
.class);
73 @XmlElement(name
= "State")
75 @XmlSchemaType(name
= "IDREF")
76 @ManyToOne(fetch
= FetchType
.LAZY
)
79 @XmlElementWrapper(name
= "Modifiers")
80 @XmlElement(name
= "Modifier")
81 @ManyToMany(fetch
= FetchType
.LAZY
)
82 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
})
83 // @NotNull // avoids creating a UNIQUE key for this field -> not needed for ManyToMany
84 private Set
<Modifier
> modifiers
= new HashSet
<Modifier
>();
86 @XmlElement(name
= "ModifyingText")
87 @XmlJavaTypeAdapter(MultilanguageTextAdapter
.class)
88 @OneToMany(fetch
= FetchType
.LAZY
)
89 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
})
90 private Map
<Language
,LanguageString
> modifyingText
= new HashMap
<Language
,LanguageString
>();
92 //********************* FACTORY METHODS ************************\
95 * Creates a new empty state data instance.
97 public static StateData
NewInstance(){
98 return new StateData();
103 * Creates a new empty state data instance.
105 public static StateData
NewInstance(State state
){
106 return new StateData();
110 * Creates a new empty state data instance.
112 public static StateData
NewInstance(String term
, String label
, String labelAbbrev
){
113 State state
= State
.NewInstance(term
, label
, labelAbbrev
);
114 return NewInstance(state
);
117 //*************************** CONSTRUCTOR ************************\
120 * Class constructor: creates a new empty state data instance.
126 //************************** GETTER /SETTER *************************\
129 * Returns the {@link State state term} used in <i>this</i> state data.
131 public State
getState(){
137 public void setState(State state
){
143 * Returns the set of {@link Modifier modifiers} used to qualify the validity
144 * of <i>this</i> state data. This is only metainformation.
146 public Set
<Modifier
> getModifiers(){
147 return this.modifiers
;
151 * Adds a {@link Modifier modifier} to the set of {@link #getModifiers() modifiers}
152 * used to qualify the validity of <i>this</i> state data.
154 * @param modifier the modifier to be added to <i>this</i> state data
155 * @see #getModifiers()
157 public void addModifier(Modifier modifier
){
158 this.modifiers
.add(modifier
);
161 * Removes one element from the set of {@link #getModifiers() modifiers}
162 * used to qualify the validity of <i>this</i> state data.
164 * @param modifier the modifier which should be removed
165 * @see #getModifiers()
166 * @see #addModifier(Modifier)
168 public void removeModifier(Modifier modifier
){
169 this.modifiers
.remove(modifier
);
174 * Returns the {@link MultilanguageText multilanguage text} used to qualify the validity
175 * of <i>this</i> state data. The different {@link LanguageString language strings}
176 * contained in the multilanguage text should all have the same meaning.<BR>
177 * A multilanguage text does not belong to a controlled {@link TermVocabulary term vocabulary}
178 * as a {@link Modifier modifier} does.
180 * NOTE: the actual content of <i>this</i> state data is NOT
181 * stored in the modifying text. This is only metainformation
182 * (like "Some experts express doubt about this assertion").
184 public Map
<Language
,LanguageString
> getModifyingText(){
185 return this.modifyingText
;
189 * Creates a {@link LanguageString language string} based on the given text string
190 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
191 * used to qualify the validity of <i>this</i> state data.
194 * @param text the string describing the validity
195 * in a particular language
196 * @param language the language in which the text string is formulated
198 * @see #getModifyingText()
199 * @see #putModifyingText(LanguageString)
200 * @deprecated should follow the put semantic of maps, this method will be removed in v4.0
201 * Use the {@link #putModifyingText(Language, String) putModifyingText} method instead
204 public LanguageString
addModifyingText(String text
, Language language
){
205 return this.putModifyingText(language
, text
);
209 * Creates a {@link LanguageString language string} based on the given text string
210 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
211 * used to qualify the validity of <i>this</i> state data.
213 * @param language the language in which the text string is formulated
214 * @param text the string describing the validity
215 * in a particular language
217 * @see #getModifyingText()
218 * @see #addModifyingText(LanguageString)
220 public LanguageString
putModifyingText(Language language
, String text
){
221 return this.modifyingText
.put(language
, LanguageString
.NewInstance(text
, language
));
224 * Adds a translated {@link LanguageString text in a particular language}
225 * to the {@link MultilanguageText multilanguage text} used to qualify the validity
226 * of <i>this</i> state data.
228 * @param text the language string describing the validity
229 * in a particular language
230 * @see #getModifyingText()
231 * @see #putModifyingText(Language, String)
232 * @deprecated should follow the put semantic of maps, this method will be removed in v4.0
233 * Use the {@link #putModifyingText(LanguagString) putModifyingText} method instead
236 public LanguageString
addModifyingText(LanguageString text
){
237 return this.putModifyingText(text
);
241 * Adds a translated {@link LanguageString text in a particular language}
242 * to the {@link MultilanguageText multilanguage text} used to qualify the validity
243 * of <i>this</i> state data.
245 * @param text the language string describing the validity
246 * in a particular language
247 * @see #getModifyingText()
248 * @see #putModifyingText(Language, String)
250 public LanguageString
putModifyingText(LanguageString text
){
251 return this.modifyingText
.put(text
.getLanguage(),text
);
254 * Removes from the {@link MultilanguageText multilanguage text} used to qualify the validity
255 * of <i>this</i> state data the one {@link LanguageString language string}
256 * with the given {@link Language language}.
258 * @param lang the language in which the language string to be removed
259 * has been formulated
260 * @see #getModifyingText()
262 public LanguageString
removeModifyingText(Language lang
){
263 return this.modifyingText
.remove(lang
);
266 //*********************************** CLONE *****************************************/
269 * Clones <i>this</i> state data. This is a shortcut that enables to create
270 * a new instance that differs only slightly from <i>this</i> state data by
271 * modifying only some of the attributes.
273 * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
274 * @see java.lang.Object#clone()
277 public Object
clone() {
280 StateData result
= (StateData
)super.clone();
283 result
.modifiers
= new HashSet
<Modifier
>();
284 for (Modifier modifier
: getModifiers()){
285 result
.modifiers
.add(modifier
);
289 result
.modifyingText
= new HashMap
<Language
, LanguageString
>();
290 for (Language language
: getModifyingText().keySet()){
291 //TODO clone needed? See also IndividualsAssociation
292 LanguageString newLanguageString
= (LanguageString
)getModifyingText().get(language
).clone();
293 result
.modifyingText
.put(language
, newLanguageString
);
297 //no changes to: state
298 } catch (CloneNotSupportedException e
) {
299 logger
.warn("Object does not implement cloneable");