Committing large number of changes relating to versioning implementation (#108)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / HybridRelationship.java
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.annotations.Cascade;
24 import org.hibernate.annotations.CascadeType;
25 import org.hibernate.envers.Audited;
26
27 import eu.etaxonomy.cdm.model.common.RelationshipBase;
28 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
29
30 /**
31 * The class representing a hybrid relationship between one of the {@link BotanicalName parents}
32 * of a hybrid taxon name and the hybrid taxon name itself. A hybrid taxon name
33 * is a {@link BotanicalName botanical taxon name} assigned to a hybrid plant following
34 * the {@link NomenclaturalCode#ICBN() ICBN} (Appendix I). A hybrid taxon name must have one
35 * of the hybrid flags set. The hybrid relationship includes a {@link HybridRelationshipType hybrid relationship type}
36 * (for instance "first parent" or "female parent") and the article of the ICBN
37 * on which the hybrid taxon name relies.
38 * <P>
39 * This class corresponds partially to: <ul>
40 * <li> Relationship according to the TDWG ontology
41 * <li> TaxonRelationship according to the TCS
42 * </ul>
43 *
44 * @author m.doering
45 * @version 1.0
46 * @created 08-Nov-2007 13:06:26
47 */
48 @XmlAccessorType(XmlAccessType.FIELD)
49 @XmlType(name = "HybridRelationship", propOrder = {
50 "relatedFrom",
51 "relatedTo",
52 "type",
53 "ruleConsidered"
54 })
55 @Entity
56 @Audited
57 public class HybridRelationship extends RelationshipBase<BotanicalName, BotanicalName, HybridRelationshipType> {
58
59 private static final Logger logger = Logger.getLogger(HybridRelationship.class);
60
61 //The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in
62 //the note property.
63 @XmlElement(name = "RuleConsidered")
64 private String ruleConsidered;
65
66 @XmlElement(name = "RelatedFrom")
67 @XmlIDREF
68 @XmlSchemaType(name = "IDREF")
69 @ManyToOne(fetch=FetchType.LAZY)
70 @Cascade(CascadeType.SAVE_UPDATE)
71 private BotanicalName relatedFrom;
72
73 @XmlElement(name = "RelatedTo")
74 @XmlIDREF
75 @XmlSchemaType(name = "IDREF")
76 @ManyToOne(fetch=FetchType.LAZY)
77 @Cascade(CascadeType.SAVE_UPDATE)
78 private BotanicalName relatedTo;
79
80 @XmlElement(name = "Type")
81 @XmlIDREF
82 @XmlSchemaType(name = "IDREF")
83 @ManyToOne(fetch=FetchType.LAZY)
84 private HybridRelationshipType type;
85
86 //for hibernate use only, don't use
87 @Deprecated
88 private HybridRelationship(){
89 super();
90 }
91
92
93 // ************* CONSTRUCTORS *************/
94 /**
95 * Class constructor: creates a new hybrid relationship instance with no
96 * reference and adds it to the respective
97 * {@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
98 *
99 * @param toName the taxon name to be set as target for the new hybrid relationship
100 * @param fromName the taxon name to be set as source for the new hybrid relationship
101 * @param type the relationship type to be assigned to the new hybrid relationship
102 * @param ruleConsidered the string indicating the article of the ICBN for the hybrid taxon name
103 * @see #HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, ReferenceBase, String, String)
104 * @see BotanicalName#addHybridRelationship(HybridRelationship)
105 */
106 protected HybridRelationship(BotanicalName hybridName, BotanicalName parentName, HybridRelationshipType type, String ruleConsidered) {
107 this(hybridName, parentName, type, null, null, ruleConsidered);
108 }
109
110 /**
111 * Class constructor: creates a new hybrid relationship instance including
112 * its {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference source} and adds it to the respective
113 *{@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
114 *
115 * @param toName the taxon name to be set as target for the new hybrid relationship
116 * @param fromName the taxon name to be set as source for the new hybrid relationship
117 * @param type the relationship type to be assigned to the new hybrid relationship
118 * @param citation the reference source for the new hybrid relationship
119 * @param citationMicroReference the string with the details describing the exact localisation within the reference
120 * @param ruleConsidered the string indicating the article of the ICBN for the hybrid taxon name
121 * @see #HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, String)
122 * @see BotanicalName#addHybridRelationship(HybridRelationship)
123 */
124 protected HybridRelationship(BotanicalName hybridName, BotanicalName parentName, HybridRelationshipType type, ReferenceBase citation, String citationMicroReference, String ruleConsidered) {
125 super(parentName, hybridName, type, citation, citationMicroReference);
126 this.setRuleConsidered(ruleConsidered);
127 }
128
129 //********* METHODS **************************************/
130
131 /**
132 * Returns the {@link BotanicalName botanical taxon name} that plays the parent role
133 * in <i>this</i> hybrid relationship.
134 *
135 * @see #getHybridName()
136 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
137 */
138 public BotanicalName getParentName(){
139 return this.getRelatedFrom();
140 }
141 /**
142 * @see #getParentName()
143 */
144 public void setParentName(BotanicalName parentName){
145 this.setRelatedFrom(parentName);
146 }
147
148 /**
149 * Returns the {@link BotanicalName botanical taxon name} that plays the child role
150 * (the child is actually the hybrid taxon name) in <i>this</i> hybrid relationship.
151 *
152 * @see #getParentName()
153 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
154 */
155 public BotanicalName getHybridName(){
156 return this.getRelatedTo();
157 }
158 /**
159 * @see #getHybridName()
160 */
161 public void setHybridName(BotanicalName hybridName){
162 this.setRelatedTo(hybridName);
163 }
164
165 /**
166 * Returns the ICBN rule considered (that is the
167 * article/note/recommendation in the nomenclatural code) for building
168 * the string representing the (child) hybrid {@link BotanicalName taxon name}
169 * within <i>this</i> hybrid relationship.
170 */
171 public String getRuleConsidered(){
172 return this.ruleConsidered;
173 }
174 /**
175 * @see #getRuleConsidered()
176 */
177 public void setRuleConsidered(String ruleConsidered){
178 this.ruleConsidered = ruleConsidered;
179 }
180
181 protected BotanicalName getRelatedFrom() {
182 return relatedFrom;
183 }
184
185 protected BotanicalName getRelatedTo() {
186 return relatedTo;
187 }
188
189 public HybridRelationshipType getType() {
190 return type;
191 }
192
193 protected void setRelatedFrom(BotanicalName relatedFrom) {
194 this.relatedFrom = relatedFrom;
195 }
196
197 protected void setRelatedTo(BotanicalName relatedTo) {
198 this.relatedTo = relatedTo;
199 }
200
201 protected void setType(HybridRelationshipType type) {
202 this.type = type;
203 }
204 }