Committing large number of changes relating to versioning implementation (#108)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / media / MediaRepresentation.java
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.List;
15
16 import javax.persistence.Entity;
17 import javax.persistence.FetchType;
18 import javax.persistence.Inheritance;
19 import javax.persistence.InheritanceType;
20 import javax.persistence.JoinColumn;
21 import javax.persistence.ManyToOne;
22 import javax.persistence.OneToMany;
23 import javax.xml.bind.annotation.XmlAccessType;
24 import javax.xml.bind.annotation.XmlAccessorType;
25 import javax.xml.bind.annotation.XmlElement;
26 import javax.xml.bind.annotation.XmlElementWrapper;
27 import javax.xml.bind.annotation.XmlElements;
28 import javax.xml.bind.annotation.XmlIDREF;
29 import javax.xml.bind.annotation.XmlSchemaType;
30 import javax.xml.bind.annotation.XmlTransient;
31 import javax.xml.bind.annotation.XmlType;
32
33 import org.apache.log4j.Logger;
34 import org.hibernate.annotations.Cascade;
35 import org.hibernate.annotations.CascadeType;
36 import org.hibernate.annotations.IndexColumn;
37 import org.hibernate.envers.Audited;
38
39 import eu.etaxonomy.cdm.model.common.VersionableEntity;
40
41 /**
42 * A media representation is basically anything having a <a
43 * href="http://iana.org/assignments/media-types/">MIME Media Type</a>. A media
44 * representation consists of one or more parts. Each of them having the same
45 * MIME Type, file suffix (if existing) and quality (more or less).
46 * E.g. a list of jpg files that represent a scanned article of multiple pages.
47 *
48 * @author m.doering
49 * @version 1.0
50 * @created 08-Nov-2007 13:06:34
51 */
52 @XmlAccessorType(XmlAccessType.FIELD)
53 @XmlType(name = "MediaRepresentation", propOrder = {
54 "mimeType",
55 "suffix",
56 "media",
57 "mediaRepresentationParts"
58 })
59 @Entity
60 @Audited
61 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
62 public class MediaRepresentation extends VersionableEntity {
63 private static final long serialVersionUID = -1520078266008619806L;
64 private static final Logger logger = Logger.getLogger(MediaRepresentation.class);
65
66 //http://www.iana.org/assignments/media-types
67 @XmlElement(name = "MimeType")
68 private String mimeType;
69
70 //the file suffix (e.g. jpg, tif, mov)
71 @XmlElement(name = "Suffix")
72 private String suffix;
73
74 @XmlElement(name = "Media")
75 @XmlIDREF
76 @XmlSchemaType(name = "IDREF")
77 @ManyToOne(fetch = FetchType.LAZY)
78 @Cascade(CascadeType.SAVE_UPDATE)
79 private Media media;
80
81 @XmlElementWrapper(name = "MediaRepresentationParts")
82 @XmlElements({
83 @XmlElement(name = "AudioFile", namespace = "http://etaxonomy.eu/cdm/model/media/1.0", type = AudioFile.class),
84 @XmlElement(name = "ImageFile", namespace = "http://etaxonomy.eu/cdm/model/media/1.0", type = ImageFile.class),
85 @XmlElement(name = "MovieFile", namespace = "http://etaxonomy.eu/cdm/model/media/1.0", type = MovieFile.class)
86 })
87 @OneToMany (cascade = {javax.persistence.CascadeType.ALL}, fetch= FetchType.LAZY)
88 @IndexColumn(name="sortIndex", base = 0)
89 @JoinColumn (name = "representation_id", nullable=false)
90 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
91 private List<MediaRepresentationPart> mediaRepresentationParts = new ArrayList<MediaRepresentationPart>();
92
93 /**
94 * Factory method
95 * @return
96 */
97 public static MediaRepresentation NewInstance(String mimeType, String suffix){
98 MediaRepresentation result = new MediaRepresentation();
99 result.setMimeType(mimeType);
100 result.setSuffix(suffix);
101 return result;
102 }
103
104
105
106 /**
107 * Factory method
108 * @return
109 */
110 public static MediaRepresentation NewInstance(){
111 logger.debug("NewInstance");
112 return new MediaRepresentation();
113 }
114
115
116
117 protected MediaRepresentation(){
118 super();
119 }
120
121 /*************** getter /setter *************************************/
122
123
124 public String getMimeType(){
125 return this.mimeType;
126 }
127
128 /**
129 *
130 * @param mimeType mimeType
131 */
132 public void setMimeType(String mimeType){
133 this.mimeType = mimeType;
134 }
135
136
137 public String getSuffix(){
138 return this.suffix;
139 }
140
141 /**
142 *
143 * @param mimeType mimeType
144 */
145 public void setSuffix(String suffix){
146 this.suffix = suffix;
147 }
148
149 public Media getMedia() {
150 return media;
151 }
152
153 @Deprecated //use only for bidirectional and hibernate
154 protected void setMedia(Media media) {
155 this.media = media;
156 }
157
158
159 public List<MediaRepresentationPart> getParts(){
160 return this.mediaRepresentationParts;
161 }
162
163 @SuppressWarnings("deprecation")
164 public void addRepresentationPart(MediaRepresentationPart mediaRepresentationPart){
165 if (mediaRepresentationPart != null){
166 this.getParts().add(mediaRepresentationPart);
167 mediaRepresentationPart.setMediaRepresentation(this);
168 }
169 }
170 @SuppressWarnings("deprecation")
171 public void removeRepresentationPart(MediaRepresentationPart representationPart){
172 this.getParts().remove(representationPart);
173 if (representationPart != null){
174 representationPart.setMediaRepresentation(null);
175 }
176 }
177
178
179
180
181 }