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.envers.Audited;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
|
29
|
/**
|
30
|
* The class representing a hybrid relationship between one of the {@link BotanicalName parents}
|
31
|
* of a hybrid taxon name and the hybrid taxon name itself. A hybrid taxon name
|
32
|
* is a {@link BotanicalName botanical taxon name} assigned to a hybrid plant following
|
33
|
* the {@link NomenclaturalCode#ICBN() ICBN} (Appendix I). A hybrid taxon name must have one
|
34
|
* of the hybrid flags set. The hybrid relationship includes a {@link HybridRelationshipType hybrid relationship type}
|
35
|
* (for instance "first parent" or "female parent") and the article of the ICBN
|
36
|
* on which the hybrid taxon name relies.
|
37
|
* <P>
|
38
|
* This class corresponds partially to: <ul>
|
39
|
* <li> Relationship according to the TDWG ontology
|
40
|
* <li> TaxonRelationship according to the TCS
|
41
|
* </ul>
|
42
|
*
|
43
|
* @author m.doering
|
44
|
* @version 1.0
|
45
|
* @since 08-Nov-2007 13:06:26
|
46
|
*/
|
47
|
@XmlAccessorType(XmlAccessType.FIELD)
|
48
|
@XmlType(name = "HybridRelationship", propOrder = {
|
49
|
"relatedFrom",
|
50
|
"relatedTo",
|
51
|
"type",
|
52
|
"ruleConsidered"
|
53
|
})
|
54
|
@Entity
|
55
|
@Audited
|
56
|
public class HybridRelationship
|
57
|
extends RelationshipBase<INonViralName, INonViralName, HybridRelationshipType>
|
58
|
implements Comparable<HybridRelationship>{
|
59
|
|
60
|
private static final long serialVersionUID = -78515930138896939L;
|
61
|
private static final Logger logger = Logger.getLogger(HybridRelationship.class);
|
62
|
|
63
|
//The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in
|
64
|
//the note property.
|
65
|
@XmlElement(name = "RuleConsidered")
|
66
|
private String ruleConsidered;
|
67
|
|
68
|
@XmlElement(name = "RelatedFrom")
|
69
|
@XmlIDREF
|
70
|
@XmlSchemaType(name = "IDREF")
|
71
|
@ManyToOne(fetch=FetchType.LAZY)
|
72
|
// @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
73
|
private TaxonName relatedFrom;
|
74
|
|
75
|
@XmlElement(name = "RelatedTo")
|
76
|
@XmlIDREF
|
77
|
@XmlSchemaType(name = "IDREF")
|
78
|
@ManyToOne(fetch=FetchType.LAZY)
|
79
|
// @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
80
|
private TaxonName relatedTo;
|
81
|
|
82
|
@XmlElement(name = "Type")
|
83
|
@XmlIDREF
|
84
|
@XmlSchemaType(name = "IDREF")
|
85
|
@ManyToOne(fetch=FetchType.LAZY)
|
86
|
private HybridRelationshipType type;
|
87
|
|
88
|
/**
|
89
|
* @deprecated for hibernate use only, don't use
|
90
|
*/
|
91
|
@Deprecated
|
92
|
private HybridRelationship(){
|
93
|
super();
|
94
|
}
|
95
|
|
96
|
|
97
|
// ************* CONSTRUCTORS *************/
|
98
|
/**
|
99
|
* Class constructor: creates a new hybrid relationship instance with no
|
100
|
* reference and adds it to the respective
|
101
|
* {@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
|
102
|
*
|
103
|
* @param toName the taxon name to be set as target for the new hybrid relationship
|
104
|
* @param fromName the taxon name to be set as source for the new hybrid relationship
|
105
|
* @param type the relationship type to be assigned to the new hybrid relationship
|
106
|
* @param ruleConsidered the string indicating the article of the ICBN for the hybrid taxon name
|
107
|
* @see #HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, Reference, String, String)
|
108
|
* @see TaxonName#addHybridRelationship(HybridRelationship)
|
109
|
*/
|
110
|
protected HybridRelationship(INonViralName hybridName, INonViralName parentName, HybridRelationshipType type, String ruleConsidered) {
|
111
|
this(hybridName, parentName, type, null, null, ruleConsidered);
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Class constructor: creates a new hybrid relationship instance including
|
116
|
* its {@link eu.etaxonomy.cdm.model.reference.Reference reference source} and adds it to the respective
|
117
|
*{@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
|
118
|
*
|
119
|
* @param toName the taxon name to be set as target for the new hybrid relationship
|
120
|
* @param fromName the taxon name to be set as source for the new hybrid relationship
|
121
|
* @param type the relationship type to be assigned to the new hybrid relationship
|
122
|
* @param citation the reference source for the new hybrid relationship
|
123
|
* @param citationMicroReference the string with the details describing the exact localisation within the reference
|
124
|
* @param ruleConsidered the string indicating the article of the ICBN for the hybrid taxon name
|
125
|
* @see #HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, String)
|
126
|
* @see TaxonName#addHybridRelationship(HybridRelationship)
|
127
|
*/
|
128
|
protected HybridRelationship(INonViralName hybridName, INonViralName parentName, HybridRelationshipType type, Reference citation, String citationMicroReference, String ruleConsidered) {
|
129
|
super(parentName, hybridName, type, citation, citationMicroReference);
|
130
|
this.setRuleConsidered(ruleConsidered);
|
131
|
}
|
132
|
|
133
|
//********* METHODS **************************************/
|
134
|
|
135
|
/**
|
136
|
* Returns the {@link BotanicalName botanical taxon name} that plays the parent role
|
137
|
* in <i>this</i> hybrid relationship.
|
138
|
*
|
139
|
* @see #getHybridName()
|
140
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
|
141
|
*/
|
142
|
@Transient
|
143
|
public TaxonName getParentName(){
|
144
|
return this.getRelatedFrom();
|
145
|
}
|
146
|
/**
|
147
|
* @see #getParentName()
|
148
|
*/
|
149
|
public void setParentName(INonViralName parentName){
|
150
|
this.setRelatedFrom(parentName);
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* Returns the {@link BotanicalName botanical taxon name} that plays the child role
|
155
|
* (the child is actually the hybrid taxon name) in <i>this</i> hybrid relationship.
|
156
|
*
|
157
|
* @see #getParentName()
|
158
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
|
159
|
*/
|
160
|
@Transient
|
161
|
public TaxonName getHybridName(){
|
162
|
return this.getRelatedTo();
|
163
|
}
|
164
|
/**
|
165
|
* @see #getHybridName()
|
166
|
*/
|
167
|
public void setHybridName(INonViralName hybridName){
|
168
|
this.setRelatedTo(hybridName);
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* Returns the ICBN rule considered (that is the
|
173
|
* article/note/recommendation in the nomenclatural code) for building
|
174
|
* the string representing the (child) hybrid {@link BotanicalName taxon name}
|
175
|
* within <i>this</i> hybrid relationship.
|
176
|
*/
|
177
|
public String getRuleConsidered(){
|
178
|
return this.ruleConsidered;
|
179
|
}
|
180
|
/**
|
181
|
* @see #getRuleConsidered()
|
182
|
*/
|
183
|
public void setRuleConsidered(String ruleConsidered){
|
184
|
this.ruleConsidered = ruleConsidered;
|
185
|
}
|
186
|
|
187
|
@Override
|
188
|
protected TaxonName getRelatedFrom() {
|
189
|
return relatedFrom;
|
190
|
}
|
191
|
|
192
|
@Override
|
193
|
protected TaxonName getRelatedTo() {
|
194
|
return relatedTo;
|
195
|
}
|
196
|
|
197
|
@Override
|
198
|
public HybridRelationshipType getType() {
|
199
|
return type;
|
200
|
}
|
201
|
|
202
|
@Override
|
203
|
protected void setRelatedFrom(INonViralName relatedFrom) {
|
204
|
this.relatedFrom = TaxonName.castAndDeproxy(relatedFrom);
|
205
|
}
|
206
|
|
207
|
@Override
|
208
|
protected void setRelatedTo(INonViralName relatedTo) {
|
209
|
this.relatedTo = TaxonName.castAndDeproxy(relatedTo);
|
210
|
}
|
211
|
|
212
|
@Override
|
213
|
public void setType(HybridRelationshipType type) {
|
214
|
this.type = type;
|
215
|
}
|
216
|
|
217
|
// ************************ compareTo *************************************************
|
218
|
|
219
|
@Override
|
220
|
public int compareTo(HybridRelationship rel2) {
|
221
|
HybridRelationshipType type1 = this.getType();
|
222
|
HybridRelationshipType type2 = rel2.getType();
|
223
|
int compareType = type1.compareTo(type2);
|
224
|
if (compareType != 0){
|
225
|
return compareType;
|
226
|
}else{
|
227
|
TaxonName related1 = this.getRelatedFrom();
|
228
|
TaxonName related2 = rel2.getRelatedFrom();
|
229
|
if (related1 != related2){
|
230
|
related1 = this.getRelatedTo();
|
231
|
related2 = rel2.getRelatedTo();
|
232
|
}
|
233
|
if (related1.equals(related2)){
|
234
|
return 0;
|
235
|
}
|
236
|
|
237
|
String title1 = related1.getTitleCache();
|
238
|
String title2 = related2.getTitleCache();
|
239
|
return title1.compareTo(title2);
|
240
|
}
|
241
|
}
|
242
|
|
243
|
|
244
|
//*********************** CLONE ********************************************************/
|
245
|
|
246
|
/**
|
247
|
* Clones <i>this</i> hybrid relationship. This is a shortcut that enables to create
|
248
|
* a new instance that differs only slightly from <i>this</i> hybrid relationship by
|
249
|
* modifying only some of the attributes.<BR>
|
250
|
* CAUTION: Cloning a relationship will not add the relationship to the according
|
251
|
* {@link #relatedFrom} and {@link #relatedTo} objects. The method is meant to be used
|
252
|
* mainly for internal purposes (e.g. used within {@link TaxonName#clone()}
|
253
|
*
|
254
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
|
255
|
* @see java.lang.Object#clone()
|
256
|
*/
|
257
|
@Override
|
258
|
public Object clone() {
|
259
|
HybridRelationship result;
|
260
|
try {
|
261
|
result = (HybridRelationship)super.clone();
|
262
|
//no changes to: relatedFrom, relatedTo, type
|
263
|
return result;
|
264
|
} catch (CloneNotSupportedException e) {
|
265
|
logger.warn("Object does not implement cloneable");
|
266
|
e.printStackTrace();
|
267
|
return null;
|
268
|
}
|
269
|
}
|
270
|
|
271
|
}
|