Project

General

Profile

Download (12.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 javax.persistence.Entity;
13
import javax.persistence.FetchType;
14
import javax.persistence.ManyToOne;
15
import javax.xml.bind.annotation.XmlAccessType;
16
import javax.xml.bind.annotation.XmlAccessorType;
17
import javax.xml.bind.annotation.XmlElement;
18
import javax.xml.bind.annotation.XmlIDREF;
19
import javax.xml.bind.annotation.XmlSchemaType;
20
import javax.xml.bind.annotation.XmlType;
21

    
22
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
23
import org.hibernate.envers.Audited;
24

    
25
import eu.etaxonomy.cdm.model.common.RelationshipBase;
26
import eu.etaxonomy.cdm.model.reference.NamedSource;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.validation.Level3;
29
import eu.etaxonomy.cdm.validation.annotation.BasionymsMustShareEpithetsAndAuthors;
30
import eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup;
31

    
32
/**
33
 * The class representing a relationship between two {@link TaxonName taxon names} according
34
 * to the {@link NomenclaturalCode nomenclatural code} which governs both of them.
35
 * This includes a {@link NameRelationshipType name relationship type} (for instance "later homonym" or
36
 * "orthographic variant") and the article of the corresponding nomenclatural
37
 * code on which the assignation of the relationship type is based.
38
 * <P>
39
 * This class corresponds partially to: <ul>
40
 * <li> Relationship according to the TDWG ontology
41
 * <li> TaxonRelationship according to the TCS
42
 * </ul>
43
 *
44
 * @author m.doering
45
 * @since 08-Nov-2007 13:06:37
46
 */
47
@XmlAccessorType(XmlAccessType.FIELD)
48
@XmlType(name = "NameRelationship", propOrder = {
49
	"relatedFrom",
50
	"relatedTo",
51
	"type",
52
    "ruleConsidered"
53
})
54
@Entity
55
@Audited
56
@NamesWithHomotypicRelationshipsMustBelongToSameGroup(groups = Level3.class)
57
@BasionymsMustShareEpithetsAndAuthors(groups = Level3.class)
58
public class NameRelationship
59
            extends RelationshipBase<TaxonName, TaxonName, NameRelationshipType>
60
            implements IRuleConsidered{
61

    
62
	private static final long serialVersionUID = -615987333520172043L;
63
	private static final Logger logger = LogManager.getLogger(NameRelationship.class);
64

    
65
//    //The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in
66
//	//the note property.
67
//    @XmlElement(name = "RuleConsidered")
68
//	private String ruleConsidered;
69

    
70
    private RuleConsidered 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
     * @param codeEdition           the edition of the nomenclatural code where the <code>ruleConsidered</code> has been published.
112
	 * @see						#NameRelationship(TaxonName, TaxonName, NameRelationshipType, Reference, String, String)
113
	 * @see						TaxonName#addNameRelationship(NameRelationship)
114
	 * @see						TaxonName#addRelationshipFromName(TaxonName, NameRelationshipType, String)
115
	 * @see						TaxonName#addRelationshipToName(TaxonName, NameRelationshipType, String)
116
	 */
117
	protected NameRelationship(TaxonName toName, TaxonName fromName, NameRelationshipType type, String ruleConsidered, NomenclaturalCodeEdition codeEdition) {
118
		this(toName, fromName, type, null, null, ruleConsidered, codeEdition);
119
	}
120

    
121
	/**
122
	 * Class constructor: creates a new name relationship instance including
123
	 * its {@link  eu.etaxonomy.cdm.model.reference.Reference reference source} and adds it to the respective
124
	 *{@link TaxonName#getNameRelations() taxon name relation sets} of both involved names.
125
	 *
126
	 * @param toName				the taxon name to be set as target for the new name relationship
127
	 * @param fromName				the taxon name to be set as source for the new name relationship
128
	 * @param type					the relationship type to be assigned to the new name relationship
129
	 * @param citation				the reference source for the new name relationship
130
	 * @param citationMicroReference	the string with the details describing the exact localisation within the reference
131
	 * @param ruleConsidered		the string indicating the article of the nomenclatural code justifying the new name relationship
132
	 * @param codeEdition           the edition of the nomenclatural code where the <code>ruleConsidered</code> has been published.
133
	 * @see							#NameRelationship(TaxonName, TaxonName, NameRelationshipType, String)
134
	 * @see							TaxonName#addNameRelationship(NameRelationship)
135
	 * @see							TaxonName#addRelationshipFromName(TaxonName, NameRelationshipType, String)
136
	 * @see							TaxonName#addRelationshipToName(TaxonName, NameRelationshipType, String)
137
	 */
138
	protected NameRelationship(TaxonName  toName, TaxonName fromName, NameRelationshipType type, Reference citation, String citationMicroReference, String ruleConsidered, NomenclaturalCodeEdition codeEdition) {
139
		super(fromName, toName, type, citation, citationMicroReference);
140
		this.setRuleConsidered(ruleConsidered);
141
		this.setCodeEdition(codeEdition);
142
	}
143

    
144
	/**
145
     * Class constructor: creates a new name relationship instance including
146
     * its {@link  eu.etaxonomy.cdm.model.description.DescriptionElementSource reference source} and adds it to the respective
147
     *{@link TaxonName#getNameRelations() taxon name relation sets} of both involved names.
148
     *
149
     * @param toName                the taxon name to be set as target for the new name relationship
150
     * @param fromName              the taxon name to be set as source for the new name relationship
151
     * @param type                  the relationship type to be assigned to the new name relationship
152
     * @param source                the source for the new name relationship
153
     * @param ruleConsidered        the string indicating the article of the nomenclatural code justifying the new name relationship
154
     * @param codeEdition           the edition of the nomenclatural code where the <code>ruleConsidered</code> has been published.
155
     * @see                         #NameRelationship(TaxonName, TaxonName, NameRelationshipType, String)
156
     * @see                         TaxonName#addNameRelationship(NameRelationship)
157
     * @see                         TaxonName#addRelationshipFromName(TaxonName, NameRelationshipType, String)
158
     * @see                         TaxonName#addRelationshipToName(TaxonName, NameRelationshipType, String)
159
     */
160
    protected NameRelationship(TaxonName  toName, TaxonName fromName, NameRelationshipType type, NamedSource source, String ruleConsidered, NomenclaturalCodeEdition codeEdition) {
161
        super(fromName, toName, type, source);
162
        this.setRuleConsidered(ruleConsidered);
163
        this.setCodeEdition(codeEdition);
164
    }
165

    
166

    
167
	//********* METHODS **************************************/
168

    
169
	/**
170
	 * Returns the {@link TaxonName taxon name} that plays the source role
171
	 * in <i>this</i> taxon name relationship.
172
	 *
173
	 * @see   #getToName()
174
	 * @see   eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
175
	 */
176
	public TaxonName getFromName(){
177
		return this.getRelatedFrom();
178
	}
179

    
180
	/**
181
	 * @see  #getFromName()
182
	 */
183
	void setFromName(TaxonName fromName){
184
		this.setRelatedFrom(fromName);
185
	}
186

    
187
	/**
188
	 * Returns the {@link TaxonName taxon name} that plays the target role
189
	 * in <i>this</i> taxon name relationship.
190
	 *
191
	 * @see   #getFromName()
192
	 * @see   eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
193
	 */
194
	public TaxonName getToName(){
195
		return this.getRelatedTo();
196
	}
197

    
198
	/**
199
	 * @see  #getToName()
200
	 */
201
	void setToName(TaxonName toName){
202
		this.setRelatedTo(toName);
203
	}
204

    
205

    
206
//	public String getRuleConsidered(){
207
//		return this.ruleConsidered;
208
//	}
209
//
210
//	/**
211
//	 * @see  #getRuleConsidered()
212
//	 */
213
//	public void setRuleConsidered(String ruleConsidered){
214
//		this.ruleConsidered = ruleConsidered;
215
//	}
216
//
217
//	/**
218
//     * The {@link NomenclaturalCodeEdition code edition} for the {@link #getRuleConsidered() rule considered}.
219
//	 */
220
//	public NomenclaturalCodeEdition getCodeEdition() {
221
//        return codeEdition;
222
//    }
223
//    public void setCodeEdition(NomenclaturalCodeEdition codeEdition) {
224
//        this.codeEdition = codeEdition;
225
//    }
226

    
227
	/**
228
     * Returns the nomenclatural code rule considered (that is the
229
     * article/note/recommendation in the nomenclatural code ruling
230
     * the  taxon name(s) of this nomenclatural status).
231
     * The considered rule gives the reason why the
232
     * {@link NameRelationshipType name relationship type} has been
233
     * assigned to this name relation.
234
     */
235
    @Override
236
    public String getRuleConsidered(){
237
        return this.ruleConsidered().getText();
238
    }
239
    /**
240
     * @see  #getRuleConsidered()
241
     */
242
    @Override
243
    public void setRuleConsidered(String ruleConsidered){
244
        this.ruleConsidered().setText(ruleConsidered);
245
    }
246
    /**
247
     * The {@link NomenclaturalCodeEdition code edition} for the {@link #getRuleConsidered() rule considered}.
248
     */
249
    @Override
250
    public NomenclaturalCodeEdition getCodeEdition() {
251
        return ruleConsidered().getCodeEdition();
252
    }
253
    @Override
254
    public void setCodeEdition(NomenclaturalCodeEdition codeEdition) {
255
        ruleConsidered().setCodeEdition(codeEdition);
256
    }
257
    private RuleConsidered ruleConsidered(){
258
        if(this.ruleConsidered==null){
259
            ruleConsidered = new RuleConsidered();
260
        }
261
        return ruleConsidered;
262
    }
263

    
264
    // for extra-package access to relatedFrom use getFromName instead
265
	@Override
266
    protected TaxonName getRelatedFrom() {
267
		return relatedFrom;
268
	}
269

    
270
    // for extra-package access to relatedFrom use getToName instead
271
	@Override
272
    protected TaxonName getRelatedTo() {
273
		return relatedTo;
274
	}
275

    
276
	@Override
277
    public NameRelationshipType getType() {
278
		return type;
279
	}
280

    
281
	@Override
282
    protected void setRelatedFrom(TaxonName relatedFrom) {
283
		this.relatedFrom = relatedFrom;
284
	}
285

    
286
	@Override
287
    protected void setRelatedTo(TaxonName relatedTo) {
288
		this.relatedTo = relatedTo;
289
	}
290

    
291
	@Override
292
    public void setType(NameRelationshipType type) {
293
		this.type = type;
294
	}
295

    
296

    
297
//*********************** CLONE ********************************************************/
298

    
299
	/**
300
	 * Clones <i>this</i> name relationship. This is a shortcut that enables to create
301
	 * a new instance that differs only slightly from <i>this</i> name relationship by
302
	 * modifying only some of the attributes.<BR>
303
	 * CAUTION: Cloning a relationship will not add the relationship to the according
304
	 * {@link #relatedFrom} and {@link #relatedTo} objects. The method is meant to be used
305
	 * mainly for internal purposes (e.g. used within {@link TaxonName#clone()}
306
	 *
307
	 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
308
	 * @see java.lang.Object#clone()
309
	 */
310
	@Override
311
	public NameRelationship clone() {
312
		NameRelationship result;
313
		try {
314
			result = (NameRelationship)super.clone();
315
            result.ruleConsidered = this.ruleConsidered == null? null : this.ruleConsidered.clone();
316
			//no changes to: relatedFrom, relatedTo, type
317
			return result;
318
		} catch (CloneNotSupportedException e) {
319
			logger.warn("Object does not implement cloneable");
320
			e.printStackTrace();
321
			return null;
322
		}
323
	}
324
}
(16-16/39)