2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.media
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
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
;
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
;
39 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
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.
50 * @created 08-Nov-2007 13:06:34
52 @XmlAccessorType(XmlAccessType
.FIELD
)
53 @XmlType(name
= "MediaRepresentation", propOrder
= {
57 "mediaRepresentationParts"
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);
66 //http://www.iana.org/assignments/media-types
67 @XmlElement(name
= "MimeType")
68 private String mimeType
;
70 //the file suffix (e.g. jpg, tif, mov)
71 @XmlElement(name
= "Suffix")
72 private String suffix
;
74 @XmlElement(name
= "Media")
76 @XmlSchemaType(name
= "IDREF")
77 @ManyToOne(fetch
= FetchType
.LAZY
)
78 @Cascade(CascadeType
.SAVE_UPDATE
)
81 @XmlElementWrapper(name
= "MediaRepresentationParts")
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)
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
>();
97 public static MediaRepresentation
NewInstance(String mimeType
, String suffix
){
98 MediaRepresentation result
= new MediaRepresentation();
99 result
.setMimeType(mimeType
);
100 result
.setSuffix(suffix
);
110 public static MediaRepresentation
NewInstance(){
111 logger
.debug("NewInstance");
112 return new MediaRepresentation();
117 protected MediaRepresentation(){
121 /*************** getter /setter *************************************/
124 public String
getMimeType(){
125 return this.mimeType
;
130 * @param mimeType mimeType
132 public void setMimeType(String mimeType
){
133 this.mimeType
= mimeType
;
137 public String
getSuffix(){
143 * @param mimeType mimeType
145 public void setSuffix(String suffix
){
146 this.suffix
= suffix
;
149 public Media
getMedia() {
153 @Deprecated //use only for bidirectional and hibernate
154 protected void setMedia(Media media
) {
159 public List
<MediaRepresentationPart
> getParts(){
160 return this.mediaRepresentationParts
;
163 @SuppressWarnings("deprecation")
164 public void addRepresentationPart(MediaRepresentationPart mediaRepresentationPart
){
165 if (mediaRepresentationPart
!= null){
166 this.getParts().add(mediaRepresentationPart
);
167 mediaRepresentationPart
.setMediaRepresentation(this);
170 @SuppressWarnings("deprecation")
171 public void removeRepresentationPart(MediaRepresentationPart representationPart
){
172 this.getParts().remove(representationPart
);
173 if (representationPart
!= null){
174 representationPart
.setMediaRepresentation(null);