cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/AnnotatableEntity.java @ 17f0cc4b
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.common; |
11 |
|
12 |
import java.util.HashSet; |
13 |
import java.util.Set; |
14 |
|
15 |
import javax.persistence.FetchType; |
16 |
import javax.persistence.MappedSuperclass; |
17 |
import javax.persistence.OneToMany; |
18 |
import javax.xml.bind.annotation.XmlAccessType; |
19 |
import javax.xml.bind.annotation.XmlAccessorType; |
20 |
import javax.xml.bind.annotation.XmlElement; |
21 |
import javax.xml.bind.annotation.XmlElementWrapper; |
22 |
import javax.xml.bind.annotation.XmlType; |
23 |
|
24 |
import org.apache.log4j.Logger; |
25 |
import org.hibernate.annotations.Cascade; |
26 |
import org.hibernate.annotations.CascadeType; |
27 |
|
28 |
import eu.etaxonomy.cdm.strategy.merge.Merge; |
29 |
import eu.etaxonomy.cdm.strategy.merge.MergeMode; |
30 |
|
31 |
/**
|
32 |
* Abstract superclass implementing human annotations and machine markers to be assigned to CDM objects.
|
33 |
* @author m.doering
|
34 |
* @version 1.0
|
35 |
* @created 08-Nov-2007 13:06:10
|
36 |
*/
|
37 |
@XmlAccessorType(XmlAccessType.FIELD) |
38 |
@XmlType(name = "AnnotatableEntity", propOrder = { |
39 |
"markers", |
40 |
"annotations"
|
41 |
})
|
42 |
@MappedSuperclass
|
43 |
public abstract class AnnotatableEntity extends VersionableEntity { |
44 |
private static final long serialVersionUID = 9151211842542443102L; |
45 |
@SuppressWarnings("unused") |
46 |
private static final Logger logger = Logger.getLogger(AnnotatableEntity.class); |
47 |
|
48 |
@XmlElementWrapper(name = "Markers") |
49 |
@XmlElement(name = "Marker") |
50 |
@OneToMany(fetch=FetchType.LAZY) |
51 |
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE}) |
52 |
@Merge(MergeMode.ADD_CLONE) |
53 |
protected Set<Marker> markers = new HashSet<Marker>(); |
54 |
|
55 |
@XmlElementWrapper(name = "Annotations") |
56 |
@XmlElement(name = "Annotation") |
57 |
@OneToMany(fetch=FetchType.LAZY) |
58 |
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE}) |
59 |
@Merge(MergeMode.ADD_CLONE) |
60 |
protected Set<Annotation> annotations = new HashSet<Annotation>(); |
61 |
|
62 |
protected AnnotatableEntity() { |
63 |
super(); |
64 |
}
|
65 |
|
66 |
//*************** MARKER **********************************************
|
67 |
|
68 |
|
69 |
public Set<Marker> getMarkers(){ |
70 |
return this.markers; |
71 |
}
|
72 |
public void addMarker(Marker marker){ |
73 |
if (marker != null){ |
74 |
marker.setMarkedObj(this); |
75 |
markers.add(marker); |
76 |
}
|
77 |
}
|
78 |
public void removeMarker(Marker marker){ |
79 |
if(this.markers.contains(marker)) { |
80 |
this.markers.remove(marker); |
81 |
marker.setMarkedObj(null); |
82 |
}
|
83 |
}
|
84 |
|
85 |
//*************** ANNOTATIONS **********************************************
|
86 |
|
87 |
public Set<Annotation> getAnnotations(){ |
88 |
return this.annotations; |
89 |
}
|
90 |
public void addAnnotation(Annotation annotation){ |
91 |
if (annotation != null){ |
92 |
annotation.setAnnotatedObj(this); |
93 |
annotations.add(annotation); |
94 |
}
|
95 |
}
|
96 |
|
97 |
public void removeAnnotation(Annotation annotation){ |
98 |
if(this.annotations.contains(annotation)) { |
99 |
this.annotations.remove(annotation); |
100 |
annotation.setAnnotatedObj(null); |
101 |
}
|
102 |
}
|
103 |
|
104 |
//********************** CLONE *****************************************/
|
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
|
108 |
*/
|
109 |
@Override
|
110 |
public Object clone() throws CloneNotSupportedException{ |
111 |
AnnotatableEntity result = (AnnotatableEntity)super.clone(); |
112 |
|
113 |
//Annotations
|
114 |
result.annotations = new HashSet<Annotation>(); |
115 |
for (Annotation annotation : this.annotations ){ |
116 |
Annotation newAnnotation = (Annotation)annotation.clone(); |
117 |
result.addAnnotation(newAnnotation); |
118 |
}
|
119 |
|
120 |
//Markers
|
121 |
result.markers = new HashSet<Marker>(); |
122 |
for (Marker marker : this.markers ){ |
123 |
Marker newMarker = (Marker)marker.clone(); |
124 |
result.addMarker(newMarker); |
125 |
}
|
126 |
|
127 |
//no changes to: -
|
128 |
return result; |
129 |
}
|
130 |
}
|