Project

General

Profile

Download (6.01 KB) Statistics
| Branch: | Tag: | Revision:
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.common;
11

    
12
import java.net.URI;
13
import java.net.URISyntaxException;
14

    
15
import javax.persistence.Column;
16
import javax.persistence.Entity;
17
import javax.persistence.FetchType;
18
import javax.persistence.JoinColumn;
19
import javax.persistence.ManyToOne;
20
import javax.xml.bind.annotation.XmlAccessType;
21
import javax.xml.bind.annotation.XmlAccessorType;
22
import javax.xml.bind.annotation.XmlElement;
23
import javax.xml.bind.annotation.XmlIDREF;
24
import javax.xml.bind.annotation.XmlSchemaType;
25
import javax.xml.bind.annotation.XmlType;
26

    
27
import org.apache.commons.lang.StringUtils;
28
import org.apache.log4j.Logger;
29
import org.hibernate.annotations.Any;
30
import org.hibernate.annotations.Cascade;
31
import org.hibernate.annotations.CascadeType;
32
import org.hibernate.annotations.Type;
33
import org.hibernate.envers.Audited;
34
import org.hibernate.envers.NotAudited;
35

    
36
import eu.etaxonomy.cdm.model.agent.Person;
37

    
38
/**
39
 * @author m.doering
40
 * @version 1.0
41
 * @created 08-Nov-2007 13:06:10
42
 */
