3261aa827c2385c166e04af342320711c70aeaa1
[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 import java.util.Set;
16 import java.util.SortedSet;
17 import java.util.TreeSet;
18
19 import org.apache.log4j.Logger;
20 import org.hibernate.annotations.Cascade;
21 import org.hibernate.annotations.CascadeType;
22
23 import eu.etaxonomy.cdm.model.common.VersionableEntity;
24 import javax.persistence.*;
25
26 /**
27 * metadata for an external file such as images, phylogenetic trees, or audio
28 * recordings available through the location attribute!
29 * @author m.doering
30 * @version 1.0
31 * @created 08-Nov-2007 13:06:34
32 */
33 @Entity
34 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
35 public class MediaRepresentation extends VersionableEntity {
36 private static final Logger logger = Logger.getLogger(MediaRepresentation.class);
37 //http://www.iana.org/assignments/media-types
38 private String mimeType;
39 //the file suffix (e.g. jpg, tif, mov)
40 private String suffix;
41 private Media media;
42 private List<MediaRepresentationPart> mediaRepresentationParts = new ArrayList<MediaRepresentationPart>();
43
44
45 /**
46 * Factory method
47 * @return
48 */
49 public static MediaRepresentation NewInstance(String mimeType, String suffix){
50 MediaRepresentation result = new MediaRepresentation();
51 result.setMimeType(mimeType);
52 result.setSuffix(suffix);
53 return result;
54 }
55
56
57
58 /**
59 * Factory method
60 * @return
61 */
62 public static MediaRepresentation NewInstance(){
63 return new MediaRepresentation();
64 }
65
66
67
68 protected MediaRepresentation(){
69 super();
70 }
71
72 /*************** getter /setter *************************************/
73
74
75 public String getMimeType(){
76 return this.mimeType;
77 }
78
79 /**
80 *
81 * @param mimeType mimeType
82 */
83 public void setMimeType(String mimeType){
84 this.mimeType = mimeType;
85 }
86
87
88 public String getSuffix(){
89 return this.suffix;
90 }
91
92 /**
93 *
94 * @param mimeType mimeType
95 */
96 public void setSuffix(String suffix){
97 this.suffix = suffix;
98 }
99
100 @ManyToOne
101 public Media getMedia() {
102 return media;
103 }
104
105 @Deprecated //use only for bidirectional and hibernate
106 protected void setMedia(Media media) {
107 this.media = media;
108 }
109
110
111 @OneToMany(mappedBy="mediaRepresentation")
112 @org.hibernate.annotations.IndexColumn(name="sortIndex")
113 @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
114 public List<MediaRepresentationPart> getParts(){
115 return this.mediaRepresentationParts;
116 }
117 protected void setParts(List<MediaRepresentationPart> mediaRepresentationParts){
118 this.mediaRepresentationParts = mediaRepresentationParts;
119 }
120 public void addRepresentationPart(MediaRepresentationPart mediaRepresentationPart){
121 if (mediaRepresentationPart != null){
122 this.getParts().add(mediaRepresentationPart);
123 mediaRepresentationPart.setMediaRepresentation(this);
124 }
125 }
126 public void removeRepresentationPart(MediaRepresentationPart representationPart){
127 this.getParts().remove(representationPart);
128 if (representationPart != null){
129 representationPart.setMediaRepresentation(null);
130 }
131 }
132
133
134
135
136 }