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
.common
;
12 import java
.util
.HashSet
;
15 import javax
.persistence
.MappedSuperclass
;
16 import javax
.persistence
.Transient
;
17 import javax
.xml
.bind
.annotation
.XmlAccessType
;
18 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
19 import javax
.xml
.bind
.annotation
.XmlAttribute
;
20 import javax
.xml
.bind
.annotation
.XmlEnum
;
21 import javax
.xml
.bind
.annotation
.XmlEnumValue
;
22 import javax
.xml
.bind
.annotation
.XmlRootElement
;
23 import javax
.xml
.bind
.annotation
.XmlTransient
;
24 import javax
.xml
.bind
.annotation
.XmlType
;
26 import org
.apache
.log4j
.Logger
;
28 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
31 * Concrete implementations of this abstract base class express a directed relationship between two
32 * cdm entities ( {@link IRelated} ). The most important properties of the relationship are:
34 * <li>{@link #getRelatedFrom(IRelated)}</li>
35 * <li>{@link #getRelatedTo(IRelated)}</li>
36 * <li>The {@code <TYPE>}, a RelationshipTermBase which specifies the kind of the relationship</li>
38 * A relationship thus is forming a directed graph consisting of two nodes and an edge:
40 relatedFrom -----[TYPE]----> relatedTo
42 * Whereas the direction of the relation can be valid for the direct (everted) and also for the inverted {@link Direction} direction.
43 * This directional validity is defined by {@link RelationshipTermBase#isSymmetric()}
48 * @author a.kohlbecker (Documentation)
50 @XmlAccessorType(XmlAccessType
.FIELD
)
51 @XmlType(name
= "RelationshipBase")
52 @XmlRootElement(name
= "RelationshipBase")
54 public abstract class RelationshipBase
<FROM
extends IRelated
, TO
extends IRelated
, TYPE
extends RelationshipTermBase
> extends ReferencedEntityBase
implements Cloneable
{
55 private static final long serialVersionUID
= -5030154633820061997L;
56 @SuppressWarnings("unused")
57 private static final Logger logger
= Logger
.getLogger(RelationshipBase
.class);
59 @XmlAttribute(name
= "isDoubtful")
60 private boolean doubtful
;
62 //this set is used only for persistence (CdmDeleteListener) to delete safely relationships and update their former related objects
65 protected Set
<IRelated
> deletedObjects
= new HashSet
<IRelated
>();
69 * Enumeration and String representation of the <code>relatedFrom</code> (invers) and
70 * <code>relatedTo</code> (direct, everted) bean properties. Intended to be used in the
71 * persistence layer only.( But also used in the service layer now - a.kohlbecker )
73 * See also {@link RelationshipBase} for an explanation on relationships in general.
76 public enum Direction
{
77 @XmlEnumValue("relatedFrom")
79 @XmlEnumValue("relatedTo")
83 protected RelationshipBase(){
88 * Creates a relationship between 2 objects and adds it to the respective
89 * relation sets of both objects.
95 * @param citationMicroReference
97 protected RelationshipBase(FROM from
, TO to
, TYPE type
, Reference citation
, String citationMicroReference
) {
98 super(citation
, citationMicroReference
, null);
102 from
.addRelationship(this);
103 to
.addRelationship(this);
106 public abstract TYPE
getType();
108 public abstract void setType(TYPE type
);
110 protected abstract FROM
getRelatedFrom();
112 protected abstract void setRelatedFrom(FROM relatedFrom
);
114 protected abstract TO
getRelatedTo();
116 protected abstract void setRelatedTo(TO relatedTo
);
119 * A boolean flag that marks the relationship between two objects as doubtful
120 * Please be aware that this flag should not be used to mark any status of the
121 * objects themselfs. E.g. when marking a synonym relationship as doubtful
122 * this means that it is doubtful that the synonym is really a synonym to the
123 * taxon. It does not mean that the synonym is doubtfully a synonym.
124 * @return true, if the relationship is doubtful, false otherwise
126 public boolean isDoubtful(){
127 return this.doubtful
;
130 public void setDoubtful(boolean doubtful
){
131 this.doubtful
= doubtful
;
134 public boolean isRemoved(){
135 if ( this.getRelatedFrom() == null ^
this.getRelatedTo() == null){
136 throw new IllegalStateException("A relationship may have only both related object as null or none. But just one is null!");
138 return this.getRelatedFrom() == null || this.getRelatedTo() == null;
141 public Set
getDeletedObjects(){
142 return this.deletedObjects
;
150 // public UUID getToUuidCache(){
151 // return relationTo.getUuid();
153 // protected void setToUuid(UUID uuid){
157 // public UUID getFromUuid(){
158 // return relationTo.getUuid();
160 // protected void setFromUuid(UUID uuid){
165 //*********************** CLONE ********************************************************/
168 * Clones <i>this</i> relationship. This is a shortcut that enables to create
169 * a new instance that differs only slightly from <i>this</i> relationship by
170 * modifying only some of the attributes.
171 * @throws CloneNotSupportedException
173 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
174 * @see java.lang.Object#clone()
177 public Object
clone() throws CloneNotSupportedException
{
178 RelationshipBase
<FROM
,TO
,TYPE
> result
= (RelationshipBase
<FROM
,TO
,TYPE
>)super.clone();
179 //no changes to: doubtful, deletedObjects