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
;
16 import javax
.persistence
.Entity
;
17 import javax
.persistence
.FetchType
;
18 import javax
.persistence
.JoinTable
;
19 import javax
.persistence
.ManyToOne
;
20 import javax
.persistence
.MapKeyJoinColumn
;
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
57 * @since 08-Nov-2007 13:06:57
59 @XmlAccessorType(XmlAccessType
.FIELD
)
60 @XmlType(name
= "TaxonInteraction", propOrder
= {
64 @XmlRootElement(name
= "TaxonInteraction")
67 @Indexed(index
= "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
68 public class TaxonInteraction
extends DescriptionElementBase
implements IMultiLanguageTextHolder
, Cloneable
{
69 private static final long serialVersionUID
= -5014025677925668627L;
70 private static final Logger logger
= Logger
.getLogger(TaxonInteraction
.class);
72 @XmlElement(name
= "Description")
73 @XmlJavaTypeAdapter(MultilanguageTextAdapter
.class)
74 @OneToMany(fetch
= FetchType
.LAZY
, orphanRemoval
=true)
75 @MapKeyJoinColumn(name
="description_mapkey_id")
76 @JoinTable(name
= "TaxonInteraction_LanguageString") //to distinguish from other DescriptionElementBase_LanguageString
77 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
, CascadeType
.DELETE
})
78 private Map
<Language
,LanguageString
> description
= new HashMap
<>();
80 @XmlElement(name
= "Taxon2")
82 @XmlSchemaType(name
= "IDREF")
83 @ManyToOne(fetch
= FetchType
.LAZY
)
84 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
})
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
> getDescription(){
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)
165 public void putDescription(LanguageString description
){
166 this.description
.put(description
.getLanguage(),description
);
169 * Creates a {@link LanguageString language string} based on the given text string
170 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
171 * used to describe <i>this</i> taxon interaction.
173 * @param text the string describing the taxon interaction
174 * in a particular language
175 * @param language the language in which the text string is formulated
176 * @see #getDescription()
177 * @see #putDescription(LanguageString)
179 public void putDescription(Language language
, String text
){
180 this.description
.put(language
, LanguageString
.NewInstance(text
, language
));
184 * Removes from the {@link MultilanguageText multilanguage text} used to describe
185 * <i>this</i> taxon interaction the one {@link LanguageString language string}
186 * with the given {@link Language language}.
188 * @param lang the language in which the language string to be removed
189 * has been formulated
190 * @see #getDescription()
192 public void removeDescription(Language lang
){
193 this.description
.remove(lang
);
197 //*********************************** CLONE *****************************************/
200 * Clones <i>this</i> taxon interaction. This is a shortcut that enables to create
201 * a new instance that differs only slightly from <i>this</i> taxon interaction by
202 * modifying only some of the attributes.
204 * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
205 * @see java.lang.Object#clone()
208 public Object
clone() {
211 TaxonInteraction result
= (TaxonInteraction
)super.clone();
214 result
.description
= cloneLanguageString(getDescription());
217 //no changes to: taxon2
218 } catch (CloneNotSupportedException e
) {
219 logger
.warn("Object does not implement cloneable");