Project

General

Profile

Download (8.77 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.log4j.Logger;
23
import org.hibernate.envers.Audited;
24

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

    
31
/**
32
 * The class representing a relationship between two {@link TaxonName taxon names} according
33
 * to the {@link NomenclaturalCode nomenclatural code} which governs both of them.
34
 * This includes a {@link NameRelationshipType name relationship type} (for instance "later homonym" or
35
 * "orthographic variant") and the article of the corresponding nomenclatural
36
 * code on which the assignation of the relationship type is based.
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
 * @created 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
	private static final long serialVersionUID = -615987333520172043L;
61
	private static final 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,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 NameRelationshipType type;
87

    
88
    /**
89
	 * @deprecated for hibernate use only, don't use
90
	 */
91
	@Deprecated
92
	private NameRelationship(){
93
		super();
94
	}
95

    
96

    
97
	// ************* CONSTRUCTORS *************/
98
	/**
99
	 * Class constructor: creates a new name relationship instance with no
100
	 * reference and adds it to the respective
101
	 * {@link TaxonName#getNameRelations() taxon name relation sets} of both involved names.
102
	 *
103
	 * @param toName			the taxon name to be set as target for the new name relationship
104
	 * @param fromName			the taxon name to be set as source for the new name relationship
105
	 * @param type				the relationship type to be assigned to the new name relationship
106
	 * @param ruleConsidered	the string indicating the article of the nomenclatural code for the new name relationship
107
	 * @see						#NameRelationship(TaxonName, TaxonName, NameRelationshipType, Reference, String, String)
108
	 * @see						TaxonName#addNameRelationship(NameRelationship)
109
	 * @see						TaxonName#addRelationshipFromName(TaxonName, NameRelationshipType, String)
110
	 * @see						TaxonName#addRelationshipToName(TaxonName, NameRelationshipType, String)
111
	 */
112
	protected NameRelationship(TaxonName toName, TaxonName fromName, NameRelationshipType type, String ruleConsidered) {
113
		this(toName, fromName, type, null, null, ruleConsidered);
114
	}
115

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

    
137
	//********* METHODS **************************************/
138

    
139
	/**
140
	 * Returns the {@link TaxonName taxon name} that plays the source role
141
	 * in <i>this</i> taxon name relationship.
142
	 *
143
	 * @see   #getToName()
144
	 * @see   eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
145
	 */
146
	public TaxonName getFromName(){
147
		return this.getRelatedFrom();
148
	}
149

    
150
	/**
151
	 * @see  #getFromName()
152
	 */
153
	void setFromName(TaxonName fromName){
154
		this.setRelatedFrom(fromName);
155
	}
156

    
157
	/**
158
	 * Returns the {@link TaxonName taxon name} that plays the target role
159
	 * in <i>this</i> taxon name relationship.
160
	 *
161
	 * @see   #getFromName()
162
	 * @see   eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
163
	 */
164
	public TaxonName getToName(){
165
		return this.getRelatedTo();
166
	}
167

    
168
	/**
169
	 * @see  #getToName()
170
	 */
171
	void setToName(TaxonName 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 TaxonName 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
	// for extra-package access to relatedFrom use getFromName instead
195
	@Override
196
    protected TaxonName getRelatedFrom() {
197
		return relatedFrom;
198
	}
199

    
200
    // for extra-package access to relatedFrom use getToName instead
201
	@Override
202
    protected TaxonName getRelatedTo() {
203
		return relatedTo;
204
	}
205

    
206
	@Override
207
    public NameRelationshipType getType() {
208
		return type;
209
	}
210

    
211
	@Override
212
    protected void setRelatedFrom(TaxonName relatedFrom) {
213
		this.relatedFrom = relatedFrom;
214
	}
215

    
216
	@Override
217
    protected void setRelatedTo(TaxonName relatedTo) {
218
		this.relatedTo = relatedTo;
219
	}
220

    
221
	@Override
222
    public void setType(NameRelationshipType type) {
223
		this.type = type;
224
	}
225

    
226

    
227
//*********************** CLONE ********************************************************/
228

    
229
	/**
230
	 * Clones <i>this</i> name relationship. This is a shortcut that enables to create
231
	 * a new instance that differs only slightly from <i>this</i> name relationship by
232
	 * modifying only some of the attributes.<BR>
233
	 * CAUTION: Cloning a relationship will not add the relationship to the according
234
	 * {@link #relatedFrom} and {@link #relatedTo} objects. The method is meant to be used
235
	 * mainly for internal purposes (e.g. used within {@link TaxonName#clone()}
236
	 *
237
	 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
238
	 * @see java.lang.Object#clone()
239
	 */
240
	@Override
241
	public Object clone() {
242
		NameRelationship result;
243
		try {
244
			result = (NameRelationship)super.clone();
245
			//no changes to: relatedFrom, relatedTo, type
246
			return result;
247
		} catch (CloneNotSupportedException e) {
248
			logger.warn("Object does not implement cloneable");
249
			e.printStackTrace();
250
			return null;
251
		}
252
	}
253
}
(16-16/36)