2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.name
;
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
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.hibernate
.annotations
.Cascade
;
25 import org
.hibernate
.annotations
.CascadeType
;
26 import org
.hibernate
.envers
.Audited
;
28 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
29 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
32 * The class representing a hybrid relationship between one of the {@link BotanicalName parents}
33 * of a hybrid taxon name and the hybrid taxon name itself. A hybrid taxon name
34 * is a {@link BotanicalName botanical taxon name} assigned to a hybrid plant following
35 * the {@link NomenclaturalCode#ICBN() ICBN} (Appendix I). A hybrid taxon name must have one
36 * of the hybrid flags set. The hybrid relationship includes a {@link HybridRelationshipType hybrid relationship type}
37 * (for instance "first parent" or "female parent") and the article of the ICBN
38 * on which the hybrid taxon name relies.
40 * This class corresponds partially to: <ul>
41 * <li> Relationship according to the TDWG ontology
42 * <li> TaxonRelationship according to the TCS
47 * @created 08-Nov-2007 13:06:26
49 @XmlAccessorType(XmlAccessType
.FIELD
)
50 @XmlType(name
= "HybridRelationship", propOrder
= {
58 public class HybridRelationship
extends RelationshipBase
<NonViralName
, NonViralName
, HybridRelationshipType
> implements Cloneable
, Comparable
<HybridRelationship
>{
59 private static final Logger logger
= Logger
.getLogger(HybridRelationship
.class);
61 //The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in
63 @XmlElement(name
= "RuleConsidered")
64 private String ruleConsidered
;
66 @XmlElement(name
= "RelatedFrom")
68 @XmlSchemaType(name
= "IDREF")
69 @ManyToOne(fetch
=FetchType
.LAZY
)
70 @Cascade(CascadeType
.SAVE_UPDATE
)
71 private NonViralName relatedFrom
;
73 @XmlElement(name
= "RelatedTo")
75 @XmlSchemaType(name
= "IDREF")
76 @ManyToOne(fetch
=FetchType
.LAZY
)
77 @Cascade(CascadeType
.SAVE_UPDATE
)
78 private NonViralName relatedTo
;
80 @XmlElement(name
= "Type")
82 @XmlSchemaType(name
= "IDREF")
83 @ManyToOne(fetch
=FetchType
.LAZY
)
84 private HybridRelationshipType type
;
87 * @deprecated for hibernate use only, don't use
90 private HybridRelationship(){
95 // ************* CONSTRUCTORS *************/
97 * Class constructor: creates a new hybrid relationship instance with no
98 * reference and adds it to the respective
99 * {@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
101 * @param toName the taxon name to be set as target for the new hybrid relationship
102 * @param fromName the taxon name to be set as source for the new hybrid relationship
103 * @param type the relationship type to be assigned to the new hybrid relationship
104 * @param ruleConsidered the string indicating the article of the ICBN for the hybrid taxon name
105 * @see #HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, Reference, String, String)
106 * @see BotanicalName#addHybridRelationship(HybridRelationship)
108 protected HybridRelationship(NonViralName hybridName
, NonViralName parentName
, HybridRelationshipType type
, String ruleConsidered
) {
109 this(hybridName
, parentName
, type
, null, null, ruleConsidered
);
113 * Class constructor: creates a new hybrid relationship instance including
114 * its {@link eu.etaxonomy.cdm.model.reference.Reference reference source} and adds it to the respective
115 *{@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
117 * @param toName the taxon name to be set as target for the new hybrid relationship
118 * @param fromName the taxon name to be set as source for the new hybrid relationship
119 * @param type the relationship type to be assigned to the new hybrid relationship
120 * @param citation the reference source for the new hybrid relationship
121 * @param citationMicroReference the string with the details describing the exact localisation within the reference
122 * @param ruleConsidered the string indicating the article of the ICBN for the hybrid taxon name
123 * @see #HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, String)
124 * @see BotanicalName#addHybridRelationship(HybridRelationship)
126 protected HybridRelationship(NonViralName hybridName
, NonViralName parentName
, HybridRelationshipType type
, Reference citation
, String citationMicroReference
, String ruleConsidered
) {
127 super(parentName
, hybridName
, type
, citation
, citationMicroReference
);
128 this.setRuleConsidered(ruleConsidered
);
131 //********* METHODS **************************************/
134 * Returns the {@link BotanicalName botanical taxon name} that plays the parent role
135 * in <i>this</i> hybrid relationship.
137 * @see #getHybridName()
138 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
141 public NonViralName
getParentName(){
142 return this.getRelatedFrom();
145 * @see #getParentName()
147 public void setParentName(NonViralName parentName
){
148 this.setRelatedFrom(parentName
);
152 * Returns the {@link BotanicalName botanical taxon name} that plays the child role
153 * (the child is actually the hybrid taxon name) in <i>this</i> hybrid relationship.
155 * @see #getParentName()
156 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
159 public NonViralName
getHybridName(){
160 return this.getRelatedTo();
163 * @see #getHybridName()
165 public void setHybridName(NonViralName hybridName
){
166 this.setRelatedTo(hybridName
);
170 * Returns the ICBN rule considered (that is the
171 * article/note/recommendation in the nomenclatural code) for building
172 * the string representing the (child) hybrid {@link BotanicalName taxon name}
173 * within <i>this</i> hybrid relationship.
175 public String
getRuleConsidered(){
176 return this.ruleConsidered
;
179 * @see #getRuleConsidered()
181 public void setRuleConsidered(String ruleConsidered
){
182 this.ruleConsidered
= ruleConsidered
;
185 protected NonViralName
getRelatedFrom() {
189 protected NonViralName
getRelatedTo() {
193 public HybridRelationshipType
getType() {
197 protected void setRelatedFrom(NonViralName relatedFrom
) {
198 if (relatedFrom
== null){
199 this.deletedObjects
.add(this.relatedFrom
);
201 this.relatedFrom
= relatedFrom
;
204 protected void setRelatedTo(NonViralName relatedTo
) {
205 if (relatedTo
== null){
206 this.deletedObjects
.add(this.relatedTo
);
208 this.relatedTo
= relatedTo
;
211 public void setType(HybridRelationshipType type
) {
215 // ************************ compareTo *************************************************
217 * @see java.lang.Comparable#compareTo(java.lang.Object)
219 // @Override //leads to compile errors in some environments
220 public int compareTo(HybridRelationship rel2
) {
221 HybridRelationshipType type1
= this.getType();
222 HybridRelationshipType type2
= rel2
.getType();
223 int compareType
= type1
.compareTo(type2
);
224 if (compareType
!= 0){
227 NonViralName related1
= this.getRelatedFrom();
228 NonViralName
<?
> related2
= rel2
.getRelatedFrom();
229 if (related1
!= related2
){
230 related1
= this.getRelatedTo();
231 related2
= rel2
.getRelatedTo();
233 String title1
= related1
.getTitleCache();
234 String title2
= related2
.getTitleCache();
235 return title1
.compareTo(title2
);
240 //*********************** CLONE ********************************************************/
243 * Clones <i>this</i> hybrid relationship. This is a shortcut that enables to create
244 * a new instance that differs only slightly from <i>this</i> hybrid relationship by
245 * modifying only some of the attributes.<BR>
246 * CAUTION: Cloning a relationship will not add the relationship to the according
247 * {@link #relatedFrom} and {@link #relatedTo} objects. The method is meant to be used
248 * mainly for internal purposes (e.g. used within {@link TaxonNameBase#clone()}
250 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
251 * @see java.lang.Object#clone()
254 public Object
clone() {
255 HybridRelationship result
;
257 result
= (HybridRelationship
)super.clone();
258 //no changes to: relatedFrom, relatedTo, type
260 } catch (CloneNotSupportedException e
) {
261 logger
.warn("Object does not implement cloneable");