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