Project

General

Profile

Download (9.22 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.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 TaxonNameBase 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 extends RelationshipBase<TaxonNameBase, TaxonNameBase, NameRelationshipType> implements Cloneable{
62
	private static final long serialVersionUID = -615987333520172043L;
63
	private static final Logger logger = Logger.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
    @XmlElement(name = "RelatedFrom")
71
    @XmlIDREF
72
    @XmlSchemaType(name = "IDREF")
73
    @ManyToOne(fetch=FetchType.LAZY)
74
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
75
	private TaxonNameBase relatedFrom;
76

    
77
	@XmlElement(name = "RelatedTo")
78
    @XmlIDREF
79
    @XmlSchemaType(name = "IDREF")
80
    @ManyToOne(fetch=FetchType.LAZY)
81
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
82
	private TaxonNameBase relatedTo;
83

    
84
    @XmlElement(name = "Type")
85
    @XmlIDREF
86
    @XmlSchemaType(name = "IDREF")
87
    @ManyToOne(fetch = FetchType.LAZY)
88
	private NameRelationshipType type;
89

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

    
98

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

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

    
139
	//********* METHODS **************************************/
140

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

    
153
	/**
154
	 * @see  #getFromName()
155
	 */
156
	void setFromName(TaxonNameBase fromName){
157
		this.setRelatedFrom(fromName);
158
	}
159

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

    
172
	/**
173
	 * @see  #getToName()
174
	 */
175
	void setToName(TaxonNameBase toName){
176
		this.setRelatedTo(toName);
177
	}
178

    
179
	/**
180
	 * Returns the nomenclatural code rule considered (that is the
181
	 * article/note/recommendation in the nomenclatural code ruling
182
	 * the  taxon name(s) of this nomenclatural status).
183
	 * The considered rule gives the reason why the
184
	 * {@link NomenclaturalStatusType nomenclatural status type} has been
185
	 * assigned to the {@link TaxonNameBase taxon name(s)}.
186
	 */
187
	public String getRuleConsidered(){
188
		return this.ruleConsidered;
189
	}
190

    
191
	/**
192
	 * @see  #getRuleConsidered()
193
	 */
194
	public void setRuleConsidered(String ruleConsidered){
195
		this.ruleConsidered = ruleConsidered;
196
	}
197

    
198
	// for extra-package access to relatedFrom use getFromName instead
199
	@Override
200
    protected TaxonNameBase getRelatedFrom() {
201
		return relatedFrom;
202
	}
203

    
204
    // for extra-package access to relatedFrom use getToName instead
205
	@Override
206
    protected TaxonNameBase getRelatedTo() {
207
		return relatedTo;
208
	}
209

    
210
	@Override
211
    public NameRelationshipType getType() {
212
		return type;
213
	}
214

    
215
	@Override
216
    protected void setRelatedFrom(TaxonNameBase relatedFrom) {
217
		/*if (relatedFrom == null){
218
			this.deletedObjects.add(this.relatedFrom);
219
		}*/
220
		this.relatedFrom = relatedFrom;
221
	}
222

    
223
	@Override
224
    protected void setRelatedTo(TaxonNameBase relatedTo) {
225
		/*if (relatedTo == null){
226
			this.deletedObjects.add(this.relatedTo);
227
		}*/
228
		this.relatedTo = relatedTo;
229
	}
230

    
231
	@Override
232
    public void setType(NameRelationshipType type) {
233
		this.type = type;
234
	}
235

    
236

    
237
//*********************** CLONE ********************************************************/
238

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