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 javax.persistence.Entity;
|
13
|
import javax.persistence.FetchType;
|
14
|
import javax.persistence.ManyToOne;
|
15
|
import javax.persistence.Transient;
|
16
|
import javax.xml.bind.annotation.XmlAccessType;
|
17
|
import javax.xml.bind.annotation.XmlAccessorType;
|
18
|
import javax.xml.bind.annotation.XmlElement;
|
19
|
import javax.xml.bind.annotation.XmlIDREF;
|
20
|
import javax.xml.bind.annotation.XmlSchemaType;
|
21
|
import javax.xml.bind.annotation.XmlType;
|
22
|
|
23
|
import org.apache.log4j.Logger;
|
24
|
import org.hibernate.annotations.Cascade;
|
25
|
import org.hibernate.annotations.CascadeType;
|
26
|
import org.hibernate.envers.Audited;
|
27
|
|
28
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
29
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
30
|
import eu.etaxonomy.cdm.validation.Level3;
|
31
|
import eu.etaxonomy.cdm.validation.annotation.BasionymsMustShareEpithetsAndAuthors;
|
32
|
import eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup;
|
33
|
|
34
|
/**
|
35
|
* The class representing a relationship between two {@link TaxonName taxon names} according
|
36
|
* to the {@link NomenclaturalCode nomenclatural code} which governs both of them.
|
37
|
* This includes a {@link NameRelationshipType name relationship type} (for instance "later homonym" or
|
38
|
* "orthographic variant") and the article of the corresponding nomenclatural
|
39
|
* code on which the assignation of the relationship type is based.
|
40
|
* <P>
|
41
|
* This class corresponds partially to: <ul>
|
42
|
* <li> Relationship according to the TDWG ontology
|
43
|
* <li> TaxonRelationship according to the TCS
|
44
|
* </ul>
|
45
|
*
|
46
|
* @author m.doering
|
47
|
* @version 1.0
|
48
|
* @created 08-Nov-2007 13:06:37
|
49
|
*/
|
50
|
@XmlAccessorType(XmlAccessType.FIELD)
|
51
|
@XmlType(name = "NameRelationship", propOrder = {
|
52
|
"relatedFrom",
|
53
|
"relatedTo",
|
54
|
"type",
|
55
|
"ruleConsidered"
|
56
|
})
|
57
|
@Entity
|
58
|
@Audited
|
59
|
@NamesWithHomotypicRelationshipsMustBelongToSameGroup(groups = Level3.class)
|
60
|
@BasionymsMustShareEpithetsAndAuthors(groups = Level3.class)
|
61
|
public class NameRelationship
|
62
|
extends RelationshipBase<TaxonName, TaxonName, NameRelationshipType>
|
63
|
implements Cloneable{
|
64
|
private static final long serialVersionUID = -615987333520172043L;
|
65
|
private static final Logger logger = Logger.getLogger(NameRelationship.class);
|
66
|
|
67
|
//The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in
|
68
|
//the note property.
|
69
|
@XmlElement(name = "RuleConsidered")
|
70
|
private String ruleConsidered;
|
71
|
|
72
|
@XmlElement(name = "RelatedFrom")
|
73
|
@XmlIDREF
|
74
|
@XmlSchemaType(name = "IDREF")
|
75
|
@ManyToOne(fetch=FetchType.LAZY)
|
76
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
77
|
private TaxonName relatedFrom;
|
78
|
|
79
|
@XmlElement(name = "RelatedTo")
|
80
|
@XmlIDREF
|
81
|
@XmlSchemaType(name = "IDREF")
|
82
|
@ManyToOne(fetch=FetchType.LAZY)
|
83
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
84
|
private TaxonName relatedTo;
|
85
|
|
86
|
@XmlElement(name = "Type")
|
87
|
@XmlIDREF
|
88
|
@XmlSchemaType(name = "IDREF")
|
89
|
@ManyToOne(fetch = FetchType.LAZY)
|
90
|
private NameRelationshipType type;
|
91
|
|
92
|
/**
|
93
|
* @deprecated for hibernate use only, don't use
|
94
|
*/
|
95
|
@Deprecated
|
96
|
private NameRelationship(){
|
97
|
super();
|
98
|
}
|
99
|
|
100
|
|
101
|
// ************* CONSTRUCTORS *************/
|
102
|
/**
|
103
|
* Class constructor: creates a new name relationship instance with no
|
104
|
* reference and adds it to the respective
|
105
|
* {@link TaxonName#getNameRelations() taxon name relation sets} of both involved names.
|
106
|
*
|
107
|
* @param toName the taxon name to be set as target for the new name relationship
|
108
|
* @param fromName the taxon name to be set as source for the new name relationship
|
109
|
* @param type the relationship type to be assigned to the new name relationship
|
110
|
* @param ruleConsidered the string indicating the article of the nomenclatural code for the new name relationship
|
111
|
* @see #NameRelationship(TaxonName, TaxonName, NameRelationshipType, Reference, String, String)
|
112
|
* @see TaxonName#addNameRelationship(NameRelationship)
|
113
|
* @see TaxonName#addRelationshipFromName(TaxonName, NameRelationshipType, String)
|
114
|
* @see TaxonName#addRelationshipToName(TaxonName, NameRelationshipType, String)
|
115
|
*/
|
116
|
protected NameRelationship(TaxonName toName, TaxonName fromName, NameRelationshipType type, String ruleConsidered) {
|
117
|
this(toName, fromName, type, null, null, ruleConsidered);
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Class constructor: creates a new name relationship instance including
|
122
|
* its {@link eu.etaxonomy.cdm.model.reference.Reference reference source} and adds it to the respective
|
123
|
*{@link TaxonName#getNameRelations() taxon name relation sets} of both involved names.
|
124
|
*
|
125
|
* @param toName the taxon name to be set as target for the new name relationship
|
126
|
* @param fromName the taxon name to be set as source for the new name relationship
|
127
|
* @param type the relationship type to be assigned to the new name relationship
|
128
|
* @param citation the reference source for the new name relationship
|
129
|
* @param citationMicroReference the string with the details describing the exact localisation within the reference
|
130
|
* @param ruleConsidered the string indicating the article of the nomenclatural code justifying the new name relationship
|
131
|
* @see #NameRelationship(TaxonName, TaxonName, NameRelationshipType, String)
|
132
|
* @see TaxonName#addNameRelationship(NameRelationship)
|
133
|
* @see TaxonName#addRelationshipFromName(TaxonName, NameRelationshipType, String)
|
134
|
* @see TaxonName#addRelationshipToName(TaxonName, NameRelationshipType, String)
|
135
|
*/
|
136
|
protected NameRelationship(TaxonName toName, TaxonName fromName, NameRelationshipType type, Reference citation, String citationMicroReference, String ruleConsidered) {
|
137
|
super(fromName, toName, type, citation, citationMicroReference);
|
138
|
this.setRuleConsidered(ruleConsidered);
|
139
|
}
|
140
|
|
141
|
//********* METHODS **************************************/
|
142
|
|
143
|
/**
|
144
|
* Returns the {@link TaxonName taxon name} that plays the source role
|
145
|
* in <i>this</i> taxon name relationship.
|
146
|
*
|
147
|
* @see #getToName()
|
148
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
|
149
|
*/
|
150
|
@Transient
|
151
|
public TaxonName getFromName(){
|
152
|
return this.getRelatedFrom();
|
153
|
}
|
154
|
|
155
|
/**
|
156
|
* @see #getFromName()
|
157
|
*/
|
158
|
void setFromName(TaxonName fromName){
|
159
|
this.setRelatedFrom(fromName);
|
160
|
}
|
161
|
|
162
|
/**
|
163
|
* Returns the {@link TaxonName taxon name} that plays the target role
|
164
|
* in <i>this</i> taxon name relationship.
|
165
|
*
|
166
|
* @see #getFromName()
|
167
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
|
168
|
*/
|
169
|
@Transient
|
170
|
public TaxonName getToName(){
|
171
|
return this.getRelatedTo();
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* @see #getToName()
|
176
|
*/
|
177
|
void setToName(TaxonName toName){
|
178
|
this.setRelatedTo(toName);
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
* Returns the nomenclatural code rule considered (that is the
|
183
|
* article/note/recommendation in the nomenclatural code ruling
|
184
|
* the taxon name(s) of this nomenclatural status).
|
185
|
* The considered rule gives the reason why the
|
186
|
* {@link NomenclaturalStatusType nomenclatural status type} has been
|
187
|
* assigned to the {@link TaxonName taxon name(s)}.
|
188
|
*/
|
189
|
public String getRuleConsidered(){
|
190
|
return this.ruleConsidered;
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* @see #getRuleConsidered()
|
195
|
*/
|
196
|
public void setRuleConsidered(String ruleConsidered){
|
197
|
this.ruleConsidered = ruleConsidered;
|
198
|
}
|
199
|
|
200
|
// for extra-package access to relatedFrom use getFromName instead
|
201
|
@Override
|
202
|
protected TaxonName getRelatedFrom() {
|
203
|
return relatedFrom;
|
204
|
}
|
205
|
|
206
|
// for extra-package access to relatedFrom use getToName instead
|
207
|
@Override
|
208
|
protected TaxonName getRelatedTo() {
|
209
|
return relatedTo;
|
210
|
}
|
211
|
|
212
|
@Override
|
213
|
public NameRelationshipType getType() {
|
214
|
return type;
|
215
|
}
|
216
|
|
217
|
@Override
|
218
|
protected void setRelatedFrom(TaxonName relatedFrom) {
|
219
|
this.relatedFrom = relatedFrom;
|
220
|
}
|
221
|
|
222
|
@Override
|
223
|
protected void setRelatedTo(TaxonName relatedTo) {
|
224
|
this.relatedTo = relatedTo;
|
225
|
}
|
226
|
|
227
|
@Override
|
228
|
public void setType(NameRelationshipType type) {
|
229
|
this.type = type;
|
230
|
}
|
231
|
|
232
|
|
233
|
//*********************** CLONE ********************************************************/
|
234
|
|
235
|
/**
|
236
|
* Clones <i>this</i> name relationship. This is a shortcut that enables to create
|
237
|
* a new instance that differs only slightly from <i>this</i> name relationship by
|
238
|
* modifying only some of the attributes.<BR>
|
239
|
* CAUTION: Cloning a relationship will not add the relationship to the according
|
240
|
* {@link #relatedFrom} and {@link #relatedTo} objects. The method is meant to be used
|
241
|
* mainly for internal purposes (e.g. used within {@link TaxonName#clone()}
|
242
|
*
|
243
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
|
244
|
* @see java.lang.Object#clone()
|
245
|
*/
|
246
|
@Override
|
247
|
public Object clone() {
|
248
|
NameRelationship result;
|
249
|
try {
|
250
|
result = (NameRelationship)super.clone();
|
251
|
//no changes to: relatedFrom, relatedTo, type
|
252
|
return result;
|
253
|
} catch (CloneNotSupportedException e) {
|
254
|
logger.warn("Object does not implement cloneable");
|
255
|
e.printStackTrace();
|
256
|
return null;
|
257
|
}
|
258
|
}
|
259
|
}
|