Project

General

Profile

Download (6.65 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.taxon;
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.XmlRootElement;
21
import javax.xml.bind.annotation.XmlSchemaType;
22
import javax.xml.bind.annotation.XmlType;
23

    
24
import org.apache.log4j.Logger;
25
import org.hibernate.annotations.Cascade;
26
import org.hibernate.annotations.CascadeType;
27
import org.hibernate.envers.Audited;
28

    
29
import eu.etaxonomy.cdm.model.common.RelationshipBase;
30
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
31
import eu.etaxonomy.cdm.validation.Level3;
32
import eu.etaxonomy.cdm.validation.annotation.ChildTaxaMustBeLowerRankThanParent;
33
import eu.etaxonomy.cdm.validation.annotation.ChildTaxaMustDeriveNameFromParent;
34
import eu.etaxonomy.cdm.validation.annotation.ChildTaxaMustNotSkipRanks;
35

    
36
/**
37
 * The class representing a relationship between two {@link Taxon ("accepted/correct") taxa}. 
38
 * This includes a {@link TaxonRelationshipType taxon relationship type} (for instance "congruent to" or
39
 * "misapplied name for").
40
 * <P>
41
 * This class corresponds in part 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:58
49
 */
50
@XmlAccessorType(XmlAccessType.FIELD)
51
@XmlType(name = "TaxonRelationship", propOrder = {
52
	"relatedFrom",
53
	"relatedTo",
54
	"type"
55
})
56
@XmlRootElement(name = "TaxonRelationship")
57
@Entity
58
@Audited
59
@ChildTaxaMustBeLowerRankThanParent(groups = Level3.class)
60
@ChildTaxaMustNotSkipRanks(groups = Level3.class)
61
@ChildTaxaMustDeriveNameFromParent(groups = Level3.class)
62
public class TaxonRelationship extends RelationshipBase<Taxon, Taxon, TaxonRelationshipType> {
63

    
64
	static private final Logger logger = Logger.getLogger(TaxonRelationship.class);
65

    
66
	@XmlElement(name = "RelatedFrom")
67
    @XmlIDREF
68
    @XmlSchemaType(name = "IDREF")
69
    @ManyToOne(fetch=FetchType.EAGER)
70
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
71
	private Taxon relatedFrom;
72

    
73
	@XmlElement(name = "RelatedTo")
74
    @XmlIDREF
75
    @XmlSchemaType(name = "IDREF")
76
    @ManyToOne(fetch=FetchType.EAGER)
77
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
78
	private Taxon relatedTo;
79
	
80
    @XmlElement(name = "Type")
81
    @XmlIDREF
82
    @XmlSchemaType(name = "IDREF")
83
    @ManyToOne(fetch=FetchType.EAGER)
84
	private TaxonRelationshipType type;
85
	
86
	//for hibernate, don't use
87
	@Deprecated
88
	private TaxonRelationship(){		
89
	}
90
	
91
	/**
92
	 * Class constructor: creates a new taxon relationship instance (with the
93
	 * given "accepted/correct" {@link Taxon taxa}, the given {@link SynonymRelationshipType synonym relationship type}
94
	 * and with the {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference source} on which the relationship
95
	 * assertion is based). Moreover the new taxon relationship will be added to
96
	 * the respective sets of taxon relationships assigned to both taxa.
97
	 * 
98
	 * @param from 						the taxon instance to be involved as a source in the new taxon relationship
99
	 * @param to						the taxon instance to be involved as a target in the new taxon relationship
100
	 * @param type						the taxon relationship type of the new taxon relationship
101
	 * @param citation					the reference source for the new taxon relationship
102
	 * @param citationMicroReference	the string with the details describing the exact localisation within the reference
103
	 * @see 							eu.etaxonomy.cdm.model.common.RelationshipBase
104
	 */
105
	protected TaxonRelationship(Taxon from, Taxon to, TaxonRelationshipType type, ReferenceBase citation, String citationMicroReference) {
106
		super(from, to, type, citation, citationMicroReference);
107
	}
108
	
109
	/** 
110
	 * Returns the {@link Taxon taxon} involved as a source in <i>this</i>
111
	 * taxon relationship.
112
	 *  
113
	 * @see    #getToTaxon()
114
	 * @see    Taxon#getRelationsFromThisTaxon()
115
	 * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
116
	 * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getType()
117
	 */
118
	@Transient
119
	public Taxon getFromTaxon(){
120
		return getRelatedFrom();
121
	}
122
	/** 
123
	 * Sets the given {@link Taxon taxon} as a source in <i>this</i> taxon relationship.
124
	 * Therefore <i>this</i> taxon relationship will be added to the corresponding
125
	 * set of taxon relationships assigned to the given taxon. Furthermore if
126
	 * the given taxon replaces an "old" one <i>this</i> taxon relationship will
127
	 * be removed from the set of taxon relationships assigned to the "old"
128
	 * source taxon.
129
	 *  
130
	 * @param fromTaxon	the taxon instance to be set as a source in <i>this</i> synonym relationship
131
	 * @see    			#getFromTaxon()
132
	 */
133
	public void setFromTaxon(Taxon fromTaxon){
134
		setRelatedFrom(fromTaxon);
135
	}
136

    
137
	/** 
138
	 * Returns the {@link Taxon taxon} involved as a target in <i>this</i>
139
	 * taxon relationship.
140
	 *  
141
	 * @see    #getFromTaxon()
142
	 * @see    Taxon#getRelationsToThisTaxon()
143
	 * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
144
	 * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getType()
145
	 */
146
	@Transient
147
	public Taxon getToTaxon(){
148
		return getRelatedTo();
149
	}
150

    
151
	/** 
152
	 * Sets the given {@link Taxon taxon} as a target in <i>this</i> taxon relationship.
153
	 * Therefore <i>this</i> taxon relationship will be added to the corresponding
154
	 * set of taxon relationships assigned to the given taxon. Furthermore if
155
	 * the given taxon replaces an "old" one <i>this</i> taxon relationship will
156
	 * be removed from the set of taxon relationships assigned to the "old"
157
	 * target taxon.
158
	 *  
159
	 * @param toTaxon	the taxon instance to be set as a target in <i>this</i> synonym relationship
160
	 * @see    			#getToTaxon()
161
	 */
162
	public void setToTaxon(Taxon toTaxon){
163
		setRelatedTo(toTaxon);
164
	}
165

    
166
	protected Taxon getRelatedFrom() {
167
		return relatedFrom;
168
	}
169

    
170
	protected Taxon getRelatedTo() {
171
		return relatedTo;
172
	}
173

    
174
	public TaxonRelationshipType getType() {
175
		return type;
176
	}
177

    
178
	protected void setRelatedFrom(Taxon relatedFrom) {
179
		if (relatedFrom == null){
180
			this.deletedObjects.add(this.relatedFrom);
181
		}
182
		this.relatedFrom = relatedFrom;
183
	}
184

    
185
	protected void setRelatedTo(Taxon relatedTo) {
186
		if (relatedTo == null){
187
			this.deletedObjects.add(this.relatedTo);
188
		}
189
		this.relatedTo = relatedTo;
190
	}
191

    
192
	public void setType(TaxonRelationshipType type) {
193
		this.type = type;
194
	}
195
}
(12-12/16)