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
.OneToMany
;
21 import javax
.xml
.bind
.annotation
.XmlAccessType
;
22 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
23 import javax
.xml
.bind
.annotation
.XmlElement
;
24 import javax
.xml
.bind
.annotation
.XmlIDREF
;
25 import javax
.xml
.bind
.annotation
.XmlRootElement
;
26 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
27 import javax
.xml
.bind
.annotation
.XmlType
;
28 import javax
.xml
.bind
.annotation
.adapters
.XmlJavaTypeAdapter
;
30 import org
.apache
.log4j
.Logger
;
31 import org
.hibernate
.annotations
.Cascade
;
32 import org
.hibernate
.annotations
.CascadeType
;
33 import org
.hibernate
.envers
.Audited
;
34 import org
.hibernate
.search
.annotations
.Indexed
;
36 import eu
.etaxonomy
.cdm
.jaxb
.MultilanguageTextAdapter
;
37 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
38 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
39 import eu
.etaxonomy
.cdm
.model
.common
.MultilanguageText
;
40 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
43 * This class represents associations between the described
44 * {@link SpecimenOrObservationBase specimen or observation}
45 * and a second one (for instance a host).
46 * Only {@link SpecimenDescription specimen descriptions} may contain individuals association.
47 * The association itself is described by a {@link MultilanguageText multilanguage text}.
49 * This class corresponds (partially) to NaturalLanguageDescriptionType
50 * according to the SDD schema.
54 * @created 08-Nov-2007 13:06:28
56 @XmlAccessorType(XmlAccessType
.FIELD
)
57 @XmlType(name
= "IndividualsAssociation", propOrder
= {
59 "associatedSpecimenOrObservation"
61 @XmlRootElement(name
= "IndividualsAssociation")
64 @Indexed(index
= "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
65 public class IndividualsAssociation
extends DescriptionElementBase
{
66 private static final long serialVersionUID
= -4117554860254531809L;
67 @SuppressWarnings("unused")
68 private static final Logger logger
= Logger
.getLogger(IndividualsAssociation
.class);
70 @XmlElement(name
= "Description")
71 @XmlJavaTypeAdapter(MultilanguageTextAdapter
.class)
72 @OneToMany(fetch
= FetchType
.LAZY
)
73 @JoinTable(name
= "IndividualAssociation_LanguageString")
74 private Map
<Language
,LanguageString
> description
= new HashMap
<Language
,LanguageString
>();
76 @XmlElement(name
= "AssociatedSpecimenOrObservation")
78 @XmlSchemaType(name
= "IDREF")
79 @ManyToOne(fetch
= FetchType
.LAZY
)
80 @Cascade(CascadeType
.SAVE_UPDATE
)
81 private SpecimenOrObservationBase associatedSpecimenOrObservation
;
84 * Class constructor: creates a new empty individuals association instance.
86 protected IndividualsAssociation(){
91 * Creates a new empty individuals association instance.
93 public static IndividualsAssociation
NewInstance(){
94 return new IndividualsAssociation();
99 * Returns the second {@link SpecimenOrObservationBase specimen or observation}
100 * involved in <i>this</i> individuals association.
101 * The first specimen or observation is the specimen or observation
102 * described in the corresponding {@link SpecimenDescription specimen description}.
104 public SpecimenOrObservationBase
getAssociatedSpecimenOrObservation() {
105 return associatedSpecimenOrObservation
;
108 * @see #getAssociatedSpecimenOrObservation()
110 public void setAssociatedSpecimenOrObservation(
111 SpecimenOrObservationBase associatedSpecimenOrObservation
) {
112 this.associatedSpecimenOrObservation
= associatedSpecimenOrObservation
;
117 * Returns the {@link MultilanguageText multilanguage text} used to describe
118 * <i>this</i> individuals association. The different {@link LanguageString language strings}
119 * contained in the multilanguage text should all have the same meaning.
121 public Map
<Language
,LanguageString
> getDescription(){
122 return this.description
;
126 * Adds a translated {@link LanguageString text in a particular language}
127 * to the {@link MultilanguageText multilanguage text} used to describe
128 * <i>this</i> individuals association.
130 * @param description the language string describing the individuals association
131 * in a particular language
132 * @see #getDescription()
133 * @see #addDescription(String, Language)
135 public void addDescription(LanguageString description
){
136 this.description
.put(description
.getLanguage(),description
);
139 * Creates a {@link LanguageString language string} based on the given text string
140 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text}
141 * used to describe <i>this</i> individuals association.
143 * @param text the string describing the individuals association
144 * in a particular language
145 * @param language the language in which the text string is formulated
146 * @see #getDescription()
147 * @see #addDescription(LanguageString)
149 public void addDescription(String text
, Language language
){
150 this.description
.put(language
, LanguageString
.NewInstance(text
, language
));
153 * Removes from the {@link MultilanguageText multilanguage text} used to describe
154 * <i>this</i> individuals association the one {@link LanguageString language string}
155 * with the given {@link Language language}.
157 * @param language the language in which the language string to be removed
158 * has been formulated
159 * @see #getDescription()
161 public void removeDescription(Language language
){
162 this.description
.remove(language
);