3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.model
.description
;
13 import java
.util
.HashSet
;
16 import javax
.persistence
.Entity
;
17 import javax
.persistence
.FetchType
;
18 import javax
.persistence
.JoinColumn
;
19 import javax
.persistence
.JoinTable
;
20 import javax
.persistence
.ManyToMany
;
21 import javax
.validation
.constraints
.NotNull
;
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
.XmlElementWrapper
;
26 import javax
.xml
.bind
.annotation
.XmlIDREF
;
27 import javax
.xml
.bind
.annotation
.XmlRootElement
;
28 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
29 import javax
.xml
.bind
.annotation
.XmlType
;
31 import org
.apache
.log4j
.Logger
;
32 import org
.hibernate
.envers
.Audited
;
33 import org
.hibernate
.search
.annotations
.Indexed
;
35 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
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.
49 @XmlAccessorType(XmlAccessType
.FIELD
)
50 @XmlType(name
= "MultiAccessKey", propOrder
= {
56 @XmlRootElement(name
= "MultiAccessKey")
58 @Indexed(index
= "eu.etaxonomy.cdm.model.media.WorkingSet")
61 public class MultiAccessKey
extends WorkingSet
implements IIdentificationKey
{
62 private static final long serialVersionUID
= -240407483572972239L;
63 @SuppressWarnings("unused")
64 private static final Logger logger
= Logger
.getLogger(MultiAccessKey
.class);
66 @XmlElementWrapper(name
= "CoveredTaxa")
67 @XmlElement(name
= "CoveredTaxon")
69 @XmlSchemaType(name
= "IDREF")
70 @ManyToMany(fetch
= FetchType
.LAZY
)
72 private Set
<Taxon
> coveredTaxa
= new HashSet
<Taxon
>();
74 @XmlElementWrapper(name
= "TaxonomicScope")
75 @XmlElement(name
= "Taxon")
77 @XmlSchemaType(name
= "IDREF")
78 @ManyToMany(fetch
= FetchType
.LAZY
)
80 name
="MultiAccessKey_Taxon",
81 joinColumns
=@JoinColumn(name
="multiAccessKey_id"),
82 inverseJoinColumns
=@JoinColumn(name
="taxon_id")
85 private Set
<Taxon
> taxonomicScope
= new HashSet
<Taxon
>();
87 @XmlElementWrapper( name
= "GeographicalScope")
88 @XmlElement( name
= "Area")
90 @XmlSchemaType(name
= "IDREF")
91 @ManyToMany(fetch
= FetchType
.LAZY
)
92 @JoinTable(name
="MultiAccessKey_NamedArea")
94 private Set
<NamedArea
> geographicalScope
= new HashSet
<NamedArea
>();
96 @XmlElementWrapper( name
= "ScopeRestrictions")
97 @XmlElement( name
= "Restriction")
99 @XmlSchemaType(name
= "IDREF")
100 @ManyToMany(fetch
= FetchType
.LAZY
)
101 @JoinTable(name
="MultiAccessKey_Scope")
103 private Set
<Scope
> scopeRestrictions
= new HashSet
<Scope
>();
106 * Class constructor: creates a new empty multi-access key instance.
108 protected MultiAccessKey() {
113 * Creates a new empty identification multi-access key instance.
115 public static MultiAccessKey
NewInstance(){
116 return new MultiAccessKey();
120 * Returns the set of possible {@link Taxon taxa} corresponding to
121 * <i>this</i> identification key.
123 public Set
<Taxon
> getCoveredTaxa() {
124 if(coveredTaxa
== null) {
125 this.coveredTaxa
= new HashSet
<Taxon
>();
130 * @see #getCoveredTaxa()
132 protected void setCoveredTaxa(Set
<Taxon
> coveredTaxa
) {
133 this.coveredTaxa
= coveredTaxa
;
137 * Adds a {@link Taxon taxa} to the set of {@link #getCoveredTaxa() covered taxa}
138 * corresponding to <i>this</i> identification key.
140 * @param taxon the taxon to be added to <i>this</i> identification key
141 * @see #getCoveredTaxa()
143 public void addCoveredTaxon(Taxon taxon
) {
144 this.coveredTaxa
.add(taxon
);
148 * Removes one element from the set of {@link #getCoveredTaxa() covered taxa}
149 * corresponding to <i>this</i> identification key.
151 * @param taxon the taxon which should be removed
152 * @see #getCoveredTaxa()
153 * @see #addCoveredTaxon(Taxon)
155 public void removeCoveredTaxon(Taxon taxon
) {
156 this.coveredTaxa
.remove(taxon
);
160 * Returns the set of {@link NamedArea named areas} indicating the geospatial
161 * data where <i>this</i> identification key is valid.
163 public Set
<NamedArea
> getGeographicalScope() {
164 if(geographicalScope
== null) {
165 this.geographicalScope
= new HashSet
<NamedArea
>();
167 return geographicalScope
;
171 * Adds a {@link NamedArea geoScope} to the set of {@link #getGeoScopes() geogspatial scopes}
172 * corresponding to <i>this</i> identification key.
174 * @param geoScope the named area to be added to <i>this</i> identification key
175 * @see #getGeoScopes()
177 public void addGeographicalScope(NamedArea geoScope
) {
178 this.geographicalScope
.add(geoScope
);
181 * Removes one element from the set of {@link #getGeoScopes() geogspatial scopes}
182 * corresponding to <i>this</i> identification key.
184 * @param geoScope the named area which should be removed
185 * @see #getGeoScopes()
186 * @see #addGeoScope(NamedArea)
188 public void removeGeographicalScope(NamedArea geoScope
) {
189 this.geographicalScope
.remove(geoScope
);
193 * Returns the set of {@link Taxon taxa} that define the taxonomic
194 * scope of <i>this</i> identification key
196 public Set
<Taxon
> getTaxonomicScope() {
197 if(taxonomicScope
== null) {
198 this.taxonomicScope
= new HashSet
<Taxon
>();
200 return taxonomicScope
;
204 * Adds a {@link Taxon taxa} to the set of {@link #getTaxonomicScope() taxonomic scopes}
205 * corresponding to <i>this</i> identification key.
207 * @param taxon the taxon to be added to <i>this</i> identification key
208 * @see #getTaxonomicScope()
210 public void addTaxonomicScope(Taxon taxon
) {
211 this.taxonomicScope
.add(taxon
);
215 * Removes one element from the set of {@link #getTaxonomicScope() taxonomic scopes}
216 * corresponding to <i>this</i> identification key.
218 * @param taxon the taxon which should be removed
219 * @see #getTaxonomicScope()
220 * @see #addTaxonomicScope(Taxon)
222 public void removeTaxonomicScope(Taxon taxon
) {
223 this.taxonomicScope
.remove(taxon
);
227 * Returns the set of {@link Scope scope restrictions} corresponding to
228 * <i>this</i> identification key
230 public Set
<Scope
> getScopeRestrictions() {
231 if(scopeRestrictions
== null) {
232 this.scopeRestrictions
= new HashSet
<Scope
>();
234 return scopeRestrictions
;
238 * Adds a {@link Scope scope restriction} to the set of {@link #getScopeRestrictions() scope restrictions}
239 * corresponding to <i>this</i> identification key.
241 * @param scopeRestriction the scope restriction to be added to <i>this</i> identification key
242 * @see #getScopeRestrictions()
244 public void addScopeRestriction(Scope scopeRestriction
) {
245 this.scopeRestrictions
.add(scopeRestriction
);
249 * Removes one element from the set of {@link #getScopeRestrictions() scope restrictions}
250 * corresponding to <i>this</i> identification key.
252 * @param scopeRestriction the scope restriction which should be removed
253 * @see #getScopeRestrictions()
254 * @see #addScopeRestriction(Scope)
256 public void removeScopeRestriction(Scope scopeRestriction
) {
257 this.scopeRestrictions
.remove(scopeRestriction
);
260 //*********************** CLONE ********************************************************/
263 * Clones <i>this</i> MultiAccessKey. This is a shortcut that enables to create
264 * a new instance that differs only slightly from <i>this</i> MultiAccessKey by
265 * modifying only some of the attributes.
267 * @see eu.etaxonomy.cdm.model.common.AnnotatableEntity#clone()
268 * @see java.lang.Object#clone()
271 public Object
clone() {
272 MultiAccessKey result
;
274 result
= (MultiAccessKey
)super.clone();
276 result
.coveredTaxa
= new HashSet
<Taxon
>();
277 for (Taxon taxon
: this.coveredTaxa
){
278 result
.addCoveredTaxon(taxon
);
281 result
.geographicalScope
= new HashSet
<NamedArea
>();
282 for (NamedArea area
: this.geographicalScope
){
283 result
.addGeographicalScope(area
);
286 result
.scopeRestrictions
= new HashSet
<Scope
>();
287 for (Scope scope
: this.scopeRestrictions
){
288 result
.addScopeRestriction(scope
);
291 result
.taxonomicScope
= new HashSet
<Taxon
>();
292 for (Taxon taxon
: this.taxonomicScope
){
293 result
.addTaxonomicScope(taxon
);