Project

General

Profile

Download (7.92 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.envers.Audited;
26
import org.hibernate.search.annotations.Indexed;
27
import org.hibernate.search.annotations.IndexedEmbedded;
28

    
29
import eu.etaxonomy.cdm.model.common.RelationshipBase;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31

    
32
/**
33
 * The class representing a relationship between two {@link Taxon ("accepted/correct") taxa}.
34
 * This includes a {@link TaxonRelationshipType taxon relationship type} (for instance "congruent to" or
35
 * "misapplied name for").
36
 * <P>
37
 * This class corresponds in part to: <ul>
38
 * <li> Relationship according to the TDWG ontology
39
 * <li> TaxonRelationship according to the TCS
40
 * </ul>
41
 *
42
 * @author m.doering
43
 * @created 08-Nov-2007 13:06:58
44
 */
45
@XmlAccessorType(XmlAccessType.FIELD)
46
@XmlType(name = "TaxonRelationship", propOrder = {
47
    "relatedFrom",
48
    "relatedTo",
49
    "type"
50
})
51
@XmlRootElement(name = "TaxonRelationship")
52
@Entity
53
@Audited
54
@Indexed(index = "eu.etaxonomy.cdm.model.taxon.TaxonRelationship")
55
public class TaxonRelationship
56
        extends RelationshipBase<Taxon, Taxon, TaxonRelationshipType> {
57
    private static final long serialVersionUID = 1378437971941534653L;
58
    static private final Logger logger = Logger.getLogger(TaxonRelationship.class);
59

    
60
    @XmlElement(name = "RelatedFrom")
61
    @XmlIDREF
62
    @XmlSchemaType(name = "IDREF")
63
    @ManyToOne(fetch=FetchType.EAGER)
64
//    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
65
    @IndexedEmbedded(includeEmbeddedObjectId=true, depth=1)
66
    private Taxon relatedFrom;
67

    
68
    @XmlElement(name = "RelatedTo")
69
    @XmlIDREF
70
    @XmlSchemaType(name = "IDREF")
71
    @ManyToOne(fetch=FetchType.EAGER)
72
//  @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
73
    @IndexedEmbedded(includeEmbeddedObjectId=true, depth=1)
74
    private Taxon relatedTo;
75

    
76
    @XmlElement(name = "Type")
77
    @XmlIDREF
78
    @XmlSchemaType(name = "IDREF")
79
    @ManyToOne(fetch=FetchType.EAGER)
80
    @IndexedEmbedded(depth=1)
81
    private TaxonRelationshipType type;
82

    
83
    /**
84
     * @deprecated for hibernate only, don't use
85
     */
86
    @Deprecated
87
    private TaxonRelationship(){}
88

    
89
    /**
90
     * Class constructor: creates a new taxon relationship instance (with the
91
     * given "accepted/valid" {@link Taxon taxa}, the given {@link TaxonRelationshipType taxon relationship type}
92
     * and with the {@link eu.etaxonomy.cdm.model.reference.Reference reference source} on which the relationship
93
     * assertion is based). Moreover the new taxon relationship will be added to
94
     * the respective sets of taxon relationships assigned to both taxa.
95
     *
96
     * @param from 						the taxon instance to be involved as a source in the new taxon relationship
97
     * @param to						the taxon instance to be involved as a target in the new taxon relationship
98
     * @param type						the taxon relationship type of the new taxon relationship
99
     * @param citation					the reference source for the new taxon relationship
100
     * @param citationMicroReference	the string with the details describing the exact localisation within the reference
101
     * @see 							eu.etaxonomy.cdm.model.common.RelationshipBase
102
     */
103
    protected TaxonRelationship(Taxon from, Taxon to, TaxonRelationshipType type, Reference citation, String citationMicroReference) {
104
        super(from, to, type, citation, citationMicroReference);
105
    }
106

    
107
    /**
108
     * Returns the {@link Taxon taxon} involved as a source in <i>this</i>
109
     * taxon relationship.
110
     *
111
     * @see    #getToTaxon()
112
     * @see    Taxon#getRelationsFromThisTaxon()
113
     * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
114
     * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getType()
115
     */
116
    @Transient
117
    public Taxon getFromTaxon(){
118
        return getRelatedFrom();
119
    }
120
    /**
121
     * Sets the given {@link Taxon taxon} as a source in <i>this</i> taxon relationship.
122
     * Therefore <i>this</i> taxon relationship will be added to the corresponding
123
     * set of taxon relationships assigned to the given taxon. Furthermore if
124
     * the given taxon replaces an "old" one <i>this</i> taxon relationship will
125
     * be removed from the set of taxon relationships assigned to the "old"
126
     * source taxon.
127
     *
128
     * @param fromTaxon	the taxon instance to be set as a source in <i>this</i> taxon relationship
129
     * @see    			#getFromTaxon()
130
     */
131
    public void setFromTaxon(Taxon fromTaxon){
132
        setRelatedFrom(fromTaxon);
133
    }
134

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

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

    
164
    // for extra-package access to relatedFrom use getFromTaxon instead
165
    @Override
166
    protected Taxon getRelatedFrom() {
167
        return relatedFrom;
168
    }
169

    
170
    // for extra-package access to relatedFrom use getToTaxon instead
171
    @Override
172
    protected Taxon getRelatedTo() {
173
        return relatedTo;
174
    }
175

    
176
    @Override
177
    public TaxonRelationshipType getType() {
178
        return type;
179
    }
180

    
181
    @Override
182
    protected void setRelatedFrom(Taxon relatedFrom) {
183
        if (relatedFrom == null){
184
         //   this.deletedObjects.add(this.relatedFrom);
185
        }
186
        this.relatedFrom = relatedFrom;
187
    }
188

    
189
    @Override
190
    protected void setRelatedTo(Taxon relatedTo) {
191
        if (relatedTo == null){
192
          //  this.deletedObjects.add(this.relatedTo);
193
        }
194
        this.relatedTo = relatedTo;
195
    }
196

    
197
    @Override
198
    public void setType(TaxonRelationshipType type) {
199
        this.type = type;
200
    }
201

    
202
    //*********************************** CLONE *****************************************/
203

    
204
    /**
205
     * Clones <i>this</i> TaxonRelationship. This is a shortcut that enables to create
206
     * a new instance that differs only slightly from <i>this</i> TaxonRelationship by
207
     * modifying only some of the attributes.
208
     *
209
     * @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
210
     * @see java.lang.Object#clone()
211
     */
212
    @Override
213
    public Object clone() {
214
        TaxonRelationship result;
215

    
216
        try{
217
            result = (TaxonRelationship) super.clone();
218
            //no changes to relatedFrom, relatedTo, type
219

    
220
            return result;
221
        } catch (CloneNotSupportedException e) {
222
            logger.warn("Object does not implement cloneable");
223
            e.printStackTrace();
224
            return null;
225
        }
226
    }
227
}
(17-17/21)