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
;
29 * Abstract superclass implementing human annotations and machine markers to be assigned to CDM objects.
32 * @created 08-Nov-2007 13:06:10
34 @XmlAccessorType(XmlAccessType
.FIELD
)
35 @XmlType(name
= "AnnotatableEntity", propOrder
= {
40 public abstract class AnnotatableEntity
extends VersionableEntity
{
41 private static final long serialVersionUID
= 9151211842542443102L;
42 @SuppressWarnings("unused")
43 private static final Logger logger
= Logger
.getLogger(AnnotatableEntity
.class);
45 @XmlElementWrapper(name
= "Markers")
46 @XmlElement(name
= "Marker")
47 @OneToMany(fetch
=FetchType
.LAZY
)
48 @Cascade({CascadeType
.SAVE_UPDATE
})
49 protected Set
<Marker
> markers
= new HashSet
<Marker
>();
51 @XmlElementWrapper(name
= "Annotations")
52 @XmlElement(name
= "Annotation")
53 @OneToMany(fetch
=FetchType
.LAZY
)
54 @Cascade({CascadeType
.SAVE_UPDATE
})
55 protected Set
<Annotation
> annotations
= new HashSet
<Annotation
>();
57 protected AnnotatableEntity() {
61 //*************** MARKER **********************************************
64 public Set
<Marker
> getMarkers(){
67 public void addMarker(Marker marker
){
69 marker
.setMarkedObj(this);
73 public void removeMarker(Marker marker
){
74 marker
.setMarkedObj(null);
77 //*************** ANNOTATIONS **********************************************
79 public Set
<Annotation
> getAnnotations(){
80 return this.annotations
;
82 public void addAnnotation(Annotation annotation
){
83 if (annotation
!= null){
84 annotation
.setAnnotatedObj(this);
85 annotations
.add(annotation
);
89 public void removeAnnotation(Annotation annotation
){
90 this.annotations
.remove(annotation
);
91 annotation
.setAnnotatedObj(null);
94 //********************** CLONE *****************************************/
97 * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
100 public Object
clone() throws CloneNotSupportedException
{
101 AnnotatableEntity result
= (AnnotatableEntity
)super.clone();
104 result
.annotations
= new HashSet
<Annotation
>();
105 for (Annotation annotation
: this.annotations
){
106 Annotation newAnnotation
= (Annotation
)annotation
.clone();
107 result
.addAnnotation(newAnnotation
);
111 result
.markers
= new HashSet
<Marker
>();
112 for (Marker marker
: this.markers
){
113 Marker newMarker
= (Marker
)marker
.clone();
114 result
.addMarker(newMarker
);