Project

General

Profile

Download (11.3 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.name;
11

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

    
15
import javax.persistence.Entity;
16
import javax.persistence.FetchType;
17
import javax.persistence.Inheritance;
18
import javax.persistence.InheritanceType;
19
import javax.persistence.ManyToMany;
20
import javax.persistence.ManyToOne;
21
import javax.validation.constraints.NotNull;
22
import javax.xml.bind.annotation.XmlElement;
23
import javax.xml.bind.annotation.XmlElementWrapper;
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.XmlSeeAlso;
28
import javax.xml.bind.annotation.XmlType;
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.IndexedEmbedded;
35

    
36
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
37
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
38
import eu.etaxonomy.cdm.model.common.SourcedEntityBase;
39
import eu.etaxonomy.cdm.model.reference.Reference;
40
import eu.etaxonomy.cdm.validation.Level2;
41
import eu.etaxonomy.cdm.validation.annotation.ValidTypeDesignation;
42

    
43
/**
44
 * The (abstract) class representing a typification of one or several {@link TaxonName taxon names}.<BR>
45
 * All taxon names which have a {@link Rank rank} "species aggregate" or lower
46
 * can only be typified by specimens (a {@link SpecimenTypeDesignation specimen type designation}), but taxon
47
 * names with a higher rank might be typified by an other taxon name with
48
 * rank "species" or "genus" (a {@link NameTypeDesignation name type designation}).
49
 *
50
 * @see		TaxonName
51
 * @see		NameTypeDesignation
52
 * @see		SpecimenTypeDesignation
53
 * @author  a.mueller
54
 * @since 07.08.2008
55
 */
56
@XmlRootElement(name = "TypeDesignationBase")
57
@XmlType(name = "TypeDesignationBase", propOrder = {
58
    "typeStatus",
59
    "notDesignated",
60
    "typifiedNames",
61
    "citation",
62
    "citationMicroReference",
63
    "registrations",
64
})
65
@XmlSeeAlso({
66
    NameTypeDesignation.class,
67
    SpecimenTypeDesignation.class,
68
    TextTypeDesignation.class
69
})
70
@Entity
71
@Audited
72
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
73
@ValidTypeDesignation(groups=Level2.class)
74
public abstract class TypeDesignationBase<T extends TypeDesignationStatusBase<T>>
75
        extends SourcedEntityBase<IdentifiableSource>
76
        implements ITypeDesignation {
77

    
78
    private static final long serialVersionUID = 4838214337140859787L;
79

    
80
    @SuppressWarnings("unused")
81
    private static final Logger logger = Logger.getLogger(TypeDesignationBase.class);
82

    
83
    @XmlElement(name = "IsNotDesignated")
84
    private boolean notDesignated;
85

    
86
    @XmlElement(name = "TypeStatus")
87
    @XmlIDREF
88
    @XmlSchemaType(name = "IDREF")
89
    @ManyToOne(fetch = FetchType.LAZY, targetEntity = TypeDesignationStatusBase.class)
90
    private T typeStatus;
91

    
92
    //the lectotype (or similar) reference
93
    @XmlElement(name = "Citation")
94
    @XmlIDREF
95
    @XmlSchemaType(name = "IDREF")
96
    @ManyToOne(fetch = FetchType.LAZY)
97
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
98
    private Reference citation;
99

    
100
    //Details of the lectotype reference.
101
    @XmlElement(name = "CitationMicroReference")
102
    private String citationMicroReference;
103

    
104
    @XmlElementWrapper(name = "TypifiedNames")
105
    @XmlElement(name = "TypifiedName")
106
    @XmlIDREF
107
    @XmlSchemaType(name = "IDREF")
108
    @ManyToMany(fetch = FetchType.LAZY , mappedBy="typeDesignations")
109
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
110
    private Set<TaxonName> typifiedNames = new HashSet<>();
111

    
112
    //******* REGISTRATION *****************/
113

    
114
    @XmlElementWrapper(name = "Registrations")
115
    @XmlElement(name = "Registration")
116
    @XmlIDREF
117
    @XmlSchemaType(name = "IDREF")
118
    @ManyToMany(mappedBy="typeDesignations", fetch= FetchType.LAZY)
119
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
120
    @NotNull
121
    @IndexedEmbedded(depth=1)
122
    private Set<Registration> registrations = new HashSet<>();
123

    
124

    
125
// **************** CONSTRUCTOR *************************************/
126

    
127
    protected TypeDesignationBase(){
128
        super();
129
    }
130

    
131
    /**
132
     * Class constructor: creates a new type designation
133
     * (including its {@link Reference reference source} and eventually
134
     * the taxon name string originally used by this reference when establishing
135
     * the former designation).
136
     *
137
     * @param citation				the reference source for the new designation
138
     * @param citationMicroReference	the string with the details describing the exact localisation within the reference
139
     * @param originalNameString	the taxon name string used originally in the reference source for the new designation
140
     * @see							#TypeDesignationBase()
141
     * @see							#isNotDesignated()
142
     * @see							TaxonName#getTypeDesignations()
143
     */
144
    protected TypeDesignationBase(Reference citation, String citationMicroReference, String originalNameString) {
145
        this(citation, citationMicroReference, originalNameString, false);
146
    }
147

    
148
    /**
149
     * Class constructor: creates a new type designation
150
     * (including its {@link Reference reference source} and eventually
151
     * the taxon name string originally used by this reference when establishing
152
     * the former designation).
153
     *
154
     * @param citation				the reference source for the new designation
155
     * @param citationMicroReference	the string with the details describing the exact localisation within the reference
156
     * @param originalNameString	the taxon name string used originally in the reference source for the new designation
157
     * @param isNotDesignated		the boolean flag indicating whether there is no type at all for
158
     * 								<i>this</i> type designation
159
     * @see							#TypeDesignationBase()
160
     * @see							#isNotDesignated()
161
     * @see							TaxonName#getTypeDesignations()
162
     */
163
    protected TypeDesignationBase(Reference citation, String citationMicroReference, String originalNameString, boolean notDesignated){
164
        super();
165
        this.notDesignated = notDesignated;
166
        this.citationMicroReference = citationMicroReference;
167
        this.citation = citation;
168
    }
169

    
170

    
171
// **************** METHODS *************************************/
172

    
173

    
174
    /**
175
     * Returns the {@link TypeDesignationStatusBase type designation status} for <i>this</i> specimen type
176
     * designation. This status describes which of the possible categories of
177
     * types like "holotype", "neotype", "syntype" or "isotype" applies to <i>this</i>
178
     * specimen type designation.
179
     */
180
    public T getTypeStatus(){
181
        return this.typeStatus;
182
    }
183
    /**
184
     * @see  #getTypeStatus()
185
     */
186
    public void setTypeStatus(T typeStatus){
187
        this.typeStatus = typeStatus;
188
    }
189

    
190
    /**
191
     * Returns the boolean value "true" if it is known that a type does not
192
     * exist and therefore the {@link TaxonName taxon name} to which <i>this</i>
193
     * type designation is assigned must still be typified. Two
194
     * cases must be differentiated: <BR><ul>
195
     * <li> a) it is unknown whether a type exists and
196
     * <li> b) it is known that no type exists
197
     *  </ul>
198
     * If a) is true there should be no TypeDesignation instance at all
199
     * assigned to the "typified" taxon name.<BR>
200
     * If b) is true there should be a TypeDesignation instance with the
201
     * flag isNotDesignated set. The typeName attribute, in case of a
202
     * {@link NameTypeDesignation name type designation}, or the typeSpecimen attribute,
203
     * in case of a {@link SpecimenTypeDesignation specimen type designation}, should then be "null".
204
     */
205
    public boolean isNotDesignated() {
206
        return notDesignated;
207
    }
208
    /**
209
     * @see   #isNotDesignated()
210
     */
211
    public void setNotDesignated(boolean notDesignated) {
212
        this.notDesignated = notDesignated;
213
    }
214

    
215
    public String getCitationMicroReference(){
216
        return this.citationMicroReference;
217
    }
218
    public void setCitationMicroReference(String citationMicroReference){
219
        this.citationMicroReference = citationMicroReference;
220
    }
221

    
222
    public Reference getCitation(){
223
        return this.citation;
224
    }
225
    public void setCitation(Reference citation) {
226
        this.citation = citation;
227
    }
228

    
229
    /**
230
     * Returns the {@link Registration registrations} available for this
231
     * type designation.
232
     */
233
    public Set<Registration> getRegistrations() {
234
        return this.registrations;
235
    }
236

    
237
    /**
238
     * Remove the type (specimen or name) from this type designation
239
     */
240
    public abstract void removeType();
241

    
242
    /**
243
     * Returns the set of {@link TaxonName taxon names} typified in <i>this</i>
244
     * type designation. This is a subset of the taxon names belonging to the
245
     * corresponding {@link #getHomotypicalGroup() homotypical group}.
246
     */
247
    @Override
248
    public Set<TaxonName> getTypifiedNames() {
249
        return typifiedNames;
250
    }
251

    
252
    /**
253
     * @deprecated for bidirectional use only
254
     */
255
    @Deprecated
256
    protected void addTypifiedName(TaxonName taxonName){
257
        this.typifiedNames.add(taxonName);
258
    }
259

    
260
    /**
261
     * @deprecated for bidirectional use only
262
     */
263
    @Deprecated
264
    protected void removeTypifiedName(TaxonName taxonName){
265
        this.typifiedNames.remove(taxonName);
266
        if (taxonName.getTypeDesignations().contains(this)){
267
            taxonName.removeTypeDesignation(this);
268
        }
269
    }
270

    
271

    
272
    /**
273
     * {@inheritDoc}
274
     */
275
    @Override
276
    protected IdentifiableSource createNewInstance(OriginalSourceType type, String idInSource, String idNamespace,
277
            Reference reference, String microReference, String originalInfo) {
278
        return IdentifiableSource.NewInstance(type, idInSource, idNamespace, reference, microReference, originalInfo);
279
    }
280

    
281
//*********************** CLONE ********************************************************/
282

    
283
    /**
284
     * Clones <i>this</i> type designation. This is a shortcut that enables to create
285
     * a new instance that differs only slightly from <i>this</i> type designation by
286
     * modifying only some of the attributes.<BR>
287
     * CAUTION: the typifiedNames set is also cloned by adding the new type designation
288
     * to the typifiedNames of the original type designation. If this is unwanted
289
     * th
290
     *
291
     * not cloned but empty after cloning as the typified
292
     * names is considered to be the not owning part of a bidirectional relationship.
293
     * This may be changed in future.
294
     *
295
     * @throws CloneNotSupportedException
296
     *
297
     * @see eu.etaxonomy.cdm.model.common.ReferencedEntityBase#clone()
298
     * @see java.lang.Object#clone()
299
     */
300
    @Override
301
    public Object clone() throws CloneNotSupportedException {
302
        TypeDesignationBase<?> result = (TypeDesignationBase<?>)super.clone();
303

    
304
		//registrations
305
		result.registrations = new HashSet<>();
306
		for (Registration registration : registrations){
307
		    registration.addTypeDesignation(result);
308
		}
309

    
310
        //typified names
311
        result.typifiedNames = new HashSet<>();
312
        for (TaxonName taxonName : getTypifiedNames()){
313
            taxonName.addTypeDesignation(result, false);
314
        }
315

    
316
        //no changes to: notDesignated, typeStatus, homotypicalGroup
317
        return result;
318
    }
319
}
(33-33/36)