Project

General

Profile

Download (10.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.xml.bind.annotation.XmlElement;
22
import javax.xml.bind.annotation.XmlElementWrapper;
23
import javax.xml.bind.annotation.XmlIDREF;
24
import javax.xml.bind.annotation.XmlRootElement;
25
import javax.xml.bind.annotation.XmlSchemaType;
26
import javax.xml.bind.annotation.XmlSeeAlso;
27
import javax.xml.bind.annotation.XmlType;
28

    
29
import org.apache.log4j.Logger;
30
import org.hibernate.annotations.Cascade;
31
import org.hibernate.annotations.CascadeType;
32
import org.hibernate.envers.Audited;
33

    
34
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
35
import eu.etaxonomy.cdm.model.reference.Reference;
36
import eu.etaxonomy.cdm.validation.Level2;
37
import eu.etaxonomy.cdm.validation.annotation.ValidTypeDesignation;
38

    
39
/**
40
 * The (abstract) class representing a typification of one or several {@link TaxonNameBase taxon names}.<BR>
41
 * All taxon names which have a {@link Rank rank} "species aggregate" or lower
42
 * can only be typified by specimens (a {@link SpecimenTypeDesignation specimen type designation}), but taxon
43
 * names with a higher rank might be typified by an other taxon name with
44
 * rank "species" or "genus" (a {@link NameTypeDesignation name type designation}).
45
 *
46
 * @see		TaxonNameBase
47
 * @see		NameTypeDesignation
48
 * @see		SpecimenTypeDesignation
49
 * @author  a.mueller
50
 * @created 07.08.2008
51
 * @version 1.0
52
 */
53
@XmlRootElement(name = "TypeDesignationBase")
54
@XmlType(name = "TypeDesignationBase", propOrder = {
55
    "typifiedNames",
56
    "notDesignated",
57
    "typeStatus"
58
})
59
@XmlSeeAlso({
60
    NameTypeDesignation.class,
61
    SpecimenTypeDesignation.class
62
})
63
@Entity
64
@Audited
65
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
66
@ValidTypeDesignation(groups=Level2.class)
67
public abstract class TypeDesignationBase<T extends TypeDesignationStatusBase> extends ReferencedEntityBase implements ITypeDesignation {
68
    private static final long serialVersionUID = 8622351017235131355L;
69

    
70
    @SuppressWarnings("unused")
71
    private static final Logger logger = Logger.getLogger(TypeDesignationBase.class);
72

    
73
    @XmlElement(name = "IsNotDesignated")
74
    private boolean notDesignated;
75

    
76
    @XmlElementWrapper(name = "TypifiedNames")
77
    @XmlElement(name = "TypifiedName")
78
    @XmlIDREF
79
    @XmlSchemaType(name = "IDREF")
80
    @ManyToMany(fetch = FetchType.LAZY , mappedBy="typeDesignations")
81
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
82
    private Set<TaxonNameBase> typifiedNames = new HashSet<TaxonNameBase>();
83

    
84
//    @XmlElement(name = "HomotypicalGroup")
85
//    @XmlIDREF
86
//    @XmlSchemaType(name = "IDREF")
87
//    @ManyToOne(fetch = FetchType.LAZY)
88
//    @Cascade(CascadeType.SAVE_UPDATE,CascadeType.MERGE)
89
//    private HomotypicalGroup homotypicalGroup;
90

    
91
    @XmlElement(name = "TypeStatus")
92
    @XmlIDREF
93
    @XmlSchemaType(name = "IDREF")
94
    @ManyToOne(fetch = FetchType.LAZY, targetEntity = TypeDesignationStatusBase.class)
95
    private T typeStatus;
96

    
97
// **************** CONSTRUCTOR *************************************/
98

    
99
    /**
100
     * Class constructor: creates a new empty type designation.
101
     *
102
     * @see	#TypeDesignationBase(Reference, String, String, Boolean)
103
     */
104
    protected TypeDesignationBase(){
105
        super();
106
    }
107

    
108
    /**
109
     * Class constructor: creates a new type designation
110
     * (including its {@link Reference reference source} and eventually
111
     * the taxon name string originally used by this reference when establishing
112
     * the former designation).
113
     *
114
     * @param citation				the reference source for the new designation
115
     * @param citationMicroReference	the string with the details describing the exact localisation within the reference
116
     * @param originalNameString	the taxon name string used originally in the reference source for the new designation
117
     * @see							#TypeDesignationBase()
118
     * @see							#isNotDesignated()
119
     * @see							TaxonNameBase#getTypeDesignations()
120
     */
121
    protected TypeDesignationBase(Reference citation, String citationMicroReference, String originalNameString) {
122
        this(citation, citationMicroReference, originalNameString, false);
123
    }
124

    
125
    /**
126
     * Class constructor: creates a new type designation
127
     * (including its {@link Reference reference source} and eventually
128
     * the taxon name string originally used by this reference when establishing
129
     * the former designation).
130
     *
131
     * @param citation				the reference source for the new designation
132
     * @param citationMicroReference	the string with the details describing the exact localisation within the reference
133
     * @param originalNameString	the taxon name string used originally in the reference source for the new designation
134
     * @param isNotDesignated		the boolean flag indicating whether there is no type at all for
135
     * 								<i>this</i> type designation
136
     * @see							#TypeDesignationBase()
137
     * @see							#isNotDesignated()
138
     * @see							TaxonNameBase#getTypeDesignations()
139
     */
140
    protected TypeDesignationBase(Reference citation, String citationMicroReference, String originalNameString, boolean notDesignated){
141
        super(citation, citationMicroReference, originalNameString);
142
        this.notDesignated = notDesignated;
143
    }
144

    
145

    
146
// **************** METHODS *************************************/
147

    
148

    
149
    /**
150
     * Returns the {@link TypeDesignationStatusBase type designation status} for <i>this</i> specimen type
151
     * designation. This status describes which of the possible categories of
152
     * types like "holotype", "neotype", "syntype" or "isotype" applies to <i>this</i>
153
     * specimen type designation.
154
     */
155
    public T getTypeStatus(){
156
        return this.typeStatus;
157
    }
158
    /**
159
     * @see  #getTypeStatus()
160
     */
161
    public void setTypeStatus(T typeStatus){
162
        this.typeStatus = typeStatus;
163
    }
164

    
165
//    /* (non-Javadoc)
166
//     * @see eu.etaxonomy.cdm.model.name.ITypeDesignation#getHomotypicalGroup()
167
//     */
168
//    /**
169
//     * Returns the {@link HomotypicalGroup homotypical group} to which all (in <i>this</i>
170
//     * type designation) typified {@link TaxonNameBase taxon names} belong.
171
//     *
172
//     * @see   #getTypifiedNames()
173
//     * @deprecated homotypical group can not be set and always seems to be <code>null</code>.
174
//     * Probably it is a relict of an old version.
175
//     * See also http://dev.e-taxonomy.eu/trac/ticket/2173
176
//     */
177
//    @Deprecated
178
//    public HomotypicalGroup getHomotypicalGroup() {
179
//        return homotypicalGroup;
180
//    }
181

    
182
    /* (non-Javadoc)
183
     * @see eu.etaxonomy.cdm.model.name.ITypeDesignation#getTypifiedNames()
184
     */
185
    /**
186
     * Returns the set of {@link TaxonNameBase taxon names} typified in <i>this</i>
187
     * type designation. This is a subset of the taxon names belonging to the
188
     * corresponding {@link #getHomotypicalGroup() homotypical group}.
189
     */
190
    @Override
191
    public Set<TaxonNameBase> getTypifiedNames() {
192
        return typifiedNames;
193
    }
194

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

    
214
    /**
215
     * @see   #isNotDesignated()
216
     */
217
    public void setNotDesignated(boolean notDesignated) {
218
        this.notDesignated = notDesignated;
219
    }
220

    
221
    /**
222
     * @deprecated for bidirectional use only
223
     */
224
    @Deprecated
225
    protected void addTypifiedName(TaxonNameBase taxonName){
226
        this.typifiedNames.add(taxonName);
227
    }
228

    
229
    /**
230
     * @deprecated for bidirectional use only
231
     */
232
    @Deprecated
233
    protected void removeTypifiedName(TaxonNameBase taxonName){
234
        this.typifiedNames.remove(taxonName);
235
        if (taxonName.getTypeDesignations().contains(this)){
236
            taxonName.removeTypeDesignation(this);
237
        }
238
    }
239

    
240
    public abstract void removeType();
241

    
242
//*********************** CLONE ********************************************************/
243

    
244
    /**
245
     * Clones <i>this</i> type designation. This is a shortcut that enables to create
246
     * a new instance that differs only slightly from <i>this</i> type designation by
247
     * modifying only some of the attributes.<BR>
248
     * CAUTION: the typifiedNames set is not cloned but empty after cloning as the typified
249
     * names is considered to be the not owning part of a bidirectional relationship.
250
     * This may be changed in future.
251
     *
252
     * @throws CloneNotSupportedException
253
     *
254
     * @see eu.etaxonomy.cdm.model.common.ReferencedEntityBase#clone()
255
     * @see java.lang.Object#clone()
256
     */
257
    @Override
258
    public Object clone() throws CloneNotSupportedException {
259
        TypeDesignationBase result = (TypeDesignationBase)super.clone();
260

    
261
        result.typifiedNames = new HashSet<TaxonNameBase>();
262
//		for (TaxonNameBase taxonNameBase : getTypifiedNames()){
263
//			result.typifiedNames.add(taxonNameBase);
264
//		}
265

    
266

    
267
        //no changes to: notDesignated, typeStatus, homotypicalGroup
268
        return result;
269
    }
270
}
(23-23/28)