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
.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
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.hibernate
.annotations
.Cascade
;
26 import org
.hibernate
.annotations
.CascadeType
;
28 import eu
.etaxonomy
.cdm
.strategy
.merge
.Merge
;
29 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeMode
;
32 * Abstract superclass implementing human annotations and machine markers to be assigned to CDM objects.
35 * @created 08-Nov-2007 13:06:10
37 @XmlAccessorType(XmlAccessType
.FIELD
)
38 @XmlType(name
= "AnnotatableEntity", propOrder
= {
43 public abstract class AnnotatableEntity
extends VersionableEntity
implements IAnnotatableEntity
{
44 private static final long serialVersionUID
= 9151211842542443102L;
45 @SuppressWarnings("unused")
46 private static final Logger logger
= Logger
.getLogger(AnnotatableEntity
.class);
48 @XmlElementWrapper(name
= "Markers", nillable
= true)
49 @XmlElement(name
= "Marker")
50 @OneToMany(fetch
=FetchType
.LAZY
)
51 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
, CascadeType
.DELETE_ORPHAN
})
52 @Merge(MergeMode
.ADD_CLONE
)
53 protected Set
<Marker
> markers
;
55 @XmlElementWrapper(name
= "Annotations", nillable
= true)
56 @XmlElement(name
= "Annotation")
57 @OneToMany(fetch
=FetchType
.LAZY
)
58 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
, CascadeType
.DELETE_ORPHAN
})
59 @Merge(MergeMode
.ADD_CLONE
)
60 protected Set
<Annotation
> annotations
;
62 protected AnnotatableEntity() {
66 //*************** MARKER **********************************************
69 public Set
<Marker
> getMarkers(){
71 this.markers
= new HashSet
<Marker
>();
75 public void addMarker(Marker marker
){
77 marker
.setMarkedObj(this);
78 getMarkers().add(marker
);
81 public void removeMarker(Marker marker
){
82 if(getMarkers().contains(marker
)) {
83 getMarkers().remove(marker
);
84 marker
.setMarkedObj(null);
88 //*************** ANNOTATIONS **********************************************
90 public Set
<Annotation
> getAnnotations(){
91 if(annotations
== null) {
92 this.annotations
= new HashSet
<Annotation
>();
94 return this.annotations
;
96 public void addAnnotation(Annotation annotation
){
97 if (annotation
!= null){
98 annotation
.setAnnotatedObj(this);
99 getAnnotations().add(annotation
);
103 public void removeAnnotation(Annotation annotation
){
104 if(getAnnotations().contains(annotation
)) {
105 getAnnotations().remove(annotation
);
106 annotation
.setAnnotatedObj(null);
110 //********************** CLONE *****************************************/
113 * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
116 public Object
clone() throws CloneNotSupportedException
{
117 AnnotatableEntity result
= (AnnotatableEntity
)super.clone();
120 result
.annotations
= new HashSet
<Annotation
>();
121 for (Annotation annotation
: getAnnotations()){
122 Annotation newAnnotation
= (Annotation
)annotation
.clone();
123 result
.addAnnotation(newAnnotation
);
127 result
.markers
= new HashSet
<Marker
>();
128 for (Marker marker
: getMarkers()){
129 Marker newMarker
= (Marker
)marker
.clone();
130 result
.addMarker(newMarker
);