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 URI 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
|
// ***************************** TO STRING ***********************************
|
179
|
|
180
|
|
181
|
/* (non-Javadoc)
|
182
|
* @see eu.etaxonomy.cdm.model.common.CdmBase#toString()
|
183
|
*/
|
184
|
@Override
|
185
|
public String toString() {
|
186
|
if (StringUtils.isNotBlank(this.text)){
|
187
|
return "Ann.: " + this.text;
|
188
|
}else{
|
189
|
return super.toString();
|
190
|
}
|
191
|
}
|
192
|
|
193
|
|
194
|
|
195
|
//****************** CLONE ************************************************/
|
196
|
|
197
|
/* (non-Javadoc)
|
198
|
* @see java.lang.Object#clone()
|
199
|
*/
|
200
|
@Override
|
201
|
public Object clone() throws CloneNotSupportedException{
|
202
|
Annotation result = (Annotation)super.clone();
|
203
|
result.setCommentator(this.getCommentator());
|
204
|
result.setAnnotationType(this.getAnnotationType());
|
205
|
result.setLinkbackUri(this.linkbackUri);
|
206
|
return result;
|
207
|
}
|
208
|
|
209
|
|
210
|
/**
|
211
|
* Clones this annotation and sets the clone's annotated object to 'annotatedObject'
|
212
|
* @see java.lang.Object#clone()
|
213
|
*/
|
214
|
public Annotation clone(AnnotatableEntity annotatedObject) throws CloneNotSupportedException{
|
215
|
Annotation result = (Annotation)clone();
|
216
|
result.setAnnotatedObj(annotatedObject);
|
217
|
return result;
|
218
|
}
|
219
|
}
|