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.ReferenceBase;
|
30
|
import eu.etaxonomy.cdm.validation.Level3;
|
31
|
import eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup;
|
32
|
|
33
|
/**
|
34
|
* The class representing a relationship between two {@link TaxonNameBase taxon names} according
|
35
|
* to the {@link NomenclaturalCode nomenclatural code} which governs both of them.
|
36
|
* This includes a {@link NameRelationshipType name relationship type} (for instance "later homonym" or
|
37
|
* "orthographic variant") and the article of the corresponding nomenclatural
|
38
|
* code on which the assignation of the relationship type is based.
|
39
|
* <P>
|
40
|
* This class corresponds partially to: <ul>
|
41
|
* <li> Relationship according to the TDWG ontology
|
42
|
* <li> TaxonRelationship according to the TCS
|
43
|
* </ul>
|
44
|
*
|
45
|
* @author m.doering
|
46
|
* @version 1.0
|
47
|
* @created 08-Nov-2007 13:06:37
|
48
|
*/
|
49
|
@XmlAccessorType(XmlAccessType.FIELD)
|
50
|
@XmlType(name = "NameRelationship", propOrder = {
|
51
|
"relatedFrom",
|
52
|
"relatedTo",
|
53
|
"type",
|
54
|
"ruleConsidered"
|
55
|
})
|
56
|
@Entity
|
57
|
@Audited
|
58
|
@NamesWithHomotypicRelationshipsMustBelongToSameGroup(groups = {Level3.class})
|
59
|
public class NameRelationship extends RelationshipBase<TaxonNameBase, TaxonNameBase, NameRelationshipType> {
|
60
|
|
61
|
static Logger logger = Logger.getLogger(NameRelationship.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})
|
73
|
private TaxonNameBase relatedFrom;
|
74
|
|
75
|
@XmlElement(name = "RelatedTo")
|
76
|
@XmlIDREF
|
77
|
@XmlSchemaType(name = "IDREF")
|
78
|
@ManyToOne(fetch=FetchType.LAZY)
|
79
|
@Cascade(CascadeType.SAVE_UPDATE)
|
80
|
private TaxonNameBase relatedTo;
|
81
|
|
82
|
@XmlElement(name = "Type")
|
83
|
@XmlIDREF
|
84
|
@XmlSchemaType(name = "IDREF")
|
85
|
@ManyToOne(fetch = FetchType.LAZY)
|
86
|
private NameRelationshipType type;
|
87
|
|
88
|
//for hibernate, don't use
|
89
|
@Deprecated
|
90
|
private NameRelationship(){
|
91
|
super();
|
92
|
}
|
93
|
|
94
|
|
95
|
// ************* CONSTRUCTORS *************/
|
96
|
/**
|
97
|
* Class constructor: creates a new name relationship instance with no
|
98
|
* reference and adds it to the respective
|
99
|
* {@link TaxonNameBase#getNameRelations() taxon name relation sets} of both involved names.
|
100
|
*
|
101
|
* @param toName the taxon name to be set as target for the new name relationship
|
102
|
* @param fromName the taxon name to be set as source for the new name relationship
|
103
|
* @param type the relationship type to be assigned to the new name relationship
|
104
|
* @param ruleConsidered the string indicating the article of the nomenclatural code for the new name relationship
|
105
|
* @see #NameRelationship(TaxonNameBase, TaxonNameBase, NameRelationshipType, ReferenceBase, String, String)
|
106
|
* @see TaxonNameBase#addNameRelationship(NameRelationship)
|
107
|
* @see TaxonNameBase#addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
|
108
|
* @see TaxonNameBase#addRelationshipToName(TaxonNameBase, NameRelationshipType, String)
|
109
|
*/
|
110
|
protected NameRelationship(TaxonNameBase toName, TaxonNameBase fromName, NameRelationshipType type, String ruleConsidered) {
|
111
|
this(toName, fromName, type, null, null, ruleConsidered);
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Class constructor: creates a new name relationship instance including
|
116
|
* its {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference source} and adds it to the respective
|
117
|
*{@link TaxonNameBase#getNameRelations() taxon name relation sets} of both involved names.
|
118
|
*
|
119
|
* @param toName the taxon name to be set as target for the new name relationship
|
120
|
* @param fromName the taxon name to be set as source for the new name relationship
|
121
|
* @param type the relationship type to be assigned to the new name relationship
|
122
|
* @param citation the reference source for the new name 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 nomenclatural code justifying the new name relationship
|
125
|
* @see #NameRelationship(TaxonNameBase, TaxonNameBase, NameRelationshipType, String)
|
126
|
* @see TaxonNameBase#addNameRelationship(NameRelationship)
|
127
|
* @see TaxonNameBase#addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
|
128
|
* @see TaxonNameBase#addRelationshipToName(TaxonNameBase, NameRelationshipType, String)
|
129
|
*/
|
130
|
protected NameRelationship(TaxonNameBase toName, TaxonNameBase fromName, NameRelationshipType type, ReferenceBase citation, String citationMicroReference, String ruleConsidered) {
|
131
|
super(fromName, toName, type, citation, citationMicroReference);
|
132
|
this.setRuleConsidered(ruleConsidered);
|
133
|
}
|
134
|
|
135
|
//********* METHODS **************************************/
|
136
|
|
137
|
/**
|
138
|
* Returns the {@link TaxonNameBase taxon name} that plays the source role
|
139
|
* in <i>this</i> taxon name relationship.
|
140
|
*
|
141
|
* @see #getToName()
|
142
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
|
143
|
*/
|
144
|
@Transient
|
145
|
public TaxonNameBase getFromName(){
|
146
|
return this.getRelatedFrom();
|
147
|
}
|
148
|
|
149
|
/**
|
150
|
* @see #getFromName()
|
151
|
*/
|
152
|
void setFromName(TaxonNameBase fromName){
|
153
|
this.setRelatedFrom(fromName);
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Returns the {@link TaxonNameBase taxon name} that plays the target role
|
158
|
* in <i>this</i> taxon name relationship.
|
159
|
*
|
160
|
* @see #getFromName()
|
161
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
|
162
|
*/
|
163
|
@Transient
|
164
|
public TaxonNameBase getToName(){
|
165
|
return this.getRelatedTo();
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* @see #getToName()
|
170
|
*/
|
171
|
void setToName(TaxonNameBase toName){
|
172
|
this.setRelatedTo(toName);
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* Returns the nomenclatural code rule considered (that is the
|
177
|
* article/note/recommendation in the nomenclatural code ruling
|
178
|
* the taxon name(s) of this nomenclatural status).
|
179
|
* The considered rule gives the reason why the
|
180
|
* {@link NomenclaturalStatusType nomenclatural status type} has been
|
181
|
* assigned to the {@link TaxonNameBase taxon name(s)}.
|
182
|
*/
|
183
|
public String getRuleConsidered(){
|
184
|
return this.ruleConsidered;
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* @see #getRuleConsidered()
|
189
|
*/
|
190
|
public void setRuleConsidered(String ruleConsidered){
|
191
|
this.ruleConsidered = ruleConsidered;
|
192
|
}
|
193
|
|
194
|
protected TaxonNameBase getRelatedFrom() {
|
195
|
return relatedFrom;
|
196
|
}
|
197
|
|
198
|
protected TaxonNameBase getRelatedTo() {
|
199
|
return relatedTo;
|
200
|
}
|
201
|
|
202
|
public NameRelationshipType getType() {
|
203
|
return type;
|
204
|
}
|
205
|
|
206
|
protected void setRelatedFrom(TaxonNameBase relatedFrom) {
|
207
|
if (relatedFrom == null){
|
208
|
this.deletedObjects.add(this.relatedFrom);
|
209
|
}
|
210
|
this.relatedFrom = relatedFrom;
|
211
|
}
|
212
|
|
213
|
protected void setRelatedTo(TaxonNameBase relatedTo) {
|
214
|
if (relatedTo == null){
|
215
|
this.deletedObjects.add(this.relatedTo);
|
216
|
}
|
217
|
this.relatedTo = relatedTo;
|
218
|
}
|
219
|
|
220
|
public void setType(NameRelationshipType type) {
|
221
|
this.type = type;
|
222
|
}
|
223
|
}
|