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