Committing large number of changes relating to versioning implementation (#108)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / StateData.java
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
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.Map;
16 import java.util.Set;
17
18 import javax.persistence.Entity;
19 import javax.persistence.FetchType;
20 import javax.persistence.ManyToOne;
21 import javax.persistence.OneToMany;
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlElementWrapper;
26 import javax.xml.bind.annotation.XmlIDREF;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import javax.xml.bind.annotation.XmlSchemaType;
29 import javax.xml.bind.annotation.XmlType;
30 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
31
32 import org.apache.log4j.Logger;
33 import org.hibernate.envers.Audited;
34
35 import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
36 import eu.etaxonomy.cdm.model.common.Language;
37 import eu.etaxonomy.cdm.model.common.LanguageString;
38 import eu.etaxonomy.cdm.model.common.MultilanguageText;
39 import eu.etaxonomy.cdm.model.common.TermVocabulary;
40 import eu.etaxonomy.cdm.model.common.VersionableEntity;
41
42 /**
43 * This class represents the assignment of values ({@link State state terms}) to {@link Feature features}
44 * corresponding to {@link CategoricalData categorical data}. A state data instance
45 * constitutes an atomized part of an information piece (categorical data) so
46 * that several state data instances may belong to one categorical data
47 * instance.
48 * <P>
49 * This class corresponds to CharacterStateDataType according to the SDD schema.
50 *
51 * @author m.doering
52 * @version 1.0
53 * @created 08-Nov-2007 13:06:53
54 */
55 @XmlAccessorType(XmlAccessType.FIELD)
56 @XmlType(name = "StateData", propOrder = {
57 "state",
58 "modifiers",
59 "modifyingText"
60 })
61 @XmlRootElement(name = "StateData")
62 @Entity
63 @Audited
64 public class StateData extends VersionableEntity {
65 private static final long serialVersionUID = -4380314126624505415L;
66 @SuppressWarnings("unused")
67 private static final Logger logger = Logger.getLogger(StateData.class);
68
69 @XmlElement(name = "State")
70 @XmlIDREF
71 @XmlSchemaType(name = "IDREF")
72 @ManyToOne(fetch = FetchType.LAZY)
73 private State state;
74
75 @XmlElementWrapper(name = "Modifiers")
76 @XmlElement(name = "Modifier")
77 @OneToMany(fetch = FetchType.LAZY)
78 private Set<Modifier> modifiers = new HashSet<Modifier>();
79
80 @XmlElement(name = "ModifyingText")
81 @XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
82 @OneToMany(fetch = FetchType.LAZY)
83 private Map<Language,LanguageString> modifyingText = new HashMap<Language,LanguageString>();
84
85 /**
86 * Class constructor: creates a new empty state data instance.
87 */
88 public StateData() {
89 super();
90 }
91
92 /**
93 * Creates a new empty state data instance.
94 */
95 public static StateData NewInstance(){
96 return new StateData();
97 }
98
99 /**
100 * Returns the {@link State state term} used in <i>this</i> state data.
101 */
102 public State getState(){
103 return this.state;
104 }
105 /**
106 * @see #getState()
107 */
108 public void setState(State state){
109 this.state = state;
110 }
111
112
113 /**
114 * Returns the set of {@link Modifier modifiers} used to qualify the validity
115 * of <i>this</i> state data. This is only metainformation.
116 */
117 public Set<Modifier> getModifiers(){
118 return this.modifiers;
119 }
120
121 /**
122 * Adds a {@link Modifier modifier} to the set of {@link #getModifiers() modifiers}
123 * used to qualify the validity of <i>this</i> state data.
124 *
125 * @param modifier the modifier to be added to <i>this</i> state data
126 * @see #getModifiers()
127 */
128 public void addModifier(Modifier modifier){
129 this.modifiers.add(modifier);
130 }
131 /**
132 * Removes one element from the set of {@link #getModifiers() modifiers}
133 * used to qualify the validity of <i>this</i> state data.
134 *
135 * @param modifier the modifier which should be removed
136 * @see #getModifiers()
137 * @see #addModifier(Modifier)
138 */
139 public void removeModifier(Modifier modifier){
140 this.modifiers.remove(modifier);
141 }
142
143
144 /**
145 * Returns the {@link MultilanguageText multilanguage text} used to qualify the validity
146 * of <i>this</i> state data. The different {@link LanguageString language strings}
147 * contained in the multilanguage text should all have the same meaning.<BR>
148 * A multilanguage text does not belong to a controlled {@link TermVocabulary term vocabulary}
149 * as a {@link Modifier modifier} does.
150 * <P>
151 * NOTE: the actual content of <i>this</i> state data is NOT
152 * stored in the modifying text. This is only metainformation
153 * (like "Some experts express doubt about this assertion").
154 */
155 public Map<Language,LanguageString> getModifyingText(){
156 return this.modifyingText;
157 }
158
159 /**
160 * Creates a {@link LanguageString language string} based on the given text string
161 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
162 * used to qualify the validity of <i>this</i> state data.
163 *
164 * @param text the string describing the validity
165 * in a particular language
166 * @param language the language in which the text string is formulated
167 * @see #getModifyingText()
168 * @see #addModifyingText(LanguageString)
169 */
170 public void addModifyingText(String text, Language language){
171 this.modifyingText.put(language, LanguageString.NewInstance(text, language));
172 }
173 /**
174 * Adds a translated {@link LanguageString text in a particular language}
175 * to the {@link MultilanguageText multilanguage text} used to qualify the validity
176 * of <i>this</i> state data.
177 *
178 * @param text the language string describing the validity
179 * in a particular language
180 * @see #getModifyingText()
181 * @see #addModifyingText(String, Language)
182 */
183 public void addModifyingText(LanguageString text){
184 this.modifyingText.put(text.getLanguage(),text);
185 }
186 /**
187 * Removes from the {@link MultilanguageText multilanguage text} used to qualify the validity
188 * of <i>this</i> state data the one {@link LanguageString language string}
189 * with the given {@link Language language}.
190 *
191 * @param lang the language in which the language string to be removed
192 * has been formulated
193 * @see #getModifyingText()
194 */
195 public void removeModifyingText(Language lang){
196 this.modifyingText.remove(lang);
197 }
198
199 }