Project

General

Profile

Download (8.97 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

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

    
13
import java.util.HashSet;
14
import java.util.Set;
15

    
16
import javax.persistence.Entity;
17
import javax.persistence.FetchType;
18
import javax.persistence.JoinTable;
19
import javax.persistence.ManyToMany;
20
import javax.validation.constraints.NotNull;
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.XmlElementWrapper;
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

    
30
import org.apache.log4j.Logger;
31
import org.hibernate.envers.Audited;
32

    
33
import eu.etaxonomy.cdm.model.common.DefinedTerm;
34
import eu.etaxonomy.cdm.model.location.NamedArea;
35
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
36
import eu.etaxonomy.cdm.model.taxon.Taxon;
37

    
38
/**
39
 *
40
 * The class representing multi-access dynamic keys used to identify
41
 * {@link SpecimenOrObservationBase specimens or observations} (this means to assign {@link Taxon taxa} to).
42
 * The determination process is performed by an identification software.
43
 *
44
 * @author h.fradin
45
 * @created 13.08.2009
46
 * @version 1.0
47
 */
48

    
49
@XmlAccessorType(XmlAccessType.FIELD)
50
@XmlType(name = "MultiAccessKey", propOrder = {
51
    "coveredTaxa",
52
    "taxonomicScope",
53
    "geographicalScope",
54
    "scopeRestrictions"
55
})
56
@XmlRootElement(name = "MultiAccessKey")
57
@Entity
58
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
59
//@Indexed(index = "eu.etaxonomy.cdm.model.media.WorkingSet")
60
@Audited
61

    
62
public class MultiAccessKey extends WorkingSet implements IIdentificationKey{
63
	private static final long serialVersionUID = -240407483572972239L;
64
	@SuppressWarnings("unused")
65
	private static final Logger logger = Logger.getLogger(MultiAccessKey.class);
66

    
67
	@XmlElementWrapper(name = "CoveredTaxa")
68
	@XmlElement(name = "CoveredTaxon")
69
	@XmlIDREF
70
	@XmlSchemaType(name = "IDREF")
71
	@ManyToMany(fetch = FetchType.LAZY)
72
    @JoinTable(name="MultiAccessKey_CoveredTaxon")
73
    @NotNull
74
	private Set<Taxon> coveredTaxa = new HashSet<Taxon>();
75

    
76
	@XmlElementWrapper(name = "TaxonomicScope")
77
	@XmlElement(name = "Taxon")
78
	@XmlIDREF
79
	@XmlSchemaType(name = "IDREF")
80
	@ManyToMany(fetch = FetchType.LAZY)
81
	@JoinTable(name="MultiAccessKey_TaxonScope")
82
	@NotNull
83
	private Set<Taxon> taxonomicScope = new HashSet<Taxon>();
84

    
85
	@XmlElementWrapper( name = "GeographicalScope")
86
	@XmlElement( name = "Area")
87
	@XmlIDREF
88
	@XmlSchemaType(name = "IDREF")
89
	@ManyToMany(fetch = FetchType.LAZY)
90
    @JoinTable(name="MultiAccessKey_NamedArea")
91
	@NotNull
92
	private Set<NamedArea> geographicalScope = new HashSet<NamedArea>();
93

    
94
	@XmlElementWrapper( name = "ScopeRestrictions")
95
	@XmlElement( name = "Restriction")
96
	@XmlIDREF
97
	@XmlSchemaType(name = "IDREF")
98
	@ManyToMany(fetch = FetchType.LAZY)
99
    @JoinTable(name="MultiAccessKey_Scope")
100
	@NotNull
101
	private Set<DefinedTerm> scopeRestrictions = new HashSet<DefinedTerm>();
102

    
103
	/**
104
	 * Class constructor: creates a new empty multi-access key instance.
105
	 */
106
	protected MultiAccessKey() {
107
		super();
108
	}
109

    
110
	/**
111
	 * Creates a new empty identification multi-access key instance.
112
	 */
113
	public static MultiAccessKey NewInstance(){
114
		return new MultiAccessKey();
115
	}
116

    
117
	/**
118
	 * Returns the set of possible {@link Taxon taxa} corresponding to
119
	 * <i>this</i> identification key.
120
	 */
121
	@Override
122
    public Set<Taxon> getCoveredTaxa() {
123
		if(coveredTaxa == null) {
124
			this.coveredTaxa = new HashSet<Taxon>();
125
		}
126
		return coveredTaxa;
127
	}
128
	/**
129
	 * @see	#getCoveredTaxa()
130
	 */
131
	protected void setCoveredTaxa(Set<Taxon> coveredTaxa) {
132
		this.coveredTaxa = coveredTaxa;
133
	}
134

    
135
	/**
136
	 * Adds a {@link Taxon taxa} to the set of {@link #getCoveredTaxa() covered taxa}
137
	 * corresponding to <i>this</i> identification key.
138
	 *
139
	 * @param	taxon	the taxon to be added to <i>this</i> identification key
140
	 * @see    	   		#getCoveredTaxa()
141
	 */
142
	@Override
143
    public void addCoveredTaxon(Taxon taxon) {
144
		this.coveredTaxa.add(taxon);
145
	}
146

    
147
	/**
148
	 * Removes one element from the set of {@link #getCoveredTaxa() covered taxa}
149
	 * corresponding to <i>this</i> identification key.
150
	 *
151
	 * @param	taxon	the taxon which should be removed
152
	 * @see     		#getCoveredTaxa()
153
	 * @see     		#addCoveredTaxon(Taxon)
154
	 */
155
	@Override
156
    public void removeCoveredTaxon(Taxon taxon) {
157
		this.coveredTaxa.remove(taxon);
158
	}
159

    
160
	/**
161
	 * Returns the set of {@link NamedArea named areas} indicating the geospatial
162
	 * data where <i>this</i> identification key is valid.
163
	 */
164
	@Override
165
    public Set<NamedArea> getGeographicalScope() {
166
		if(geographicalScope == null) {
167
			this.geographicalScope = new HashSet<NamedArea>();
168
		}
169
		return geographicalScope;
170
	}
171

    
172
	/**
173
	 * Adds a {@link NamedArea geoScope} to the set of {@link #getGeoScopes() geogspatial scopes}
174
	 * corresponding to <i>this</i> identification key.
175
	 *
176
	 * @param	geoScope	the named area to be added to <i>this</i> identification key
177
	 * @see    	   		 	#getGeoScopes()
178
	 */
179
	@Override
180
    public void addGeographicalScope(NamedArea geoScope) {
181
		this.geographicalScope.add(geoScope);
182
	}
183
	/**
184
	 * Removes one element from the set of {@link #getGeoScopes() geogspatial scopes}
185
	 * corresponding to <i>this</i> identification key.
186
	 *
187
	 * @param	geoScope	the named area which should be removed
188
	 * @see     			#getGeoScopes()
189
	 * @see     			#addGeoScope(NamedArea)
190
	 */
191
	@Override
192
    public void removeGeographicalScope(NamedArea geoScope) {
193
		this.geographicalScope.remove(geoScope);
194
	}
195

    
196
	/**
197
	 * Returns the set of {@link Taxon taxa} that define the taxonomic
198
	 * scope of <i>this</i> identification key
199
	 */
200
	@Override
201
    public Set<Taxon> getTaxonomicScope() {
202
		if(taxonomicScope == null) {
203
			this.taxonomicScope = new HashSet<Taxon>();
204
		}
205
		return taxonomicScope;
206
	}
207

    
208
	/**
209
	 * Adds a {@link Taxon taxa} to the set of {@link #getTaxonomicScope() taxonomic scopes}
210
	 * corresponding to <i>this</i> identification key.
211
	 *
212
	 * @param	taxon	the taxon to be added to <i>this</i> identification key
213
	 * @see    	   		#getTaxonomicScope()
214
	 */
215
	@Override
216
    public void addTaxonomicScope(Taxon taxon) {
217
		this.taxonomicScope.add(taxon);
218
	}
219

    
220
	/**
221
	 * Removes one element from the set of {@link #getTaxonomicScope() taxonomic scopes}
222
	 * corresponding to <i>this</i> identification key.
223
	 *
224
	 * @param	taxon	the taxon which should be removed
225
	 * @see     		#getTaxonomicScope()
226
	 * @see     		#addTaxonomicScope(Taxon)
227
	 */
228
	@Override
229
    public void removeTaxonomicScope(Taxon taxon) {
230
		this.taxonomicScope.remove(taxon);
231
	}
232

    
233
	/**
234
	 * Returns the set of {@link Scope scope restrictions} corresponding to
235
	 * <i>this</i> identification key
236
	 */
237
	@Override
238
    public Set<DefinedTerm> getScopeRestrictions() {
239
		if(scopeRestrictions == null) {
240
			this.scopeRestrictions = new HashSet<DefinedTerm>();
241
		}
242
		return scopeRestrictions;
243
	}
244

    
245
	/**
246
	 * Adds a {@link Scope scope restriction} to the set of {@link #getScopeRestrictions() scope restrictions}
247
	 * corresponding to <i>this</i> identification key.
248
	 *
249
	 * @param	scopeRestriction	the scope restriction to be added to <i>this</i> identification key
250
	 * @see    	   		#getScopeRestrictions()
251
	 */
252
	@Override
253
    public void addScopeRestriction(DefinedTerm scopeRestriction) {
254
		this.scopeRestrictions.add(scopeRestriction);
255
	}
256

    
257
	/**
258
	 * Removes one element from the set of {@link #getScopeRestrictions() scope restrictions}
259
	 * corresponding to <i>this</i> identification key.
260
	 *
261
	 * @param	scopeRestriction	the scope restriction which should be removed
262
	 * @see     		#getScopeRestrictions()
263
	 * @see     		#addScopeRestriction(Scope)
264
	 */
265
	@Override
266
    public void removeScopeRestriction(DefinedTerm scopeRestriction) {
267
		this.scopeRestrictions.remove(scopeRestriction);
268
	}
269

    
270
//*********************** CLONE ********************************************************/
271

    
272
	/**
273
	 * Clones <i>this</i> MultiAccessKey. This is a shortcut that enables to create
274
	 * a new instance that differs only slightly from <i>this</i> MultiAccessKey by
275
	 * modifying only some of the attributes.
276
	 *
277
	 * @see eu.etaxonomy.cdm.model.common.AnnotatableEntity#clone()
278
	 * @see java.lang.Object#clone()
279
	 */
280
	@Override
281
	public Object clone() {
282
		MultiAccessKey result;
283

    
284
			result = (MultiAccessKey)super.clone();
285

    
286
			result.coveredTaxa = new HashSet<Taxon>();
287
			for (Taxon taxon: this.coveredTaxa){
288
				result.addCoveredTaxon(taxon);
289
			}
290

    
291
			result.geographicalScope = new HashSet<NamedArea>();
292
			for (NamedArea area: this.geographicalScope){
293
				result.addGeographicalScope(area);
294
			}
295

    
296
			result.scopeRestrictions = new HashSet<DefinedTerm>();
297
			for (DefinedTerm scope: this.scopeRestrictions){
298
				result.addScopeRestriction(scope);
299
			}
300

    
301
			result.taxonomicScope = new HashSet<Taxon>();
302
			for (Taxon taxon: this.taxonomicScope){
303
				result.addTaxonomicScope(taxon);
304
			}
305
			return result;
306

    
307
	}
308
}
(18-18/36)