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
;
17 import javax
.persistence
.Entity
;
18 import javax
.persistence
.FetchType
;
19 import javax
.persistence
.JoinTable
;
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
.XmlIDREF
;
26 import javax
.xml
.bind
.annotation
.XmlRootElement
;
27 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
28 import javax
.xml
.bind
.annotation
.XmlType
;
29 import javax
.xml
.bind
.annotation
.adapters
.XmlJavaTypeAdapter
;
31 import org
.apache
.log4j
.Logger
;
32 import org
.hibernate
.annotations
.Cascade
;
33 import org
.hibernate
.annotations
.CascadeType
;
34 import org
.hibernate
.envers
.Audited
;
35 import org
.hibernate
.search
.annotations
.Indexed
;
37 import eu
.etaxonomy
.cdm
.jaxb
.MultilanguageTextAdapter
;
38 import eu
.etaxonomy
.cdm
.model
.common
.IMultiLanguageTextHolder
;
39 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
40 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
41 import eu
.etaxonomy
.cdm
.model
.common
.MultilanguageText
;
42 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
46 * This class represents interactions between the described {@link Taxon taxon}
47 * and a second one (for instance a parasite, a prey or a hybrid parent).
48 * Only {@link TaxonDescription taxon descriptions} may contain taxon interactions.
49 * The interaction itself is described by a {@link MultilanguageText multilanguage text}.
51 * This class corresponds to: <ul>
52 * <li> NaturalLanguageDescriptionType (partially) according to the SDD schema
53 * <li> Associations according to the TDWG ontology
58 * @created 08-Nov-2007 13:06:57
60 @XmlAccessorType(XmlAccessType
.FIELD
)
61 @XmlType(name
= "TaxonInteraction", propOrder
= {
65 @XmlRootElement(name
= "TaxonInteraction")
68 @Indexed(index
= "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
69 public class TaxonInteraction
extends DescriptionElementBase
implements IMultiLanguageTextHolder
, Cloneable
{
70 private static final long serialVersionUID
= -5014025677925668627L;
71 private static final Logger logger
= Logger
.getLogger(TaxonInteraction
.class);
73 @XmlElement(name
= "Description")
74 @XmlJavaTypeAdapter(MultilanguageTextAdapter
.class)
75 @OneToMany(fetch
= FetchType
.LAZY
)
76 @JoinTable(name
= "TaxonInteraction_LanguageString")
77 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
, CascadeType
.DELETE
, CascadeType
.DELETE_ORPHAN
})
78 private Map
<Language
,LanguageString
> description
= new HashMap
<Language
,LanguageString
>();
80 @XmlElement(name
= "Taxon2")
82 @XmlSchemaType(name
= "IDREF")
83 @ManyToOne(fetch
= FetchType
.LAZY
)
84 @Cascade(CascadeType
.SAVE_UPDATE
)
88 * Class constructor: creates a new empty taxon interaction instance.
90 public TaxonInteraction() {
95 * Creates a new empty taxon interaction instance.
97 public static TaxonInteraction
NewInstance(){
98 return new TaxonInteraction();
102 * Creates a new empty taxon interaction instance and also sets the feature
107 public static TaxonInteraction
NewInstance(Feature feature
){
108 TaxonInteraction taxonInteraction
= new TaxonInteraction();
109 if(feature
.isSupportsTaxonInteraction()){
110 taxonInteraction
.setFeature(feature
);
112 return taxonInteraction
;
117 * Returns the second {@link Taxon taxon} involved in <i>this</i> taxon interaction.
118 * The first taxon is the taxon described in the corresponding
119 * {@link TaxonDescription taxon description}.
121 public Taxon
getTaxon2(){
127 public void setTaxon2(Taxon taxon2
){
128 this.taxon2
= taxon2
;
132 * Returns the {@link MultilanguageText multilanguage text} used to describe
133 * <i>this</i> taxon interaction. The different {@link LanguageString language strings}
134 * contained in the multilanguage text should all have the same meaning.
136 public Map
<Language
,LanguageString
> getDescriptions(){
137 return this.description
;
141 * Returns the description string in the given {@link Language language}
143 * @param language the language in which the description string looked for is formulated
144 * @see #getDescriptions()
146 public String
getDescription(Language language
){
147 LanguageString languageString
= description
.get(language
);
148 if (languageString
== null){
151 return languageString
.getText();
156 * Adds a translated {@link LanguageString text in a particular language}
157 * to the {@link MultilanguageText multilanguage text} used to describe
158 * <i>this</i> taxon interaction.
160 * @param description the language string describing the taxon interaction
161 * in a particular language
162 * @see #getDescription()
163 * @see #putDescription(String, Language)
164 * @deprecated should follow the put semantic of maps, this method will be removed in v4.0
165 * Use the {@link #putDescription(LanguageString) putDescription} method instead
168 public void addDescription(LanguageString description
){
169 this.putDescription(description
);
173 * Adds a translated {@link LanguageString text in a particular language}
174 * to the {@link MultilanguageText multilanguage text} used to describe
175 * <i>this</i> taxon interaction.
177 * @param description the language string describing the taxon interaction
178 * in a particular language
179 * @see #getDescription()
180 * @see #putDescription(String, Language)
182 public void putDescription(LanguageString description
){
183 this.description
.put(description
.getLanguage(),description
);
186 * Creates a {@link LanguageString language string} based on the given text string
187 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
188 * used to describe <i>this</i> taxon interaction.
190 * @param text the string describing the taxon interaction
191 * in a particular language
192 * @param language the language in which the text string is formulated
193 * @see #getDescription()
194 * @see #putDescription(LanguageString)
196 public void putDescription(Language language
, String text
){
197 this.description
.put(language
, LanguageString
.NewInstance(text
, language
));
201 * Creates a {@link LanguageString language string} based on the given text string
202 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
203 * used to describe <i>this</i> taxon interaction.
205 * @param text the string describing the taxon interaction
206 * in a particular language
207 * @param language the language in which the text string is formulated
208 * @see #getDescription()
209 * @see #addDescription(LanguageString)
210 * @deprecated should follow the put semantic of maps, this method will be removed in v4.0
211 * Use the {@link #putDescription(Language, String) putDescription} method instead
214 public void addDescription(String text
, Language language
){
215 this.putDescription(language
, text
);
218 * Removes from the {@link MultilanguageText multilanguage text} used to describe
219 * <i>this</i> taxon interaction the one {@link LanguageString language string}
220 * with the given {@link Language language}.
222 * @param lang the language in which the language string to be removed
223 * has been formulated
224 * @see #getDescription()
226 public void removeDescription(Language lang
){
227 this.description
.remove(lang
);
231 //*********************************** CLONE *****************************************/
234 * Clones <i>this</i> taxon interaction. This is a shortcut that enables to create
235 * a new instance that differs only slightly from <i>this</i> taxon interaction by
236 * modifying only some of the attributes.
238 * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
239 * @see java.lang.Object#clone()
242 public Object
clone() {
245 TaxonInteraction result
= (TaxonInteraction
)super.clone();
248 result
.description
= new HashMap
<Language
, LanguageString
>();
249 for (Language language
: getDescriptions().keySet()){
250 //TODO clone needed? See also IndividualsAssociation
251 LanguageString newLanguageString
= (LanguageString
)getDescriptions().get(language
).clone();
252 result
.description
.put(language
, newLanguageString
);
257 //no changes to: taxon2
258 } catch (CloneNotSupportedException e
) {
259 logger
.warn("Object does not implement cloneable");