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
;
14 import java
.util
.UUID
;
16 import javax
.persistence
.FetchType
;
17 import javax
.persistence
.MappedSuperclass
;
18 import javax
.persistence
.OneToMany
;
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
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.hibernate
.annotations
.Cascade
;
27 import org
.hibernate
.annotations
.CascadeType
;
28 import org
.hibernate
.envers
.Audited
;
30 import eu
.etaxonomy
.cdm
.strategy
.merge
.Merge
;
31 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeMode
;
34 * Abstract superclass implementing human annotations and machine markers to be assigned to CDM objects.
37 * @created 08-Nov-2007 13:06:10
39 @XmlAccessorType(XmlAccessType
.FIELD
)
40 @XmlType(name
= "AnnotatableEntity", propOrder
= {
46 public abstract class AnnotatableEntity
extends VersionableEntity
implements IAnnotatableEntity
{
47 private static final long serialVersionUID
= 9151211842542443102L;
48 @SuppressWarnings("unused")
49 private static final Logger logger
= Logger
.getLogger(AnnotatableEntity
.class);
51 @XmlElementWrapper(name
= "Markers", nillable
= true)
52 @XmlElement(name
= "Marker")
53 @OneToMany(fetch
=FetchType
.LAZY
, orphanRemoval
=true)
54 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
})
55 @Merge(MergeMode
.ADD_CLONE
)
56 protected Set
<Marker
> markers
;
58 @XmlElementWrapper(name
= "Annotations", nillable
= true)
59 @XmlElement(name
= "Annotation")
60 @OneToMany(fetch
=FetchType
.LAZY
, orphanRemoval
=true)
61 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
, CascadeType
.DELETE
})
62 @Merge(MergeMode
.ADD_CLONE
)
63 protected Set
<Annotation
> annotations
;
65 protected AnnotatableEntity() {
69 //*************** MARKER **********************************************
72 public Set
<Marker
> getMarkers(){
74 this.markers
= new HashSet
<Marker
>();
78 public void addMarker(Marker marker
){
80 marker
.setMarkedObj(this);
81 getMarkers().add(marker
);
84 public void removeMarker(Marker marker
){
85 if(getMarkers().contains(marker
)) {
86 getMarkers().remove(marker
);
87 marker
.setMarkedObj(null);
91 public boolean hasMarker(MarkerType type
, boolean value
){
92 return hasMarker(type
.getUuid(), value
);
95 public boolean hasMarker(UUID uuidMarkerType
, boolean value
){
96 for (Marker marker
: getMarkers()){
97 if (marker
.getMarkerType().getUuid().equals(uuidMarkerType
)){
98 if (marker
.getFlag() == value
){
106 //*************** ANNOTATIONS **********************************************
108 public Set
<Annotation
> getAnnotations(){
109 if(annotations
== null) {
110 this.annotations
= new HashSet
<Annotation
>();
112 return this.annotations
;
114 public void addAnnotation(Annotation annotation
){
115 if (annotation
!= null){
116 annotation
.setAnnotatedObj(this);
117 getAnnotations().add(annotation
);
121 public void removeAnnotation(Annotation annotation
){
122 if(getAnnotations().contains(annotation
)) {
123 getAnnotations().remove(annotation
);
124 annotation
.setAnnotatedObj(null);
128 //********************** CLONE *****************************************/
131 * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
134 public Object
clone() throws CloneNotSupportedException
{
135 AnnotatableEntity result
= (AnnotatableEntity
)super.clone();
138 result
.annotations
= new HashSet
<Annotation
>();
139 for (Annotation annotation
: getAnnotations()){
140 Annotation newAnnotation
= (Annotation
)annotation
.clone();
141 result
.addAnnotation(newAnnotation
);
145 result
.markers
= new HashSet
<Marker
>();
146 for (Marker marker
: getMarkers()){
147 Marker newMarker
= (Marker
)marker
.clone();
148 result
.addMarker(newMarker
);