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
.logging
.log4j
.LogManager
;
24 import org
.apache
.logging
.log4j
.Logger
;
25 import org
.hibernate
.envers
.Audited
;
27 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
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
46 * @since 08-Nov-2007 13:06:26
48 @XmlAccessorType(XmlAccessType
.FIELD
)
49 @XmlType(name
= "HybridRelationship", propOrder
= {
57 public class HybridRelationship
58 extends RelationshipBase
<INonViralName
, INonViralName
, HybridRelationshipType
>
59 implements Comparable
<HybridRelationship
>, IRuleConsidered
{
61 private static final long serialVersionUID
= -78515930138896939L;
62 private static final Logger logger
= LogManager
.getLogger();
64 // //The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in
65 // //the note property.
66 // @XmlElement(name = "RuleConsidered")
67 // private String ruleConsidered;
69 private RuleConsidered ruleConsidered
;
71 @XmlElement(name
= "RelatedFrom")
73 @XmlSchemaType(name
= "IDREF")
74 @ManyToOne(fetch
=FetchType
.LAZY
)
75 // @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
76 private TaxonName relatedFrom
;
78 @XmlElement(name
= "RelatedTo")
80 @XmlSchemaType(name
= "IDREF")
81 @ManyToOne(fetch
=FetchType
.LAZY
)
82 // @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
83 private TaxonName relatedTo
;
85 @XmlElement(name
= "Type")
87 @XmlSchemaType(name
= "IDREF")
88 @ManyToOne(fetch
=FetchType
.LAZY
)
89 private HybridRelationshipType type
;
92 * @deprecated for hibernate use only, don't use
95 private HybridRelationship(){
100 // ************* CONSTRUCTORS *************/
102 * Class constructor: creates a new hybrid relationship instance with no
103 * reference and adds it to the respective
104 * {@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
106 * @param toName the taxon name to be set as target for the new hybrid relationship
107 * @param fromName the taxon name to be set as source for the new hybrid relationship
108 * @param type the relationship type to be assigned to the new hybrid relationship
109 * @param ruleConsidered the string indicating the article of the ICBN for the hybrid taxon name
110 * @see #HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, Reference, String, String)
111 * @see TaxonName#addHybridRelationship(HybridRelationship)
113 protected HybridRelationship(INonViralName hybridName
, INonViralName parentName
, HybridRelationshipType type
, String ruleConsidered
) {
114 this(hybridName
, parentName
, type
, null, null, ruleConsidered
, null);
118 * Class constructor: creates a new hybrid relationship instance including
119 * its {@link eu.etaxonomy.cdm.model.reference.Reference reference source} and adds it to the respective
120 *{@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
122 * @param toName the taxon name to be set as target for the new hybrid relationship
123 * @param fromName the taxon name to be set as source for the new hybrid relationship
124 * @param type the relationship type to be assigned to the new hybrid relationship
125 * @param citation the reference source for the new hybrid relationship
126 * @param citationMicroReference the string with the details describing the exact localisation within the reference
127 * @param ruleConsidered the string indicating the article of the ICBN for the hybrid taxon name
128 * @see #HybridRelationship(BotanicalName, BotanicalName, HybridRelationshipType, String)
129 * @see TaxonName#addHybridRelationship(HybridRelationship)
131 protected HybridRelationship(INonViralName hybridName
, INonViralName parentName
, HybridRelationshipType type
, Reference citation
,
132 String citationMicroReference
, String ruleConsidered
, NomenclaturalCodeEdition codeEdition
) {
133 super(parentName
, hybridName
, type
, citation
, citationMicroReference
);
134 this.setRuleConsidered(ruleConsidered
);
135 this.setCodeEdition(codeEdition
);
138 //********* METHODS **************************************/
141 * Returns the {@link BotanicalName botanical taxon name} that plays the parent role
142 * in <i>this</i> hybrid relationship.
144 * @see #getHybridName()
145 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
148 public TaxonName
getParentName(){
149 return this.getRelatedFrom();
152 * @see #getParentName()
154 public void setParentName(INonViralName parentName
){
155 this.setRelatedFrom(parentName
);
159 * Returns the {@link BotanicalName botanical taxon name} that plays the child role
160 * (the child is actually the hybrid taxon name) in <i>this</i> hybrid relationship.
162 * @see #getParentName()
163 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
166 public TaxonName
getHybridName(){
167 return this.getRelatedTo();
170 * @see #getHybridName()
172 public void setHybridName(INonViralName hybridName
){
173 this.setRelatedTo(hybridName
);
177 * Returns the ICBN rule considered (that is the
178 * article/note/recommendation in the nomenclatural code) for building
179 * the string representing the (child) hybrid {@link BotanicalName taxon name}
180 * within <i>this</i> hybrid relationship.
183 public String
getRuleConsidered(){
184 return this.ruleConsidered().getText();
187 * @see #getRuleConsidered()
190 public void setRuleConsidered(String ruleConsidered
){
191 this.ruleConsidered().setText(ruleConsidered
);
194 * The {@link NomenclaturalCodeEdition code edition} for the {@link #getRuleConsidered() rule considered}.
197 public NomenclaturalCodeEdition
getCodeEdition() {
198 return ruleConsidered().getCodeEdition();
201 public void setCodeEdition(NomenclaturalCodeEdition codeEdition
) {
202 ruleConsidered().setCodeEdition(codeEdition
);
205 public IdentifiableSource
getCodeEditionSource() {
206 NomenclaturalCodeEdition codeEdition
= ruleConsidered().getCodeEdition();
207 return codeEdition
== null ?
null : codeEdition
.getSource();
209 private RuleConsidered
ruleConsidered(){
210 if(this.ruleConsidered
==null){
211 ruleConsidered
= new RuleConsidered();
213 return ruleConsidered
;
217 protected TaxonName
getRelatedFrom() {
222 protected TaxonName
getRelatedTo() {
227 public HybridRelationshipType
getType() {
232 protected void setRelatedFrom(INonViralName relatedFrom
) {
233 this.relatedFrom
= TaxonName
.castAndDeproxy(relatedFrom
);
237 protected void setRelatedTo(INonViralName relatedTo
) {
238 this.relatedTo
= TaxonName
.castAndDeproxy(relatedTo
);
242 public void setType(HybridRelationshipType type
) {
246 // ************************ compareTo *************************************************
249 public int compareTo(HybridRelationship rel2
) {
250 HybridRelationshipType type1
= this.getType();
251 HybridRelationshipType type2
= rel2
.getType();
252 int compareType
= type1
.compareTo(type2
);
253 if (compareType
!= 0){
256 TaxonName related1
= this.getRelatedFrom();
257 TaxonName related2
= rel2
.getRelatedFrom();
258 if (related1
!= related2
){
259 related1
= this.getRelatedTo();
260 related2
= rel2
.getRelatedTo();
262 if (related1
.equals(related2
)){
266 String title1
= related1
.getTitleCache();
267 String title2
= related2
.getTitleCache();
268 return title1
.compareTo(title2
);
272 //*********************** CLONE ********************************************************/
275 * Clones <i>this</i> hybrid relationship. This is a shortcut that enables to create
276 * a new instance that differs only slightly from <i>this</i> hybrid relationship by
277 * modifying only some of the attributes.<BR>
278 * CAUTION: Cloning a relationship will not add the relationship to the according
279 * {@link #relatedFrom} and {@link #relatedTo} objects. The method is meant to be used
280 * mainly for internal purposes (e.g. used within {@link TaxonName#clone()}
282 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
283 * @see java.lang.Object#clone()
286 public HybridRelationship
clone() {
287 HybridRelationship result
;
289 result
= (HybridRelationship
)super.clone();
290 result
.ruleConsidered
= this.ruleConsidered
== null?
null : this.ruleConsidered
.clone();
291 //no changes to: relatedFrom, relatedTo, type
293 } catch (CloneNotSupportedException e
) {
294 logger
.warn("Object does not implement cloneable");