-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.cdm.model.description;
-
-
-import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.common.LanguageString;
-import eu.etaxonomy.cdm.model.common.MultilanguageText;
-import eu.etaxonomy.cdm.model.common.TermVocabulary;
-import eu.etaxonomy.cdm.model.common.VersionableEntity;
-import org.apache.log4j.Logger;
-
-import java.util.*;
-
-import javax.persistence.*;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
-import javax.xml.bind.annotation.XmlIDREF;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlSchemaType;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- * This class represents the assignment of values ({@link State state terms}) to {@link Feature features}
- * corresponding to {@link CategoricalData categorical data}. A state data instance
- * constitutes an atomized part of an information piece (categorical data) so
- * that several state data instances may belong to one categorical data
- * instance.
- * <P>
- * This class corresponds to CharacterStateDataType according to the SDD schema.
- *
- * @author m.doering
- * @version 1.0
- * @created 08-Nov-2007 13:06:53
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "StateData", propOrder = {
- "state",
- "modifiers",
- "modifyingText"
-})
-@XmlRootElement(name = "StateData")
-@Entity
-//@Audited
-public class StateData extends VersionableEntity {
- private static final long serialVersionUID = -4380314126624505415L;
- @SuppressWarnings("unused")
- private static final Logger logger = Logger.getLogger(StateData.class);
-
- @XmlElement(name = "State")
- @XmlIDREF
- @XmlSchemaType(name = "IDREF")
- private State state;
-
- @XmlElementWrapper(name = "Modifiers")
- @XmlElement(name = "Modifier")
- private Set<Modifier> modifiers = new HashSet<Modifier>();
-
- @XmlElement(name = "ModifyingText")
- private MultilanguageText modifyingText;
-
- /**
- * Class constructor: creates a new empty state data instance.
- */
- public StateData() {
- super();
- }
-
- /**
- * Creates a new empty state data instance.
- */
- public static StateData NewInstance(){
- return new StateData();
- }
-
- /**
- * Returns the {@link State state term} used in <i>this</i> state data.
- */
- @ManyToOne(fetch = FetchType.LAZY)
- public State getState(){
- return this.state;
- }
- /**
- * @see #getState()
- */
- public void setState(State state){
- this.state = state;
- }
-
-
- /**
- * Returns the set of {@link Modifier modifiers} used to qualify the validity
- * of <i>this</i> state data. This is only metainformation.
- */
- @OneToMany(fetch = FetchType.LAZY)
- public Set<Modifier> getModifiers(){
- return this.modifiers;
- }
- /**
- * @see #getModifiers()
- */
- @SuppressWarnings("unused")
- private void setModifiers(Set<Modifier> modifiers) {
- this.modifiers = modifiers;
- }
- /**
- * Adds a {@link Modifier modifier} to the set of {@link #getModifiers() modifiers}
- * used to qualify the validity of <i>this</i> state data.
- *
- * @param modifier the modifier to be added to <i>this</i> state data
- * @see #getModifiers()
- */
- public void addModifier(Modifier modifier){
- this.modifiers.add(modifier);
- }
- /**
- * Removes one element from the set of {@link #getModifiers() modifiers}
- * used to qualify the validity of <i>this</i> state data.
- *
- * @param modifier the modifier which should be removed
- * @see #getModifiers()
- * @see #addModifier(Modifier)
- */
- public void removeModifier(Modifier modifier){
- this.modifiers.remove(modifier);
- }
-
-
- /**
- * Returns the {@link MultilanguageText multilanguage text} used to qualify the validity
- * of <i>this</i> state data. The different {@link LanguageString language strings}
- * contained in the multilanguage text should all have the same meaning.<BR>
- * A multilanguage text does not belong to a controlled {@link TermVocabulary term vocabulary}
- * as a {@link Modifier modifier} does.
- * <P>
- * NOTE: the actual content of <i>this</i> state data is NOT
- * stored in the modifying text. This is only metainformation
- * (like "Some experts express doubt about this assertion").
- */
- public MultilanguageText getModifyingText(){
- return this.modifyingText;
- }
- /**
- * @see #getModifyingText()
- */
- @SuppressWarnings("unused")
- private void setModifyingText(MultilanguageText modifyingText) {
- this.modifyingText = modifyingText;
- }
- /**
- * Creates a {@link LanguageString language string} based on the given text string
- * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
- * used to qualify the validity of <i>this</i> state data.
- *
- * @param text the string describing the validity
- * in a particular language
- * @param language the language in which the text string is formulated
- * @see #getModifyingText()
- * @see #addModifyingText(LanguageString)
- */
- public void addModifyingText(String text, Language language){
- this.modifyingText.put(language, LanguageString.NewInstance(text, language));
- }
- /**
- * Adds a translated {@link LanguageString text in a particular language}
- * to the {@link MultilanguageText multilanguage text} used to qualify the validity
- * of <i>this</i> state data.
- *
- * @param text the language string describing the validity
- * in a particular language
- * @see #getModifyingText()
- * @see #addModifyingText(String, Language)
- */
- public void addModifyingText(LanguageString text){
- this.modifyingText.add(text);
- }
- /**
- * Removes from the {@link MultilanguageText multilanguage text} used to qualify the validity
- * of <i>this</i> state data the one {@link LanguageString language string}
- * with the given {@link Language language}.
- *
- * @param lang the language in which the language string to be removed
- * has been formulated
- * @see #getModifyingText()
- */
- public void removeModifyingText(Language lang){
- this.modifyingText.remove(lang);
- }
-
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy \r
+* http://www.e-taxonomy.eu\r
+* \r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.cdm.model.description;\r
+\r
+\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import javax.persistence.Entity;\r
+import javax.persistence.FetchType;\r
+import javax.persistence.ManyToMany;\r
+import javax.persistence.ManyToOne;\r
+import javax.persistence.OneToMany;\r
+import javax.validation.constraints.NotNull;\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlElementWrapper;\r
+import javax.xml.bind.annotation.XmlIDREF;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlSchemaType;\r
+import javax.xml.bind.annotation.XmlType;\r
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.hibernate.annotations.Cascade;\r
+import org.hibernate.annotations.CascadeType;\r
+import org.hibernate.envers.Audited;\r
+\r
+import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;\r
+import eu.etaxonomy.cdm.model.common.IMultiLanguageTextHolder;\r
+import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.common.LanguageString;\r
+import eu.etaxonomy.cdm.model.common.MultilanguageText;\r
+import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
+import eu.etaxonomy.cdm.model.common.VersionableEntity;\r
+\r
+/**\r
+ * This class represents the assignment of values ({@link State state terms}) to {@link Feature features}\r
+ * corresponding to {@link CategoricalData categorical data}. A state data instance\r
+ * constitutes an atomized part of an information piece (categorical data) so\r
+ * that several state data instances may belong to one categorical data\r
+ * instance.\r
+ * <P>\r
+ * This class corresponds to CharacterStateDataType according to the SDD schema.\r
+ * \r
+ * @author m.doering\r
+ * @version 1.0\r
+ * @created 08-Nov-2007 13:06:53\r
+ */\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "StateData", propOrder = {\r
+ "state",\r
+ "modifiers",\r
+ "modifyingText"\r
+})\r
+@XmlRootElement(name = "StateData")\r
+@Entity\r
+@Audited\r
+public class StateData extends VersionableEntity implements IModifiable, IMultiLanguageTextHolder, Cloneable{\r
+ private static final long serialVersionUID = -4380314126624505415L;\r
+ private static final Logger logger = Logger.getLogger(StateData.class);\r
+ \r
+ @XmlElement(name = "State")\r
+ @XmlIDREF\r
+ @XmlSchemaType(name = "IDREF")\r
+ @ManyToOne(fetch = FetchType.LAZY)\r
+ private State state;\r
+ \r
+ @XmlElementWrapper(name = "Modifiers")\r
+ @XmlElement(name = "Modifier")\r
+ @ManyToMany(fetch = FetchType.LAZY)\r
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})\r
+// @NotNull // avoids creating a UNIQUE key for this field -> not needed for ManyToMany\r
+ private Set<Modifier> modifiers = new HashSet<Modifier>();\r
+ \r
+ @XmlElement(name = "ModifyingText")\r
+ @XmlJavaTypeAdapter(MultilanguageTextAdapter.class)\r
+ @OneToMany(fetch = FetchType.LAZY)\r
+ private Map<Language,LanguageString> modifyingText = new HashMap<Language,LanguageString>();\r
+ \r
+ /** \r
+ * Class constructor: creates a new empty state data instance.\r
+ */\r
+ public StateData() {\r
+ super();\r
+ }\r
+ \r
+ /** \r
+ * Creates a new empty state data instance.\r
+ */\r
+ public static StateData NewInstance(){\r
+ return new StateData();\r
+ }\r
+\r
+ /** \r
+ * Returns the {@link State state term} used in <i>this</i> state data.\r
+ */\r
+ public State getState(){\r
+ return this.state;\r
+ }\r
+ /** \r
+ * @see #getState()\r
+ */\r
+ public void setState(State state){\r
+ this.state = state;\r
+ }\r
+ \r
+\r
+ /** \r
+ * Returns the set of {@link Modifier modifiers} used to qualify the validity\r
+ * of <i>this</i> state data. This is only metainformation.\r
+ */\r
+ public Set<Modifier> getModifiers(){\r
+ return this.modifiers;\r
+ }\r
+ \r
+ /**\r
+ * Adds a {@link Modifier modifier} to the set of {@link #getModifiers() modifiers}\r
+ * used to qualify the validity of <i>this</i> state data.\r
+ * \r
+ * @param modifier the modifier to be added to <i>this</i> state data\r
+ * @see #getModifiers()\r
+ */\r
+ public void addModifier(Modifier modifier){\r
+ this.modifiers.add(modifier);\r
+ }\r
+ /** \r
+ * Removes one element from the set of {@link #getModifiers() modifiers}\r
+ * used to qualify the validity of <i>this</i> state data.\r
+ *\r
+ * @param modifier the modifier which should be removed\r
+ * @see #getModifiers()\r
+ * @see #addModifier(Modifier)\r
+ */\r
+ public void removeModifier(Modifier modifier){\r
+ this.modifiers.remove(modifier);\r
+ }\r
+\r
+\r
+ /** \r
+ * Returns the {@link MultilanguageText multilanguage text} used to qualify the validity\r
+ * of <i>this</i> state data. The different {@link LanguageString language strings}\r
+ * contained in the multilanguage text should all have the same meaning.<BR>\r
+ * A multilanguage text does not belong to a controlled {@link TermVocabulary term vocabulary}\r
+ * as a {@link Modifier modifier} does.\r
+ * <P>\r
+ * NOTE: the actual content of <i>this</i> state data is NOT\r
+ * stored in the modifying text. This is only metainformation\r
+ * (like "Some experts express doubt about this assertion").\r
+ */\r
+ public Map<Language,LanguageString> getModifyingText(){\r
+ return this.modifyingText;\r
+ }\r
+\r
+ /**\r
+ * Creates a {@link LanguageString language string} based on the given text string\r
+ * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text} \r
+ * used to qualify the validity of <i>this</i> state data.\r
+ * \r
+ * @param text the string describing the validity\r
+ * in a particular language\r
+ * @param language the language in which the text string is formulated\r
+ * @see #getModifyingText()\r
+ * @see #addModifyingText(LanguageString)\r
+ */\r
+ public LanguageString addModifyingText(String text, Language language){\r
+ return this.modifyingText.put(language, LanguageString.NewInstance(text, language));\r
+ }\r
+ /**\r
+ * Adds a translated {@link LanguageString text in a particular language}\r
+ * to the {@link MultilanguageText multilanguage text} used to qualify the validity\r
+ * of <i>this</i> state data.\r
+ * \r
+ * @param text the language string describing the validity\r
+ * in a particular language\r
+ * @see #getModifyingText()\r
+ * @see #addModifyingText(String, Language)\r
+ */\r
+ public LanguageString addModifyingText(LanguageString text){\r
+ return this.modifyingText.put(text.getLanguage(),text);\r
+ }\r
+ /** \r
+ * Removes from the {@link MultilanguageText multilanguage text} used to qualify the validity\r
+ * of <i>this</i> state data the one {@link LanguageString language string}\r
+ * with the given {@link Language language}.\r
+ *\r
+ * @param lang the language in which the language string to be removed\r
+ * has been formulated\r
+ * @see #getModifyingText()\r
+ */\r
+ public LanguageString removeModifyingText(Language lang){\r
+ return this.modifyingText.remove(lang);\r
+ }\r
+\r
+//*********************************** CLONE *****************************************/\r
+\r
+ /** \r
+ * Clones <i>this</i> state data. This is a shortcut that enables to create\r
+ * a new instance that differs only slightly from <i>this</i> state data by\r
+ * modifying only some of the attributes.\r
+ * \r
+ * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()\r
+ * @see java.lang.Object#clone()\r
+ */\r
+ @Override\r
+ public Object clone() {\r
+\r
+ try {\r
+ StateData result = (StateData)super.clone();\r
+ \r
+ //modifiers\r
+ result.modifiers = new HashSet<Modifier>();\r
+ for (Modifier modifier : getModifiers()){\r
+ result.modifiers.add(modifier);\r
+ }\r
+ \r
+ //modifying text\r
+ result.modifyingText = new HashMap<Language, LanguageString>();\r
+ for (Language language : getModifyingText().keySet()){\r
+ //TODO clone needed? See also IndividualsAssociation\r
+ LanguageString newLanguageString = (LanguageString)getModifyingText().get(language).clone();\r
+ result.modifyingText.put(language, newLanguageString);\r
+ }\r
+ \r
+ return result;\r
+ //no changes to: state\r
+ } catch (CloneNotSupportedException e) {\r
+ logger.warn("Object does not implement cloneable");\r
+ e.printStackTrace();\r
+ return null;\r
+ }\r
+ }\r
}
\ No newline at end of file