Project

General

Profile

Download (9.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

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

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

    
71
	@XmlElement(name = "IsNotDesignated")
72
	private boolean notDesignated;
73
	
74
	@XmlElementWrapper(name = "TypifiedNames")
75
	@XmlElement(name = "TypifiedName")
76
	@XmlIDREF
77
	@XmlSchemaType(name = "IDREF")
78
    // Need these references (bidirectional) to fill table TypeDesignationBase_TaxonNameBase
79
	@ManyToMany(fetch = FetchType.LAZY /*, mappedBy="typeDesignations"*/)
80
//	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE, CascadeType.DELETE_ORPHAN})
81
	private Set<TaxonNameBase> typifiedNames = new HashSet<TaxonNameBase>();
82
	
83
	@XmlElement(name = "HomotypicalGroup")
84
	@XmlIDREF
85
	@XmlSchemaType(name = "IDREF")
86
	@ManyToOne(fetch = FetchType.LAZY)
87
	@Cascade(CascadeType.SAVE_UPDATE)
88
	private HomotypicalGroup homotypicalGroup;
89

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

    
96
// **************** CONSTRUCTOR *************************************/
97

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

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

    
147

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

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

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

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

    
211
	/**
212
	 * @see   #isNotDesignated()
213
	 */
214
	public void setNotDesignated(boolean notDesignated) {
215
		this.notDesignated = notDesignated;
216
	}
217
	
218
	/**
219
	 * @deprecated for bidirectional use only
220
	 */
221
	@Deprecated
222
	protected void addTypifiedName(TaxonNameBase taxonName){
223
		this.typifiedNames.add(taxonName);
224
	}
225
	
226
//*********************** CLONE ********************************************************/
227
	
228
	/** 
229
	 * Clones <i>this</i> type designation. This is a shortcut that enables to create
230
	 * a new instance that differs only slightly from <i>this</i> type designation by
231
	 * modifying only some of the attributes.<BR>
232
	 * CAUTION: the typifiedNames set is not cloned but empty after cloning as the typified 
233
	 * names is considered to be the not owning part of a bidirectional relationship.
234
	 * This may be changed in future.
235
	 * 
236
	 * @throws CloneNotSupportedException 
237
	 * 
238
	 * @see eu.etaxonomy.cdm.model.common.ReferencedEntityBase#clone()
239
	 * @see java.lang.Object#clone()
240
	 */
241
	@Override
242
	public Object clone() throws CloneNotSupportedException {
243
		TypeDesignationBase result = (TypeDesignationBase)super.clone();
244
		
245
		result.typifiedNames = new HashSet<TaxonNameBase>();
246
//		for (TaxonNameBase taxonNameBase : getTypifiedNames()){
247
//			result.typifiedNames.add(taxonNameBase);
248
//		}
249

    
250
		
251
		//no changes to: notDesignated, typeStatus, homotypicalGroup
252
		return result;
253
	}	
254
}
(21-21/26)