Project

General

Profile

Download (5.8 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

    
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.List;
17

    
18
import javax.persistence.Entity;
19
import javax.persistence.FetchType;
20
import javax.persistence.Inheritance;
21
import javax.persistence.InheritanceType;
22
import javax.persistence.JoinColumn;
23
import javax.persistence.ManyToOne;
24
import javax.persistence.OneToMany;
25
import javax.xml.bind.annotation.XmlAccessType;
26
import javax.xml.bind.annotation.XmlAccessorType;
27
import javax.xml.bind.annotation.XmlElement;
28
import javax.xml.bind.annotation.XmlElementWrapper;
29
import javax.xml.bind.annotation.XmlElements;
30
import javax.xml.bind.annotation.XmlIDREF;
31
import javax.xml.bind.annotation.XmlSchemaType;
32
import javax.xml.bind.annotation.XmlType;
33

    
34
import org.apache.log4j.Logger;
35
import org.hibernate.annotations.Cascade;
36
import org.hibernate.annotations.CascadeType;
37
import org.hibernate.annotations.IndexColumn;
38
import org.hibernate.envers.Audited;
39

    
40
import eu.etaxonomy.cdm.model.common.Language;
41
import eu.etaxonomy.cdm.model.common.LanguageString;
42
import eu.etaxonomy.cdm.model.common.VersionableEntity;
43

    
44
/**
45
 * A media representation is basically anything having a <a
46
 * href="http://iana.org/assignments/media-types/">MIME Media Type</a>. A media
47
 * representation consists of one or more parts. Each of them having the same
48
 * MIME Type, file suffix (if existing) and quality (more or less).
49
 * E.g. a list of jpg files that represent a scanned article of multiple pages.
50
 * 
51
 * @author m.doering
52
 * @version 1.0
53
 * @created 08-Nov-2007 13:06:34
54
 */
55
@XmlAccessorType(XmlAccessType.FIELD)
56
@XmlType(name = "MediaRepresentation", propOrder = {
57
	"mimeType",
58
    "suffix",
59
    "media",
60
    "mediaRepresentationParts"
61
})
62
@Entity
63
@Audited
64
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
65
public class MediaRepresentation extends VersionableEntity implements Cloneable{
66
	private static final long serialVersionUID = -1520078266008619806L;
67
	private static final Logger logger = Logger.getLogger(MediaRepresentation.class);
68
	
69
	//http://www.iana.org/assignments/media-types
70
	@XmlElement(name = "MimeType")
71
	private String mimeType;
72
	
73
	//the file suffix (e.g. jpg, tif, mov)
74
	@XmlElement(name = "Suffix")
75
	private String suffix;
76
	
77
	@XmlElement(name = "Media")
78
	@XmlIDREF
79
	@XmlSchemaType(name = "IDREF")
80
	@ManyToOne(fetch = FetchType.LAZY)
81
	@Cascade(CascadeType.SAVE_UPDATE)
82
	private Media media;
83
	
84
	@XmlElementWrapper(name = "MediaRepresentationParts")
85
    @XmlElements({
86
        @XmlElement(name = "AudioFile", namespace = "http://etaxonomy.eu/cdm/model/media/1.0", type = AudioFile.class),
87
        @XmlElement(name = "ImageFile", namespace = "http://etaxonomy.eu/cdm/model/media/1.0", type = ImageFile.class),
88
        @XmlElement(name = "MovieFile", namespace = "http://etaxonomy.eu/cdm/model/media/1.0", type = MovieFile.class)
89
    })
90
    @OneToMany (cascade = {javax.persistence.CascadeType.ALL}, fetch= FetchType.LAZY)
91
	@IndexColumn(name="sortIndex", base = 0)
92
	@JoinColumn (name = "representation_id",  nullable=false)
93
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE, CascadeType.DELETE_ORPHAN})
94
	private List<MediaRepresentationPart> mediaRepresentationParts = new ArrayList<MediaRepresentationPart>();
95
		
96
	/**
97
	 * Factory method
98
	 * @return
99
	 */
100
	public static MediaRepresentation NewInstance(String mimeType, String suffix){
101
		MediaRepresentation result  = new MediaRepresentation();
102
		result.setMimeType(mimeType);
103
		result.setSuffix(suffix);
104
		return result;
105
	}
106
	
107
	
108
	
109
	/**
110
	 * Factory method
111
	 * @return
112
	 */
113
	public static MediaRepresentation NewInstance(){
114
		logger.debug("NewInstance");
115
		return new MediaRepresentation();
116
	}
117
	
118
	
119
	
120
	protected MediaRepresentation(){
121
		super();
122
	}
123
	
124
/***************  getter /setter *************************************/
125
	
126
	
127
	public String getMimeType(){
128
		return this.mimeType;
129
	}
130

    
131
	/**
132
	 * 
133
	 * @param mimeType    mimeType
134
	 */
135
	public void setMimeType(String mimeType){
136
		this.mimeType = mimeType;
137
	}
138

    
139
	
140
	public String getSuffix(){
141
		return this.suffix;
142
	}
143

    
144
	/**
145
	 * 
146
	 * @param mimeType    mimeType
147
	 */
148
	public void setSuffix(String suffix){
149
		this.suffix = suffix;
150
	}
151
	
152
	public Media getMedia() {
153
		return media;
154
	}
155

    
156
	@Deprecated //use only for bidirectional and hibernate
157
	protected void setMedia(Media media) {
158
		this.media = media;
159
	}
160
	
161
	
162
	public List<MediaRepresentationPart> getParts(){
163
		return this.mediaRepresentationParts;
164
	}
165

    
166
	@SuppressWarnings("deprecation")
167
	public void addRepresentationPart(MediaRepresentationPart mediaRepresentationPart){
168
		if (mediaRepresentationPart != null){
169
			this.getParts().add(mediaRepresentationPart);
170
			mediaRepresentationPart.setMediaRepresentation(this);
171
		}
172
	}
173
	@SuppressWarnings("deprecation")
174
	public void removeRepresentationPart(MediaRepresentationPart representationPart){
175
		this.getParts().remove(representationPart);
176
		if (representationPart != null){
177
			representationPart.setMediaRepresentation(null);
178
		}
179
	}
180
	
181
//************************* CLONE **************************/
182
		/* (non-Javadoc)
183
	 * @see java.lang.Object#clone()
184
	 */
185
	@Override
186
	public Object clone() throws CloneNotSupportedException{
187
		MediaRepresentation result = (MediaRepresentation)super.clone();
188

    
189
		//media representations
190
		result.mediaRepresentationParts = new ArrayList<MediaRepresentationPart>();
191
		for (MediaRepresentationPart mediaRepresentationPart: this.mediaRepresentationParts){
192
			result.mediaRepresentationParts.add((MediaRepresentationPart)mediaRepresentationPart.clone());
193
		}
194
		//media
195
		//this.getMedia().addRepresentation(result);
196
		this.setMedia(null);
197
		
198
		//no changes to: mimeType, suffix
199
		return result;
200
	}	
201
	
202
	
203

    
204
}
(7-7/13)