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
    "typifiedNames",
59
    "notDesignated",
60
    "typeStatus",
61
    "registrations",
62
})
63
@XmlSeeAlso({
64
    NameTypeDesignation.class,
65
    SpecimenTypeDesignation.class,
66
    TextTypeDesignation.class
67
})
68
@Entity
69
@Audited
70
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
71
@ValidTypeDesignation(groups=Level2.class)
72
public abstract class TypeDesignationBase<T extends TypeDesignationStatusBase<T>>
73
        extends SourcedEntityBase<IdentifiableSource>
74
        implements ITypeDesignation {
75

    
76
    private static final long serialVersionUID = 4838214337140859787L;
77

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

    
81
    @XmlElement(name = "IsNotDesignated")
82
    private boolean notDesignated;
83

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

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

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

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

    
110
    //******* REGISTRATION *****************/
111

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

    
122

    
123
// **************** CONSTRUCTOR *************************************/
124

    
125
    protected TypeDesignationBase(){
126
        super();
127
    }
128

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

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

    
168

    
169
// **************** METHODS *************************************/
170

    
171

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

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

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

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

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

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

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

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

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

    
269

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

    
279
//*********************** CLONE ********************************************************/
280

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

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

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

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