1
|
package eu.etaxonomy.cdm.model.media;
|
2
|
|
3
|
import java.util.HashSet;
|
4
|
import java.util.Set;
|
5
|
|
6
|
import javax.persistence.FetchType;
|
7
|
import javax.persistence.ManyToMany;
|
8
|
import javax.persistence.MappedSuperclass;
|
9
|
import javax.xml.bind.annotation.XmlAccessType;
|
10
|
import javax.xml.bind.annotation.XmlAccessorType;
|
11
|
import javax.xml.bind.annotation.XmlElement;
|
12
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
13
|
import javax.xml.bind.annotation.XmlIDREF;
|
14
|
import javax.xml.bind.annotation.XmlSchemaType;
|
15
|
import javax.xml.bind.annotation.XmlType;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.hibernate.annotations.Cascade;
|
19
|
import org.hibernate.annotations.CascadeType;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
22
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
23
|
import eu.etaxonomy.cdm.strategy.merge.Merge;
|
24
|
import eu.etaxonomy.cdm.strategy.merge.MergeMode;
|
25
|
|
26
|
@XmlAccessorType(XmlAccessType.FIELD)
|
27
|
@XmlType(name = "IdentifiableMediaEntity", propOrder = {
|
28
|
"media"
|
29
|
})
|
30
|
@MappedSuperclass
|
31
|
public abstract class IdentifiableMediaEntity<S extends IIdentifiableEntityCacheStrategy> extends IdentifiableEntity<S> implements IMediaDocumented, IMediaEntity{
|
32
|
|
33
|
private static final long serialVersionUID = 4038647011021908313L;
|
34
|
|
35
|
protected static Logger logger = Logger.getLogger(IdentifiableMediaEntity.class);
|
36
|
|
37
|
@XmlElementWrapper(name = "Media")
|
38
|
@XmlElement(name = "Medium")
|
39
|
@XmlIDREF
|
40
|
@XmlSchemaType(name = "IDREF")
|
41
|
@ManyToMany(fetch = FetchType.LAZY)
|
42
|
@Cascade({CascadeType.SAVE_UPDATE})
|
43
|
//TODO
|
44
|
@Merge(MergeMode.ADD_CLONE)
|
45
|
private Set<Media> media = new HashSet<Media>();
|
46
|
|
47
|
|
48
|
/* (non-Javadoc)
|
49
|
* @see eu.etaxonomy.cdm.model.media.IMediaEntity#getMedia()
|
50
|
*/
|
51
|
public Set<Media> getMedia() {
|
52
|
return media;
|
53
|
}
|
54
|
|
55
|
/* (non-Javadoc)
|
56
|
* @see eu.etaxonomy.cdm.model.media.IMediaEntity#addMedia(eu.etaxonomy.cdm.model.media.Media)
|
57
|
*/
|
58
|
public void addMedia(Media media) {
|
59
|
this.media.add(media);
|
60
|
}
|
61
|
/* (non-Javadoc)
|
62
|
* @see eu.etaxonomy.cdm.model.media.IMediaEntity#removeMedia(eu.etaxonomy.cdm.model.media.Media)
|
63
|
*/
|
64
|
public void removeMedia(Media media) {
|
65
|
this.media.remove(media);
|
66
|
}
|
67
|
|
68
|
//******************** CLONE **********************************************/
|
69
|
|
70
|
/* (non-Javadoc)
|
71
|
* @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#clone()
|
72
|
*/
|
73
|
@Override
|
74
|
public Object clone() throws CloneNotSupportedException{
|
75
|
IdentifiableMediaEntity result = (IdentifiableMediaEntity)super.clone();
|
76
|
//Media
|
77
|
result.media = new HashSet<Media>();
|
78
|
for(Media media : this.media) {
|
79
|
result.addMedia(media);
|
80
|
}
|
81
|
//no changes to: -
|
82
|
return result;
|
83
|
}
|
84
|
|
85
|
}
|