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 org
.apache
.log4j
.Logger
;
13 import org
.hibernate
.annotations
.Cascade
;
14 import org
.hibernate
.annotations
.CascadeType
;
18 import javax
.persistence
.*;
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
;
26 * Abstract superclass implementing human annotations and machine markers to be assigned to CDM objects.
29 * @created 08-Nov-2007 13:06:10
31 @XmlAccessorType(XmlAccessType
.FIELD
)
32 @XmlType(name
= "AnnotatableEntity", propOrder
= {
37 public abstract class AnnotatableEntity
<T
extends AnnotatableEntity
> extends VersionableEntity
<T
> {
38 private static final long serialVersionUID
= 9151211842542443102L;
39 @SuppressWarnings("unused")
40 private static final Logger logger
= Logger
.getLogger(AnnotatableEntity
.class);
42 @XmlElementWrapper(name
= "Markers")
43 @XmlElement(name
= "Marker")
44 protected Set
<Marker
> markers
= getNewMarkerSet();
46 @XmlElementWrapper(name
= "Annotations")
47 @XmlElement(name
= "Annotation")
48 protected Set
<Annotation
> annotations
= getNewAnnotationSet();
50 protected AnnotatableEntity() {
54 //*************** MARKER **********************************************
57 @OneToMany(fetch
=FetchType
.LAZY
)
58 @Cascade({CascadeType
.SAVE_UPDATE
})
59 public Set
<Marker
> getMarkers(){
62 public void addMarker(Marker marker
){
64 marker
.setMarkedObj(this);
68 public void removeMarker(Marker marker
){
69 marker
.setMarkedObj(null);
71 protected void setMarkers(Set
<Marker
> markers
) {
72 this.markers
= markers
;
75 //*************** ANNOTATIONS **********************************************
77 @OneToMany(fetch
=FetchType
.LAZY
) //(mappedBy="AnnotatedObj")
78 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.DELETE
})
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 protected void setAnnotations(Set
<Annotation
> annotations
) {
95 this.annotations
= annotations
;
98 //********************** CLONE *****************************************/
101 * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
104 public Object
clone() throws CloneNotSupportedException
{
105 AnnotatableEntity result
= (AnnotatableEntity
)super.clone();
108 Set
<Annotation
> newAnnotations
= getNewAnnotationSet();
109 for (Annotation annotation
: this.annotations
){
110 Annotation newExtension
= annotation
.clone(this);
111 newAnnotations
.add(newExtension
);
113 result
.setAnnotations(newAnnotations
);
117 Set
<Marker
> newMarkers
= getNewMarkerSet();
118 for (Marker marker
: this.markers
){
119 Marker newMarker
= marker
.clone(this);
120 newMarkers
.add(newMarker
);
122 result
.setMarkers(newMarkers
);
129 private Set
<Annotation
> getNewAnnotationSet(){
130 return new HashSet
<Annotation
>();
134 private Set
<Marker
> getNewMarkerSet(){
135 return new HashSet
<Marker
>();