X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/blobdiff_plain/a50e271f1102a81962cc0a7518cb4adad25c9e56..21f190add24e50ba7619eb87b145d3b3f3182548:/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/StateData.java
diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/StateData.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/StateData.java
index 9004e9e114..e127170d05 100644
--- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/StateData.java
+++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/StateData.java
@@ -1,8 +1,8 @@
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
@@ -35,7 +35,12 @@ import org.apache.log4j.Logger;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.envers.Audited;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.FieldBridge;
+import org.hibernate.search.annotations.IndexedEmbedded;
+import eu.etaxonomy.cdm.hibernate.search.DefinedTermBaseClassBridge;
+import eu.etaxonomy.cdm.hibernate.search.MultilanguageTextFieldBridge;
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
import eu.etaxonomy.cdm.model.common.IMultiLanguageTextHolder;
import eu.etaxonomy.cdm.model.common.Language;
@@ -52,7 +57,7 @@ import eu.etaxonomy.cdm.model.common.VersionableEntity;
* instance.
*
* This class corresponds to CharacterStateDataType according to the SDD schema.
- *
+ *
* @author m.doering
* @version 1.0
* @created 08-Nov-2007 13:06:53
@@ -67,238 +72,239 @@ import eu.etaxonomy.cdm.model.common.VersionableEntity;
@Entity
@Audited
public class StateData extends VersionableEntity implements IModifiable, IMultiLanguageTextHolder, Cloneable{
- private static final long serialVersionUID = -4380314126624505415L;
- private static final Logger logger = Logger.getLogger(StateData.class);
-
- @XmlElement(name = "State")
+ private static final long serialVersionUID = -4380314126624505415L;
+ private static final Logger logger = Logger.getLogger(StateData.class);
+
+ @XmlElement(name = "State")
@XmlIDREF
@XmlSchemaType(name = "IDREF")
@ManyToOne(fetch = FetchType.LAZY)
- private State state;
-
- @XmlElementWrapper(name = "Modifiers")
- @XmlElement(name = "Modifier")
- @ManyToMany(fetch = FetchType.LAZY)
- @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
+ @IndexedEmbedded
+ private State state;
+
+ @XmlElementWrapper(name = "Modifiers")
+ @XmlElement(name = "Modifier")
+ @ManyToMany(fetch = FetchType.LAZY)
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
+ @IndexedEmbedded
// @NotNull // avoids creating a UNIQUE key for this field -> not needed for ManyToMany
- private Set modifiers = new HashSet();
-
- @XmlElement(name = "ModifyingText")
- @XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
- @OneToMany(fetch = FetchType.LAZY)
- @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
- private Map modifyingText = new HashMap();
+ private Set modifiers = new HashSet();
+
+ @XmlElement(name = "ModifyingText")
+ @XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
+ @OneToMany(fetch = FetchType.LAZY)
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
+ @Field(name="modifyingText")
+ @FieldBridge(impl=MultilanguageTextFieldBridge.class)
+ private Map modifyingText = new HashMap();
//********************* FACTORY METHODS ************************\
-
- /**
- * Creates a new empty state data instance.
- */
- public static StateData NewInstance(){
- return new StateData();
- }
-
-
- /**
- * Creates a new empty state data instance.
- */
- public static StateData NewInstance(State state){
- return new StateData();
- }
-
- /**
- * Creates a new empty state data instance.
- */
- public static StateData NewInstance(String term, String label, String labelAbbrev){
- State state = State.NewInstance(term, label, labelAbbrev);
- return NewInstance(state);
- }
-
-//*************************** CONSTRUCTOR ************************\
-
- /**
- * 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();
+ }
+
+
+ /**
+ * Creates a new empty state data instance.
+ *
+ * NOTE: {@link State} is a sub class of {@link DefinedTermBase}.
+ * If the state passed as parameter has been created newly it has to be persisted before it is possible to save the StateData.
+ */
+ public static StateData NewInstance(State state){
+ StateData stateData = new StateData();
+ stateData.setState(state);
+ return stateData;
+ }
+
+//*************************** CONSTRUCTOR ************************\
+
+ /**
+ * Class constructor: creates a new empty state data instance.
+ */
+ public StateData() {
+ super();
+ }
//************************** GETTER /SETTER *************************\
-
- /**
- * Returns the {@link State state term} used in this state data.
- */
- 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 this state data. This is only metainformation.
- */
- public Set getModifiers(){
- return this.modifiers;
- }
-
- /**
- * Adds a {@link Modifier modifier} to the set of {@link #getModifiers() modifiers}
- * used to qualify the validity of this state data.
- *
- * @param modifier the modifier to be added to this 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 this 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 this state data. The different {@link LanguageString language strings}
- * contained in the multilanguage text should all have the same meaning.
- * A multilanguage text does not belong to a controlled {@link TermVocabulary term vocabulary}
- * as a {@link Modifier modifier} does.
- *
- * NOTE: the actual content of this state data is NOT
- * stored in the modifying text. This is only metainformation
- * (like "Some experts express doubt about this assertion").
- */
- public Map getModifyingText(){
- return this.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 this 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 #putModifyingText(LanguageString)
- * @deprecated should follow the put semantic of maps, this method will be removed in v4.0
- * Use the {@link #putModifyingText(Language, String) putModifyingText} method instead
- */
- @Deprecated
- public LanguageString addModifyingText(String text, Language language){
- return this.putModifyingText(language, text);
- }
-
- /**
- * 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 this state data.
- *
- * @param language the language in which the text string is formulated
- * @param text the string describing the validity
- * in a particular language
- *
- * @see #getModifyingText()
- * @see #addModifyingText(LanguageString)
- */
- public LanguageString putModifyingText(Language language, String text){
- return 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 this state data.
- *
- * @param text the language string describing the validity
- * in a particular language
- * @see #getModifyingText()
- * @see #putModifyingText(Language, String)
- * @deprecated should follow the put semantic of maps, this method will be removed in v4.0
- * Use the {@link #putModifyingText(LanguagString) putModifyingText} method instead
- */
- @Deprecated
- public LanguageString addModifyingText(LanguageString text){
- return this.putModifyingText(text);
- }
-
- /**
- * Adds a translated {@link LanguageString text in a particular language}
- * to the {@link MultilanguageText multilanguage text} used to qualify the validity
- * of this state data.
- *
- * @param text the language string describing the validity
- * in a particular language
- * @see #getModifyingText()
- * @see #putModifyingText(Language, String)
- */
- public LanguageString putModifyingText(LanguageString text){
- return this.modifyingText.put(text.getLanguage(),text);
- }
- /**
- * Removes from the {@link MultilanguageText multilanguage text} used to qualify the validity
- * of this 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 LanguageString removeModifyingText(Language lang){
- return this.modifyingText.remove(lang);
- }
+
+ /**
+ * Returns the {@link State state term} used in this state data.
+ */
+ 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 this state data. This is only metainformation.
+ */
+ public Set getModifiers(){
+ return this.modifiers;
+ }
+
+ /**
+ * Adds a {@link Modifier modifier} to the set of {@link #getModifiers() modifiers}
+ * used to qualify the validity of this state data.
+ *
+ * @param modifier the modifier to be added to this 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 this 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 this state data. The different {@link LanguageString language strings}
+ * contained in the multilanguage text should all have the same meaning.
+ * A multilanguage text does not belong to a controlled {@link TermVocabulary term vocabulary}
+ * as a {@link Modifier modifier} does.
+ *
+ * NOTE: the actual content of this state data is NOT
+ * stored in the modifying text. This is only metainformation
+ * (like "Some experts express doubt about this assertion").
+ */
+ public Map getModifyingText(){
+ return this.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 this 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 #putModifyingText(LanguageString)
+ * @deprecated should follow the put semantic of maps, this method will be removed in v4.0
+ * Use the {@link #putModifyingText(Language, String) putModifyingText} method instead
+ */
+ @Deprecated
+ public LanguageString addModifyingText(String text, Language language){
+ return this.putModifyingText(language, text);
+ }
+
+ /**
+ * 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 this state data.
+ *
+ * @param language the language in which the text string is formulated
+ * @param text the string describing the validity
+ * in a particular language
+ *
+ * @see #getModifyingText()
+ * @see #addModifyingText(LanguageString)
+ */
+ public LanguageString putModifyingText(Language language, String text){
+ return 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 this state data.
+ *
+ * @param text the language string describing the validity
+ * in a particular language
+ * @see #getModifyingText()
+ * @see #putModifyingText(Language, String)
+ * @deprecated should follow the put semantic of maps, this method will be removed in v4.0
+ * Use the {@link #putModifyingText(LanguagString) putModifyingText} method instead
+ */
+ @Deprecated
+ public LanguageString addModifyingText(LanguageString text){
+ return this.putModifyingText(text);
+ }
+
+ /**
+ * Adds a translated {@link LanguageString text in a particular language}
+ * to the {@link MultilanguageText multilanguage text} used to qualify the validity
+ * of this state data.
+ *
+ * @param text the language string describing the validity
+ * in a particular language
+ * @see #getModifyingText()
+ * @see #putModifyingText(Language, String)
+ */
+ public LanguageString putModifyingText(LanguageString text){
+ return this.modifyingText.put(text.getLanguage(),text);
+ }
+ /**
+ * Removes from the {@link MultilanguageText multilanguage text} used to qualify the validity
+ * of this 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 LanguageString removeModifyingText(Language lang){
+ return this.modifyingText.remove(lang);
+ }
//*********************************** CLONE *****************************************/
- /**
- * Clones this state data. This is a shortcut that enables to create
- * a new instance that differs only slightly from this state data by
- * modifying only some of the attributes.
- *
- * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
- * @see java.lang.Object#clone()
- */
- @Override
- public Object clone() {
-
- try {
- StateData result = (StateData)super.clone();
-
- //modifiers
- result.modifiers = new HashSet();
- for (Modifier modifier : getModifiers()){
- result.modifiers.add(modifier);
- }
-
- //modifying text
- result.modifyingText = new HashMap();
- for (Language language : getModifyingText().keySet()){
- //TODO clone needed? See also IndividualsAssociation
- LanguageString newLanguageString = (LanguageString)getModifyingText().get(language).clone();
- result.modifyingText.put(language, newLanguageString);
- }
-
- return result;
- //no changes to: state
- } catch (CloneNotSupportedException e) {
- logger.warn("Object does not implement cloneable");
- e.printStackTrace();
- return null;
- }
- }
+ /**
+ * Clones this state data. This is a shortcut that enables to create
+ * a new instance that differs only slightly from this state data by
+ * modifying only some of the attributes.
+ *
+ * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() {
+
+ try {
+ StateData result = (StateData)super.clone();
+
+ //modifiers
+ result.modifiers = new HashSet();
+ for (Modifier modifier : getModifiers()){
+ result.modifiers.add(modifier);
+ }
+
+ //modifying text
+ result.modifyingText = new HashMap();
+ for (Language language : getModifyingText().keySet()){
+ //TODO clone needed? See also IndividualsAssociation
+ LanguageString newLanguageString = (LanguageString)getModifyingText().get(language).clone();
+ result.modifyingText.put(language, newLanguageString);
+ }
+
+ return result;
+ //no changes to: state
+ } catch (CloneNotSupportedException e) {
+ logger.warn("Object does not implement cloneable");
+ e.printStackTrace();
+ return null;
+ }
+ }
}
\ No newline at end of file