Project

General

Profile

Download (8.66 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.ArrayList;
14
import java.util.HashMap;
15
import java.util.Map;
16

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

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

    
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.occurrence.SpecimenOrObservationBase;
43

    
44
/**
45
 * This class represents associations between the described
46
 * {@link SpecimenOrObservationBase specimen or observation}
47
 * and a second one (for instance a host).
48
 * Only {@link SpecimenDescription specimen descriptions} may contain individuals association.
49
 * The association itself is described by a {@link MultilanguageText multilanguage text}.
50
 * <P>
51
 * This class corresponds (partially) to NaturalLanguageDescriptionType
52
 * according to the SDD schema.
53
 *
54
 * @author m.doering
55
 * @version 1.0
56
 * @created 08-Nov-2007 13:06:28
57
 */
58
@XmlAccessorType(XmlAccessType.FIELD)
59
@XmlType(name = "IndividualsAssociation", propOrder = {
60
    "description",
61
    "associatedSpecimenOrObservation"
62
})
63
@XmlRootElement(name = "IndividualsAssociation")
64
@Entity
65
@Audited
66
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
67
public class IndividualsAssociation extends DescriptionElementBase implements IMultiLanguageTextHolder, Cloneable{
68
	private static final long serialVersionUID = -4117554860254531809L;
69
	@SuppressWarnings("unused")
70
	private static final Logger logger = Logger.getLogger(IndividualsAssociation.class);
71
	
72
	@XmlElement(name = "Description")
73
	@XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
74
	@OneToMany(fetch = FetchType.LAZY)
75
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE, CascadeType.DELETE_ORPHAN })
76
	@JoinTable(name = "IndividualAssociation_LanguageString")
77
	private Map<Language,LanguageString> description = new HashMap<Language,LanguageString>();
78
	
79
	@XmlElement(name = "AssociatedSpecimenOrObservation")
80
	@XmlIDREF
81
	@XmlSchemaType(name = "IDREF")
82
	@ManyToOne(fetch = FetchType.LAZY)
83
	@Cascade(CascadeType.SAVE_UPDATE)
84
	private SpecimenOrObservationBase associatedSpecimenOrObservation;
85

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

    
101
	/** 
102
	 * Returns the second {@link SpecimenOrObservationBase specimen or observation}
103
	 * involved in <i>this</i> individuals association.
104
	 * The first specimen or observation is the specimen or observation
105
	 * described in the corresponding {@link SpecimenDescription specimen description}.
106
	 */
107
	public SpecimenOrObservationBase getAssociatedSpecimenOrObservation() {
108
		return associatedSpecimenOrObservation;
109
	}
110
	/**
111
	 * @see	#getAssociatedSpecimenOrObservation() 
112
	 */
113
	public void setAssociatedSpecimenOrObservation(
114
			SpecimenOrObservationBase associatedSpecimenOrObservation) {
115
		this.associatedSpecimenOrObservation = associatedSpecimenOrObservation;
116
	}
117

    
118
	
119
	/** 
120
	 * Returns the {@link MultilanguageText multilanguage text} used to describe
121
	 * <i>this</i> individuals association. The different {@link LanguageString language strings}
122
	 * contained in the multilanguage text should all have the same meaning.
123
	 */
124
	public Map<Language,LanguageString> getDescription(){
125
		return this.description;
126
	}
127
	
128
	/**
129
	 * Adds a translated {@link LanguageString text in a particular language}
130
	 * to the {@link MultilanguageText multilanguage text} used to describe
131
	 * <i>this</i> individuals association.
132
	 * 
133
	 * @param description	the language string describing the individuals association
134
	 * 						in a particular language
135
	 * @see    	   			#getDescription()
136
	 * @see    	   			#putDescription(Language, String)
137
	 * @deprecated 			should follow the put semantic of maps, this method will be removed in v4.0
138
	 * 						Use the {@link #putDescription(LanguageString) putDescription} method instead
139
	 */
140
	public void addDescription(LanguageString description){
141
		this.putDescription(description);
142
	}
143
	
144
	/**
145
	 * Adds a translated {@link LanguageString text in a particular language}
146
	 * to the {@link MultilanguageText multilanguage text} used to describe
147
	 * <i>this</i> individuals association.
148
	 * 
149
	 * @param description	the language string describing the individuals association
150
	 * 						in a particular language
151
	 * @see    	   			#getDescription()
152
	 * @see    	   			#putDescription(Language, String)
153
	 * 
154
	 */
155
	public void putDescription(LanguageString description){
156
		this.description.put(description.getLanguage(),description);
157
	}
158
	/**
159
	 * Creates a {@link LanguageString language string} based on the given text string
160
	 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text} 
161
	 * used to describe <i>this</i> individuals association.
162
	 * 
163
	 * @param text		the string describing the individuals association
164
	 * 					in a particular language
165
	 * @param language	the language in which the text string is formulated
166
	 * @see    	   		#getDescription()
167
	 * @see    	   		#putDescription(LanguageString)
168
	 */
169
	public void putDescription(Language language, String text){
170
		this.description.put(language, LanguageString.NewInstance(text, language));
171
	}
172
	
173
	/**
174
	 * Creates a {@link LanguageString language string} based on the given text string
175
	 * and the given {@link Language language} and adds it to the {@link MultilanguageText multilanguage text} 
176
	 * used to describe <i>this</i> individuals association.
177
	 * 
178
	 * @param text		the string describing the individuals association
179
	 * 					in a particular language
180
	 * @param language	the language in which the text string is formulated
181
	 * @see    	   		#getDescription()
182
	 * @see    	   		#putDescription(LanguageString)
183
	 * @deprecated		should follow the put semantic of maps, this method will be removed in v4.0
184
	 * 					Use the {@link #putDescription(Language, String) putDescription} method instead
185
	 */
186
	public void addDescription(String text, Language language){
187
		this.putDescription(language, text);
188
	}
189
	/** 
190
	 * Removes from the {@link MultilanguageText multilanguage text} used to describe
191
	 * <i>this</i> individuals association the one {@link LanguageString language string}
192
	 * with the given {@link Language language}.
193
	 *
194
	 * @param  language	the language in which the language string to be removed
195
	 * 					has been formulated
196
	 * @see     		#getDescription()
197
	 */
198
	public void removeDescription(Language language){
199
		this.description.remove(language);
200
	}
201

    
202

    
203
//*********************************** CLONE *****************************************/
204

    
205
	/** 
206
	 * Clones <i>this</i> individuals association. This is a shortcut that enables to create
207
	 * a new instance that differs only slightly from <i>this</i> individuals association by
208
	 * modifying only some of the attributes.
209
	 * 
210
	 * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
211
	 * @see java.lang.Object#clone()
212
	 */
213
	@Override
214
	public Object clone() {
215

    
216
		try {
217
			IndividualsAssociation result = (IndividualsAssociation)super.clone();
218
			
219
			//description
220
			result.description = new HashMap<Language, LanguageString>();
221
			for (Language language : getDescription().keySet()){
222
				//TODO clone needed?
223
				LanguageString newLanguageString = (LanguageString)getDescription().get(language).clone();
224
				result.description.put(language, newLanguageString);
225
			}
226
	
227
			
228
			return result;
229
			//no changes to: associatedSpecimenOrObservation
230
		} catch (CloneNotSupportedException e) {
231
			logger.warn("Object does not implement cloneable");
232
			e.printStackTrace();
233
			return null;
234
		}
235
	}	
236
	
237
}
(12-12/39)