Project

General

Profile

Download (5.8 KB) Statistics
| Branch: | Tag: | Revision:
1 d5e92940 Andreas Müller
/**
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 c76ef9e7 Andreas Müller
import java.util.HashMap;
15
import java.util.HashSet;
16 d5e92940 Andreas Müller
import java.util.List;
17 64c4a14d a.babadshanjan
18 6252a601 Andreas Müller
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 64c4a14d a.babadshanjan
import javax.xml.bind.annotation.XmlAccessType;
26
import javax.xml.bind.annotation.XmlAccessorType;
27 0ae18eec a.babadshanjan
import javax.xml.bind.annotation.XmlElement;
28
import javax.xml.bind.annotation.XmlElementWrapper;
29 64c4a14d a.babadshanjan
import javax.xml.bind.annotation.XmlElements;
30 ee91bcd9 ben.clark
import javax.xml.bind.annotation.XmlIDREF;
31
import javax.xml.bind.annotation.XmlSchemaType;
32 64c4a14d a.babadshanjan
import javax.xml.bind.annotation.XmlType;
33 d5e92940 Andreas Müller
34 6252a601 Andreas Müller
import org.apache.log4j.Logger;
35
import org.hibernate.annotations.Cascade;
36
import org.hibernate.annotations.CascadeType;
37
import org.hibernate.annotations.IndexColumn;
38 ee91bcd9 ben.clark
import org.hibernate.envers.Audited;
39 6252a601 Andreas Müller
40 c76ef9e7 Andreas Müller
import eu.etaxonomy.cdm.model.common.Language;
41
import eu.etaxonomy.cdm.model.common.LanguageString;
42 6252a601 Andreas Müller
import eu.etaxonomy.cdm.model.common.VersionableEntity;
43
44 d5e92940 Andreas Müller
/**
45 6252a601 Andreas Müller
 * 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 d5e92940 Andreas Müller
 * @author m.doering
52
 * @version 1.0
53
 * @created 08-Nov-2007 13:06:34
54
 */
55 64c4a14d a.babadshanjan
@XmlAccessorType(XmlAccessType.FIELD)
56
@XmlType(name = "MediaRepresentation", propOrder = {
57
	"mimeType",
58 a2d95d6e a.babadshanjan
    "suffix",
59 ee91bcd9 ben.clark
    "media",
60 a2d95d6e a.babadshanjan
    "mediaRepresentationParts"
61 64c4a14d a.babadshanjan
})
62 d5e92940 Andreas Müller
@Entity
63 ee91bcd9 ben.clark
@Audited
64 d5e92940 Andreas Müller
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
65 c76ef9e7 Andreas Müller
public class MediaRepresentation extends VersionableEntity implements Cloneable{
66 b3730261 Andreas Müller
	private static final long serialVersionUID = -1520078266008619806L;
67 d5e92940 Andreas Müller
	private static final Logger logger = Logger.getLogger(MediaRepresentation.class);
68 0ae18eec a.babadshanjan
	
69 d5e92940 Andreas Müller
	//http://www.iana.org/assignments/media-types
70 0ae18eec a.babadshanjan
	@XmlElement(name = "MimeType")
71 d5e92940 Andreas Müller
	private String mimeType;
72 0ae18eec a.babadshanjan
	
73 d5e92940 Andreas Müller
	//the file suffix (e.g. jpg, tif, mov)
74 0ae18eec a.babadshanjan
	@XmlElement(name = "Suffix")
75 d5e92940 Andreas Müller
	private String suffix;
76 0ae18eec a.babadshanjan
	
77 ee91bcd9 ben.clark
	@XmlElement(name = "Media")
78
	@XmlIDREF
79
	@XmlSchemaType(name = "IDREF")
80
	@ManyToOne(fetch = FetchType.LAZY)
81
	@Cascade(CascadeType.SAVE_UPDATE)
82 d5e92940 Andreas Müller
	private Media media;
83 0ae18eec a.babadshanjan
	
84 3b54d0c9 a.babadshanjan
	@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 7b193710 m.geoffroy
        @XmlElement(name = "MovieFile", namespace = "http://etaxonomy.eu/cdm/model/media/1.0", type = MovieFile.class)
89 3b54d0c9 a.babadshanjan
    })
90 ee91bcd9 ben.clark
    @OneToMany (cascade = {javax.persistence.CascadeType.ALL}, fetch= FetchType.LAZY)
91
	@IndexColumn(name="sortIndex", base = 0)
92
	@JoinColumn (name = "representation_id",  nullable=false)
93 a641fad9 ben.clark
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE, CascadeType.DELETE_ORPHAN})
94 d5e92940 Andreas Müller
	private List<MediaRepresentationPart> mediaRepresentationParts = new ArrayList<MediaRepresentationPart>();
95 9e645ae4 n.hoffmann
		
96 d5e92940 Andreas Müller
	/**
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 b3730261 Andreas Müller
		logger.debug("NewInstance");
115 d5e92940 Andreas Müller
		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 ee91bcd9 ben.clark
166 b3730261 Andreas Müller
	@SuppressWarnings("deprecation")
167 d5e92940 Andreas Müller
	public void addRepresentationPart(MediaRepresentationPart mediaRepresentationPart){
168
		if (mediaRepresentationPart != null){
169
			this.getParts().add(mediaRepresentationPart);
170
			mediaRepresentationPart.setMediaRepresentation(this);
171
		}
172
	}
173 b3730261 Andreas Müller
	@SuppressWarnings("deprecation")
174 d5e92940 Andreas Müller
	public void removeRepresentationPart(MediaRepresentationPart representationPart){
175
		this.getParts().remove(representationPart);
176
		if (representationPart != null){
177
			representationPart.setMediaRepresentation(null);
178
		}
179
	}
180
	
181 c76ef9e7 Andreas Müller
//************************* 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 d5e92940 Andreas Müller
	
202
	
203
204
}