root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonRelationship.java

Revision 11696, 7.4 kB (checked in by k.luther, 14 months ago)

remaining clone methods

  • Property svn:keywords set to Id
Line 
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
10package eu.etaxonomy.cdm.model.taxon;
11
12import javax.persistence.Entity;
13import javax.persistence.FetchType;
14import javax.persistence.ManyToOne;
15import javax.persistence.Transient;
16import javax.xml.bind.annotation.XmlAccessType;
17import javax.xml.bind.annotation.XmlAccessorType;
18import javax.xml.bind.annotation.XmlElement;
19import javax.xml.bind.annotation.XmlIDREF;
20import javax.xml.bind.annotation.XmlRootElement;
21import javax.xml.bind.annotation.XmlSchemaType;
22import javax.xml.bind.annotation.XmlType;
23
24import org.apache.log4j.Logger;
25import org.hibernate.annotations.Cascade;
26import org.hibernate.annotations.CascadeType;
27import org.hibernate.envers.Audited;
28
29import eu.etaxonomy.cdm.model.common.RelationshipBase;
30import eu.etaxonomy.cdm.model.location.NamedArea;
31import eu.etaxonomy.cdm.model.reference.Reference;
32import eu.etaxonomy.cdm.validation.Level3;
33import eu.etaxonomy.cdm.validation.annotation.ChildTaxaMustBeLowerRankThanParent;
34import eu.etaxonomy.cdm.validation.annotation.ChildTaxaMustDeriveNameFromParent;
35import eu.etaxonomy.cdm.validation.annotation.ChildTaxaMustNotSkipRanks;
36
37/**
38 * The class representing a relationship between two {@link Taxon ("accepted/correct") taxa}.
39 * This includes a {@link TaxonRelationshipType taxon relationship type} (for instance "congruent to" or
40 * "misapplied name for").
41 * <P>
42 * This class corresponds in part to: <ul>
43 * <li> Relationship according to the TDWG ontology
44 * <li> TaxonRelationship according to the TCS
45 * </ul>
46 *
47 * @author m.doering
48 * @version 1.0
49 * @created 08-Nov-2007 13:06:58
50 */
51@XmlAccessorType(XmlAccessType.FIELD)
52@XmlType(name = "TaxonRelationship", propOrder = {
53        "relatedFrom",
54        "relatedTo",
55        "type"
56})
57@XmlRootElement(name = "TaxonRelationship")
58@Entity
59@Audited
60@ChildTaxaMustBeLowerRankThanParent(groups = Level3.class)
61@ChildTaxaMustNotSkipRanks(groups = Level3.class)
62@ChildTaxaMustDeriveNameFromParent(groups = Level3.class)
63public class TaxonRelationship extends RelationshipBase<Taxon, Taxon, TaxonRelationshipType> {
64
65        static private final Logger logger = Logger.getLogger(TaxonRelationship.class);
66
67        @XmlElement(name = "RelatedFrom")
68    @XmlIDREF
69    @XmlSchemaType(name = "IDREF")
70    @ManyToOne(fetch=FetchType.EAGER)
71    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
72        private Taxon relatedFrom;
73
74        @XmlElement(name = "RelatedTo")
75    @XmlIDREF
76    @XmlSchemaType(name = "IDREF")
77    @ManyToOne(fetch=FetchType.EAGER)
78    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
79        private Taxon relatedTo;
80       
81    @XmlElement(name = "Type")
82    @XmlIDREF
83    @XmlSchemaType(name = "IDREF")
84    @ManyToOne(fetch=FetchType.EAGER)
85        private TaxonRelationshipType type;
86       
87        /**
88         * @deprecated for hibernate only, don't use
89         */
90        @Deprecated
91        private TaxonRelationship(){           
92        }
93       
94        /**
95         * Class constructor: creates a new taxon relationship instance (with the
96         * given "accepted/correct" {@link Taxon taxa}, the given {@link SynonymRelationshipType synonym relationship type}
97         * and with the {@link eu.etaxonomy.cdm.model.reference.Reference reference source} on which the relationship
98         * assertion is based). Moreover the new taxon relationship will be added to
99         * the respective sets of taxon relationships assigned to both taxa.
100         *
101         * @param from                                          the taxon instance to be involved as a source in the new taxon relationship
102         * @param to                                            the taxon instance to be involved as a target in the new taxon relationship
103         * @param type                                          the taxon relationship type of the new taxon relationship
104         * @param citation                                      the reference source for the new taxon relationship
105         * @param citationMicroReference        the string with the details describing the exact localisation within the reference
106         * @see                                                         eu.etaxonomy.cdm.model.common.RelationshipBase
107         */
108        protected TaxonRelationship(Taxon from, Taxon to, TaxonRelationshipType type, Reference citation, String citationMicroReference) {
109                super(from, to, type, citation, citationMicroReference);
110        }
111       
112        /**
113         * Returns the {@link Taxon taxon} involved as a source in <i>this</i>
114         * taxon relationship.
115         * 
116         * @see    #getToTaxon()
117         * @see    Taxon#getRelationsFromThisTaxon()
118         * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
119         * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getType()
120         */
121        @Transient
122        public Taxon getFromTaxon(){
123                return getRelatedFrom();
124        }
125        /**
126         * Sets the given {@link Taxon taxon} as a source in <i>this</i> taxon relationship.
127         * Therefore <i>this</i> taxon relationship will be added to the corresponding
128         * set of taxon relationships assigned to the given taxon. Furthermore if
129         * the given taxon replaces an "old" one <i>this</i> taxon relationship will
130         * be removed from the set of taxon relationships assigned to the "old"
131         * source taxon.
132         * 
133         * @param fromTaxon     the taxon instance to be set as a source in <i>this</i> synonym relationship
134         * @see                         #getFromTaxon()
135         */
136        public void setFromTaxon(Taxon fromTaxon){
137                setRelatedFrom(fromTaxon);
138        }
139
140        /**
141         * Returns the {@link Taxon taxon} involved as a target in <i>this</i>
142         * taxon relationship.
143         * 
144         * @see    #getFromTaxon()
145         * @see    Taxon#getRelationsToThisTaxon()
146         * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
147         * @see    eu.etaxonomy.cdm.model.common.RelationshipBase#getType()
148         */
149        @Transient
150        public Taxon getToTaxon(){
151                return getRelatedTo();
152        }
153
154        /**
155         * Sets the given {@link Taxon taxon} as a target in <i>this</i> taxon relationship.
156         * Therefore <i>this</i> taxon relationship will be added to the corresponding
157         * set of taxon relationships assigned to the given taxon. Furthermore if
158         * the given taxon replaces an "old" one <i>this</i> taxon relationship will
159         * be removed from the set of taxon relationships assigned to the "old"
160         * target taxon.
161         * 
162         * @param toTaxon       the taxon instance to be set as a target in <i>this</i> synonym relationship
163         * @see                         #getToTaxon()
164         */
165        public void setToTaxon(Taxon toTaxon){
166                setRelatedTo(toTaxon);
167        }
168
169        protected Taxon getRelatedFrom() {
170                return relatedFrom;
171        }
172
173        protected Taxon getRelatedTo() {
174                return relatedTo;
175        }
176
177        public TaxonRelationshipType getType() {
178                return type;
179        }
180
181        protected void setRelatedFrom(Taxon relatedFrom) {
182                if (relatedFrom == null){
183                        this.deletedObjects.add(this.relatedFrom);
184                }
185                this.relatedFrom = relatedFrom;
186        }
187
188        protected void setRelatedTo(Taxon relatedTo) {
189                if (relatedTo == null){
190                        this.deletedObjects.add(this.relatedTo);
191                }
192                this.relatedTo = relatedTo;
193        }
194
195        public void setType(TaxonRelationshipType type) {
196                this.type = type;
197        }
198       
199        //*********************************** CLONE *****************************************/
200
201        /**
202         * Clones <i>this</i> TaxonRelationship. This is a shortcut that enables to create
203         * a new instance that differs only slightly from <i>this</i> TaxonRelationship by
204         * modifying only some of the attributes.
205         *
206         * @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
207         * @see java.lang.Object#clone()
208         */
209        @Override
210        public Object clone() {
211                TaxonRelationship result;
212               
213                try{
214                        result = (TaxonRelationship) super.clone();
215                        //no changes to relatedFrom, relatedTo, type
216                       
217                        return result;
218                } catch (CloneNotSupportedException e) {
219                        logger.warn("Object does not implement cloneable");
220                        e.printStackTrace();
221                        return null;
222                }
223        }
224}
Note: See TracBrowser for help on using the browser.