Project

General

Profile

Download (5.96 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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 eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
13
import eu.etaxonomy.cdm.model.agent.AgentBase;
14
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
15
import eu.etaxonomy.cdm.model.common.IMultiLanguageText;
16
import eu.etaxonomy.cdm.model.common.Language;
17
import eu.etaxonomy.cdm.model.common.LanguageString;
18
import eu.etaxonomy.cdm.model.common.MultilanguageText;
19

    
20
import org.apache.log4j.Logger;
21
import org.hibernate.annotations.Cascade;
22
import org.hibernate.annotations.CascadeType;
23
import org.hibernate.envers.Audited;
24

    
25
import java.util.*;
26
import javax.persistence.*;
27
import javax.xml.bind.annotation.XmlAccessType;
28
import javax.xml.bind.annotation.XmlAccessorType;
29
import javax.xml.bind.annotation.XmlElement;
30
import javax.xml.bind.annotation.XmlElementWrapper;
31
import javax.xml.bind.annotation.XmlElements;
32
import javax.xml.bind.annotation.XmlIDREF;
33
import javax.xml.bind.annotation.XmlRootElement;
34
import javax.xml.bind.annotation.XmlSchemaType;
35
import javax.xml.bind.annotation.XmlType;
36
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
37

    
38
/**
39
 * A {@link Media media} is any kind of media that represents a media object. 
40
 * This media object can have multiple {@link MediaRepresentation media representations} that differ in MIME-type 
41
 * and/or quality. 
42
 * E.g. 
43
 * (1) an image can have a tiff and a jpg media representation. 
44
 * (2) an formatted text can have a text/html or an application/pdf representation. 
45
 * @author m.doering
46
 * @version 1.0
47
 * @created 08-Nov-2007 13:06:34
48
 */
49
@XmlAccessorType(XmlAccessType.FIELD)
50
@XmlType(name = "Media", propOrder = {
51
    "title",
52
    "mediaCreated",
53
    "description",
54
    "representations",
55
    "rights",
56
    "artist"
57
})
58
@XmlRootElement(name = "Media")
59
@Entity
60
@Audited
61
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
62
public class Media extends AnnotatableEntity {
63
	private static final long serialVersionUID = -1927421567263473658L;
64
	private static final Logger logger = Logger.getLogger(Media.class);
65

    
66
    // TODO once hibernate annotations support custom collection type
67
	// private MultilanguageText title = new MultilanguageText();
68
	@XmlElement(name = "MediaTitle")
69
    @XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
70
    @OneToMany(fetch = FetchType.LAZY)
71
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.DELETE})
72
	private Map<Language,LanguageString> title = new HashMap<Language,LanguageString>();
73
	
74
	//creation date of the media (not of the record)
75
	@XmlElement(name = "MediaCreated")
76
	@Temporal(TemporalType.DATE)
77
	private Calendar mediaCreated;
78
	
79
	 // TODO once hibernate annotations support custom collection type
80
	// private MultilanguageText description = new MultilanguageText();
81
	@XmlElement(name = "MediaDescription")
82
    @XmlJavaTypeAdapter(MultilanguageTextAdapter.class)
83
    @OneToMany(fetch = FetchType.LAZY)
84
    @JoinTable(name = "Media_Description")
85
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.DELETE})
86
	private Map<Language,LanguageString> description = new HashMap<Language,LanguageString>();
87
	
88
	//A single medium such as a picture can have multiple representations in files. 
89
	//Common are multiple resolutions or file formats for images for example
90
	@XmlElementWrapper(name = "MediaRepresentations")
91
	@XmlElement(name = "MediaRepresentation")
92
	@OneToMany(mappedBy="media",fetch = FetchType.LAZY)
93
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
94
	private Set<MediaRepresentation> representations = new HashSet<MediaRepresentation>();
95
	
96
	// FIXME should be OneToMany?
97
	@XmlElementWrapper(name = "Rights")
98
	@XmlElement(name = "Right")
99
	@ManyToMany(fetch = FetchType.LAZY)
100
	@Cascade({CascadeType.SAVE_UPDATE})
101
	private Set<Rights> rights = new HashSet<Rights>();
102
	
103
	@XmlElement(name = "Artist")
104
	@XmlIDREF
105
	@XmlSchemaType(name = "IDREF")
106
	@ManyToOne(fetch = FetchType.LAZY)
107
	@Cascade(CascadeType.SAVE_UPDATE)
108
	private AgentBase artist;
109

    
110
	/**
111
	 * Factory method
112
	 * @return
113
	 */
114
	public static Media NewInstance(){
115
		logger.debug("NewInstance");
116
		return new Media();
117
	}
118
	
119
	/**
120
	 * Constructor
121
	 */
122
	protected Media() {
123
		super();
124
	}
125

    
126
	public Set<MediaRepresentation> getRepresentations(){
127
		return this.representations;
128
	}
129

    
130
	@SuppressWarnings("deprecation")
131
	public void addRepresentation(MediaRepresentation representation){
132
		if (representation != null){
133
			this.getRepresentations().add(representation);
134
			representation.setMedia(this);
135
		}
136
	}
137
	
138
	@SuppressWarnings("deprecation")
139
	public void removeRepresentation(MediaRepresentation representation){
140
		this.getRepresentations().remove(representation);
141
		if (representation != null){
142
			representation.setMedia(null);
143
		}
144

    
145
	}
146

    
147
	public AgentBase getArtist(){
148
		return this.artist;
149
	}
150
	
151
	public void setArtist(AgentBase artist){
152
		this.artist = artist;
153
	}
154

    
155
	public Set<Rights> getRights(){
156
		return this.rights;
157
	}
158
	
159
	public void addRights(Rights rights){
160
		this.rights.add(rights);
161
	}
162
	
163
	public void removeRights(Rights rights){
164
		this.rights.remove(rights);
165
	}
166

    
167
	public Map<Language,LanguageString> getTitle(){
168
		return this.title;
169
	}
170
	
171
	public void addTitle(LanguageString title){
172
		this.title.put(title.getLanguage(), title);
173
	}
174
	
175
	public void removeTitle(Language language){
176
		this.title.remove(language);
177
	}
178

    
179
	public Calendar getMediaCreated(){
180
		return this.mediaCreated;
181
	}
182
	
183
	public void setMediaCreated(Calendar mediaCreated){
184
		this.mediaCreated = mediaCreated;
185
	}
186

    
187
	public Map<Language,LanguageString> getDescription(){
188
		return this.description;
189
	}
190
	
191
	public void addDescription(LanguageString description){
192
		this.description.put(description.getLanguage(),description);
193
	}
194
	
195
	public void addDescription(String text, Language language){
196
		this.description.put(language, LanguageString.NewInstance(text, language));
197
	}
198
	
199
	public void removeDescription(Language language){
200
		this.description.remove(language);
201
	}
202
}
(6-6/13)