Project

General

Profile

Download (5.87 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
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.
8
*/
9

    
10
package eu.etaxonomy.cdm.model.description;
11

    
12

    
13
import java.util.HashMap;
14
import java.util.Map;
15

    
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;
29

    
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;
35

    
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;
41

    
42
/**
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}.
48
 * <P>
49
 * This class corresponds (partially) to NaturalLanguageDescriptionType
50
 * according to the SDD schema.
51
 *
52
 * @author m.doering
53
 * @version 1.0
54
 * @created 08-Nov-2007 13:06:28
55
 */
56
@XmlAccessorType(XmlAccessType.FIELD)
57
@XmlType(name = "IndividualsAssociation", propOrder = {
58
    "description",
59
    "associatedSpecimenOrObservation"
60
})
61
@XmlRootElement(name = "IndividualsAssociation")
62
@Entity
63
@Audited
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);
69
	
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>();
75
	
76
	@XmlElement(name = "AssociatedSpecimenOrObservation")
77
	@XmlIDREF
78
	@XmlSchemaType(name = "IDREF")
79
	@ManyToOne(fetch = FetchType.LAZY)
80
	@Cascade(CascadeType.SAVE_UPDATE)
81
	private SpecimenOrObservationBase associatedSpecimenOrObservation;
82

    
83
	/** 
84
	 * Class constructor: creates a new empty individuals association instance.
85
	 */
86
	protected IndividualsAssociation(){
87
		super(null);
88
	}
89
	
90
	/** 
91
	 * Creates a new empty individuals association instance.
92
	 */
93
	public static IndividualsAssociation NewInstance(){
94
		return new IndividualsAssociation();
95
	}
96
	
97

    
98
	/** 
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}.
103
	 */
104
	public SpecimenOrObservationBase getAssociatedSpecimenOrObservation() {
105
		return associatedSpecimenOrObservation;
106
	}
107
	/**
108
	 * @see	#getAssociatedSpecimenOrObservation() 
109
	 */
110
	public void setAssociatedSpecimenOrObservation(
111
			SpecimenOrObservationBase associatedSpecimenOrObservation) {
112
		this.associatedSpecimenOrObservation = associatedSpecimenOrObservation;
113
	}
114

    
115
	
116
	/** 
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.
120
	 */
121
	public Map<Language,LanguageString> getDescription(){
122
		return this.description;
123
	}
124
	
125
	/**
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.
129
	 * 
130
	 * @param description	the language string describing the individuals association
131
	 * 						in a particular language
132
	 * @see    	   			#getDescription()
133
	 * @see    	   			#addDescription(String, Language)
134
	 */
135
	public void addDescription(LanguageString description){
136
		this.description.put(description.getLanguage(),description);
137
	}
138
	/**
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.
142
	 * 
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)
148
	 */
149
	public void addDescription(String text, Language language){
150
		this.description.put(language, LanguageString.NewInstance(text, language));
151
	}
152
	/** 
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}.
156
	 *
157
	 * @param  language	the language in which the language string to be removed
158
	 * 					has been formulated
159
	 * @see     		#getDescription()
160
	 */
161
	public void removeDescription(Language language){
162
		this.description.remove(language);
163
	}
164

    
165
}
(11-11/36)