43
@XmlAccessorType(XmlAccessType.FIELD)
44
@XmlType(name = "Annotation", propOrder = {
45
    "commentator",
46
    "annotatedObj",
47
    "annotationType",
48
    "linkbackUri"
49
})
50
@Entity
51
@Audited
52
public class Annotation extends LanguageStringBase implements Cloneable {
53
	private static final long serialVersionUID = -4484677078599520233L;
54
	@SuppressWarnings("unused")
55
	private static final Logger logger = Logger.getLogger(Annotation.class);
56

    
57

    
58
	/**
59
	 * Factory method.
60
	 * @param text
61
	 * @param lang
62
	 * @return
63
	 */
64
	public static Annotation NewInstance(String text, Language lang){
65
		return new Annotation(text, lang);
66
	}
67

    
68
	public static Annotation NewInstance(String text, AnnotationType annotationType, Language lang){
69
		Annotation annotation = new Annotation(text, lang);
70
		annotation.setAnnotationType(annotationType);
71
		return annotation;
72
	}
73

    
74
	/**
75
	 * Factory method. Using default language.
76
	 * @param text
77
	 * @return
78
	 */
79
	public static Annotation NewDefaultLanguageInstance(String text){
80
		return new Annotation(text, Language.DEFAULT());
81
	}
82

    
83

    
84
	//Human annotation
85
	@XmlElement(name = "Commentator")
86
    @XmlIDREF
87
    @XmlSchemaType(name = "IDREF")
88
    @ManyToOne(fetch = FetchType.LAZY)
89
    @Cascade(CascadeType.SAVE_UPDATE)
90
	private Person commentator;
91

    
92
	@XmlElement(name = "AnnotatedObject")
93
    @XmlIDREF
94
    @XmlSchemaType(name = "IDREF")
95
    @Any(metaDef = "CdmBase",
96
	    	 metaColumn=@Column(name = "annotatedObj_type"),
97
	    	 fetch = FetchType.EAGER,
98
	    	 optional = false)
99
	@JoinColumn(name = "annotatedObj_id")
100
	@NotAudited
101
	private AnnotatableEntity annotatedObj;
102

    
103
    @XmlElement(name = "AnnotationType")
104
    @XmlIDREF
105
    @XmlSchemaType(name = "IDREF")
106
    @ManyToOne(fetch = FetchType.LAZY)
107
	private AnnotationType annotationType;
108

    
109
	// for external annotations/comments the URL of these can be set.
110
	// should be useful to implement trackback, pingback or linkback:
111
	// http://en.wikipedia.org/wiki/Linkback
112
	@XmlElement(name = "LinkbackUri")
113
	@Type(type="uriUserType")
114
	private URI linkbackUri;
115

    
116
	
117
// *********** CONSTRUCTOR **************************************/
118
	
119
	protected Annotation(){
120
		super();
121
	}
122

    
123
	/**
124
	 * Constructor
125
	 * @param text
126
	 * @param lang
127
	 */
128
	protected Annotation(String text, Language language) {
129
		super(text, language);
130
	}
131

    
132
//******************** GETTER /SETTER *************************/	
133
	
134

    
135
	/**
136
	 * Currently envers does not support @Any
137
	 * @return
138
	 */
139
	public AnnotatableEntity getAnnotatedObj() {
140
		return annotatedObj;
141
	}
142
	
143
	//TODO make not public, but TaxonTaoHibernateImpl.delete has to be changed then
144
	/**
145
	 *
146
	 * @param newAnnotatedObj
147
	 * @deprecated should not be used, is only public for internal reasons
148
	 */
149
	@Deprecated
150
	public void setAnnotatedObj(AnnotatableEntity newAnnotatedObj) {
151
		this.annotatedObj = newAnnotatedObj;
152
	}
153

    
154
	public AnnotationType getAnnotationType() {
155
		return annotationType;
156
	}
157

    
158
	public void setAnnotationType(AnnotationType annotationType) {
159
		this.annotationType = annotationType;
160
	}
161

    
162
	public Person getCommentator(){
163
		return this.commentator;
164
	}
165
	public void setCommentator(Person commentator){
166
		this.commentator = commentator;
167
	}
168

    
169

    
170
	public URI getLinkbackUri() {
171
		return linkbackUri;
172
	}
173
	public void setLinkbackUri(URI linkbackUri) {
174
		this.linkbackUri = linkbackUri;
175
	}
176

    
177
	/**
178
	 * private get/set methods for Hibernate that allows us to save the URL as strings
179
	 * @return
180
	 */
181
	private String getLinkbackUriStr() {
182
		if (linkbackUri == null){
183
			return null;
184
		}
185
		return linkbackUri.toString();
186
	}
187
	private void setLinkbackUriStr(String linkbackUriString) {
188
		if (linkbackUriString == null){
189
			this.linkbackUri = null;
190
		}else{
191
			try {
192
				this.linkbackUri = new URI(linkbackUriString);
193
			} catch (URISyntaxException e) {
194
                // TODO Auto-generated catch block
195
                e.printStackTrace();
196
            }
197
		}
198
	}
199

    
200
// ***************************** TO STRING ***********************************
201

    
202

    
203
	/* (non-Javadoc)
204
	 * @see eu.etaxonomy.cdm.model.common.CdmBase#toString()
205
	 */
206
	@Override
207
	public String toString() {
208
		if (StringUtils.isNotBlank(this.text)){
209
			return "Ann.: " + this.text;
210
		}else{
211
			return super.toString();
212
		}
213
	}
214

    
215

    
216

    
217
//****************** CLONE ************************************************/
218

    
219
	/* (non-Javadoc)
220
	 * @see java.lang.Object#clone()
221
	 */
222
	@Override
223
	public Object clone() throws CloneNotSupportedException{
224
		Annotation result = (Annotation)super.clone();
225
		result.setCommentator(this.getCommentator());
226
		result.setAnnotationType(this.getAnnotationType());
227
		result.setLinkbackUri(this.linkbackUri);
228
		return result;
229
	}
230

    
231

    
232
	/**
233
	 * Clones this annotation and sets the clone's annotated object to 'annotatedObject'
234
	 * @see java.lang.Object#clone()
235
	 */
236
	public Annotation clone(AnnotatableEntity annotatedObject) throws CloneNotSupportedException{
237
		Annotation result = (Annotation)clone();
238
		result.setAnnotatedObj(annotatedObject);
239
		return result;
240
	}
241
}
(3-3/70)