Minor changes to media API. Old methods have been set to deprecated.
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / media / MediaRepresentationPart.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 import javax.persistence.Entity;
13 import javax.persistence.FetchType;
14 import javax.persistence.JoinColumn;
15 import javax.persistence.ManyToOne;
16 import javax.xml.bind.annotation.XmlAccessType;
17 import javax.xml.bind.annotation.XmlAccessorType;
18 import javax.xml.bind.annotation.XmlElement;
19 import javax.xml.bind.annotation.XmlIDREF;
20 import javax.xml.bind.annotation.XmlSchemaType;
21 import javax.xml.bind.annotation.XmlType;
22
23 import org.apache.log4j.Logger;
24 import org.hibernate.annotations.Cascade;
25 import org.hibernate.annotations.CascadeType;
26 import org.hibernate.envers.Audited;
27
28 import eu.etaxonomy.cdm.model.common.VersionableEntity;
29
30 /**
31 * A media representation part is a resource that can be referenced by an URI.
32 * It represents a part of or the entire media. <br>
33 * E.g. a jpg file or a website
34 *
35 * @author a.mueller
36 * @created 09.06.2008
37 * @version 1.0
38 */
39 @XmlAccessorType(XmlAccessType.FIELD)
40 @XmlType(name = "MediaRepresentationPart", propOrder = {
41 "uri",
42 "size",
43 "mediaRepresentation"
44 })
45 @Entity
46 @Audited
47 public class MediaRepresentationPart extends VersionableEntity implements Cloneable{
48 private static final long serialVersionUID = -1674422508643785796L;
49 private static final Logger logger = Logger.getLogger(MediaRepresentationPart.class);
50
51 // where the media file is stored
52 @XmlElement(name = "URI")
53 private String uri;
54
55 // in bytes
56 @XmlElement(name = "Size")
57 private Integer size;
58
59 // the MediaRepresentation of this MediaRepresentationPart
60 @XmlElement(name = "MediaRepresentation")
61 @XmlIDREF
62 @XmlSchemaType(name = "IDREF")
63 @ManyToOne(fetch = FetchType.LAZY)
64 @JoinColumn(name = "representation_id", nullable = false, updatable = false, insertable = false)
65 @Cascade(CascadeType.SAVE_UPDATE)
66 private MediaRepresentation mediaRepresentation;
67
68 /**
69 * Factory method
70 *
71 * @return
72 */
73 public static MediaRepresentationPart NewInstance(String uri, Integer size) {
74 MediaRepresentationPart result = new MediaRepresentationPart(uri, size);
75 return result;
76 }
77
78 /**
79 *
80 */
81 protected MediaRepresentationPart() {
82 super();
83 }
84
85 /**
86 *
87 */
88 protected MediaRepresentationPart(String uri, Integer size) {
89 this();
90 this.setUri(uri);
91 this.setSize(size);
92 }
93
94 /*************** getter /setter *************************************/
95
96 public MediaRepresentation getMediaRepresentation() {
97 return this.mediaRepresentation;
98 }
99
100 @Deprecated
101 // use only for bidirectional and hibernate
102 protected void setMediaRepresentation(
103 MediaRepresentation mediaRepresentation) {
104 this.mediaRepresentation = mediaRepresentation;
105 }
106
107 public String getUri() {
108 return this.uri;
109 }
110
111 /**
112 *
113 * @param uri
114 * uri
115 */
116 public void setUri(String uri) {
117 this.uri = uri;
118 }
119
120 /**
121 * @return
122 */
123 public Integer getSize() {
124 return this.size;
125 }
126
127 /**
128 * @param size
129 * size
130 */
131 public void setSize(Integer size) {
132 this.size = size;
133 }
134
135 //************************* CLONE **************************/
136 /* (non-Javadoc)
137 * @see java.lang.Object#clone()
138 */
139 @Override
140 public Object clone() throws CloneNotSupportedException{
141 MediaRepresentationPart result = (MediaRepresentationPart)super.clone();
142
143 //media representation
144 result.setMediaRepresentation(null);
145
146 //no changes to: size, ure
147 return result;
148 }
149
150
151 }