1 |
9479da48
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
5d73efbd
|
Andreas Kohlbecker
|
* European Distributed Institute of Taxonomy
|
4 |
9479da48
|
Andreas Müller
|
* http://www.e-taxonomy.eu
|
5 |
5d73efbd
|
Andreas Kohlbecker
|
*
|
6 |
9479da48
|
Andreas Müller
|
* 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 |
5d73efbd
|
Andreas Kohlbecker
|
import java.net.URI;
|
13 |
|
|
import java.net.URISyntaxException;
|
14 |
b25cd654
|
ben.clark
|
|
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 |
70440a7d
|
a.babadshanjan
|
import javax.xml.bind.annotation.XmlAccessType;
|
21 |
|
|
import javax.xml.bind.annotation.XmlAccessorType;
|
22 |
|
|
import javax.xml.bind.annotation.XmlElement;
|
23 |
153fd456
|
a.babadshanjan
|
import javax.xml.bind.annotation.XmlIDREF;
|
24 |
|
|
import javax.xml.bind.annotation.XmlSchemaType;
|
25 |
70440a7d
|
a.babadshanjan
|
import javax.xml.bind.annotation.XmlType;
|
26 |
9479da48
|
Andreas Müller
|
|
27 |
3dc3440e
|
Andreas Müller
|
import org.apache.commons.lang.StringUtils;
|
28 |
b25cd654
|
ben.clark
|
import org.apache.log4j.Logger;
|
29 |
|
|
import org.hibernate.annotations.Any;
|
30 |
|
|
import org.hibernate.annotations.Cascade;
|
31 |
|
|
import org.hibernate.annotations.CascadeType;
|
32 |
a0d9fb62
|
Andreas Müller
|
import org.hibernate.annotations.Type;
|
33 |
b25cd654
|
ben.clark
|
import org.hibernate.envers.Audited;
|
34 |
|
|
import org.hibernate.envers.NotAudited;
|
35 |
|
|
|
36 |
|
|
import eu.etaxonomy.cdm.model.agent.Person;
|
37 |
|
|
|
38 |
9479da48
|
Andreas Müller
|
/**
|
39 |
|
|
* @author m.doering
|
40 |
|
|
* @version 1.0
|
41 |
|
|
* @created 08-Nov-2007 13:06:10
|
42 |
|
|
*/
|
43 |
70440a7d
|
a.babadshanjan
|
@XmlAccessorType(XmlAccessType.FIELD)
|
44 |
|
|
@XmlType(name = "Annotation", propOrder = {
|
45 |
ddae61ce
|
a.babadshanjan
|
"commentator",
|
46 |
|
|
"annotatedObj",
|
47 |
072ecc79
|
a.babadshanjan
|
"annotationType",
|
48 |
4794837a
|
Andreas Müller
|
"linkbackUri"
|
49 |
70440a7d
|
a.babadshanjan
|
})
|
50 |
9479da48
|
Andreas Müller
|
@Entity
|
51 |
ee91bcd9
|
ben.clark
|
@Audited
|
52 |
835c12dd
|
Andreas Müller
|
public class Annotation extends LanguageStringBase implements Cloneable {
|
53 |
0d575644
|
Andreas Müller
|
private static final long serialVersionUID = -4484677078599520233L;
|
54 |
4794837a
|
Andreas Müller
|
@SuppressWarnings("unused")
|
55 |
572ce758
|
Andreas Müller
|
private static final Logger logger = Logger.getLogger(Annotation.class);
|
56 |
5d73efbd
|
Andreas Kohlbecker
|
|
57 |
|
|
|
58 |
572ce758
|
Andreas Müller
|
/**
|
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 |
5d73efbd
|
Andreas Kohlbecker
|
|
68 |
f4d4156f
|
n.hoffmann
|
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 |
5d73efbd
|
Andreas Kohlbecker
|
|
74 |
0ed0ef35
|
Andreas Müller
|
/**
|
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 |
5d73efbd
|
Andreas Kohlbecker
|
|
83 |
|
|
|
84 |
9479da48
|
Andreas Müller
|
//Human annotation
|
85 |
70440a7d
|
a.babadshanjan
|
@XmlElement(name = "Commentator")
|
86 |
153fd456
|
a.babadshanjan
|
@XmlIDREF
|
87 |
|
|
@XmlSchemaType(name = "IDREF")
|
88 |
ee91bcd9
|
ben.clark
|
@ManyToOne(fetch = FetchType.LAZY)
|
89 |
|
|
@Cascade(CascadeType.SAVE_UPDATE)
|
90 |
9479da48
|
Andreas Müller
|
private Person commentator;
|
91 |
5d73efbd
|
Andreas Kohlbecker
|
|
92 |
70440a7d
|
a.babadshanjan
|
@XmlElement(name = "AnnotatedObject")
|
93 |
153fd456
|
a.babadshanjan
|
@XmlIDREF
|
94 |
|
|
@XmlSchemaType(name = "IDREF")
|
95 |
ee91bcd9
|
ben.clark
|
@Any(metaDef = "CdmBase",
|
96 |
|
|
metaColumn=@Column(name = "annotatedObj_type"),
|
97 |
b0530fee
|
Katja Luther
|
fetch = FetchType.EAGER,
|
98 |
ee91bcd9
|
ben.clark
|
optional = false)
|
99 |
|
|
@JoinColumn(name = "annotatedObj_id")
|
100 |
|
|
@NotAudited
|
101 |
9479da48
|
Andreas Müller
|
private AnnotatableEntity annotatedObj;
|
102 |
5d73efbd
|
Andreas Kohlbecker
|
|
103 |
7ae8a962
|
Andreas Müller
|
@XmlElement(name = "AnnotationType")
|
104 |
|
|
@XmlIDREF
|
105 |
|
|
@XmlSchemaType(name = "IDREF")
|
106 |
ee91bcd9
|
ben.clark
|
@ManyToOne(fetch = FetchType.LAZY)
|
107 |
07877786
|
a.babadshanjan
|
private AnnotationType annotationType;
|
108 |
5d73efbd
|
Andreas Kohlbecker
|
|
109 |
5ba6074a
|
Andreas Müller
|
// for external annotations/comments the URI of these can be set.
|
110 |
12ea3992
|
m.doering
|
// should be useful to implement trackback, pingback or linkback:
|
111 |
|
|
// http://en.wikipedia.org/wiki/Linkback
|
112 |
a0d9fb62
|
Andreas Müller
|
@XmlElement(name = "LinkbackUri")
|
113 |
|
|
@Type(type="uriUserType")
|
114 |
5d73efbd
|
Andreas Kohlbecker
|
private URI linkbackUri;
|
115 |
|
|
|
116 |
0014d956
|
Andreas Müller
|
|
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 |
f6765014
|
ben.clark
|
/**
|
136 |
|
|
* Currently envers does not support @Any
|
137 |
|
|
* @return
|
138 |
|
|
*/
|
139 |
9479da48
|
Andreas Müller
|
public AnnotatableEntity getAnnotatedObj() {
|
140 |
|
|
return annotatedObj;
|
141 |
|
|
}
|
142 |
0014d956
|
Andreas Müller
|
|
143 |
7baa0c0d
|
Andreas Müller
|
//TODO make not public, but TaxonTaoHibernateImpl.delete has to be changed then
|
144 |
294bd6f5
|
em.lee
|
/**
|
145 |
5d73efbd
|
Andreas Kohlbecker
|
*
|
146 |
294bd6f5
|
em.lee
|
* @param newAnnotatedObj
|
147 |
|
|
* @deprecated should not be used, is only public for internal reasons
|
148 |
|
|
*/
|
149 |
|
|
@Deprecated
|
150 |
ee91bcd9
|
ben.clark
|
public void setAnnotatedObj(AnnotatableEntity newAnnotatedObj) {
|
151 |
7baa0c0d
|
Andreas Müller
|
this.annotatedObj = newAnnotatedObj;
|
152 |
9479da48
|
Andreas Müller
|
}
|
153 |
|
|
|
154 |
f6765014
|
ben.clark
|
public AnnotationType getAnnotationType() {
|
155 |
|
|
return annotationType;
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
public void setAnnotationType(AnnotationType annotationType) {
|
159 |
|
|
this.annotationType = annotationType;
|
160 |
|
|
}
|
161 |
|
|
|
162 |
9479da48
|
Andreas Müller
|
public Person getCommentator(){
|
163 |
|
|
return this.commentator;
|
164 |
|
|
}
|
165 |
|
|
public void setCommentator(Person commentator){
|
166 |
|
|
this.commentator = commentator;
|
167 |
|
|
}
|
168 |
5d73efbd
|
Andreas Kohlbecker
|
|
169 |
|
|
|
170 |
|
|
public URI getLinkbackUri() {
|
171 |
|
|
return linkbackUri;
|
172 |
12ea3992
|
m.doering
|
}
|
173 |
5d73efbd
|
Andreas Kohlbecker
|
public void setLinkbackUri(URI linkbackUri) {
|
174 |
|
|
this.linkbackUri = linkbackUri;
|
175 |
12ea3992
|
m.doering
|
}
|
176 |
5d73efbd
|
Andreas Kohlbecker
|
|
177 |
|
|
|
178 |
3dc3440e
|
Andreas Müller
|
// ***************************** TO STRING ***********************************
|
179 |
5d73efbd
|
Andreas Kohlbecker
|
|
180 |
|
|
|
181 |
3dc3440e
|
Andreas Müller
|
/* (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 |
5d73efbd
|
Andreas Kohlbecker
|
|
193 |
|
|
|
194 |
|
|
|
195 |
835c12dd
|
Andreas Müller
|
//****************** CLONE ************************************************/
|
196 |
5d73efbd
|
Andreas Kohlbecker
|
|
197 |
835c12dd
|
Andreas Müller
|
/* (non-Javadoc)
|
198 |
|
|
* @see java.lang.Object#clone()
|
199 |
|
|
*/
|
200 |
e1c9b32e
|
a.babadshanjan
|
@Override
|
201 |
835c12dd
|
Andreas Müller
|
public Object clone() throws CloneNotSupportedException{
|
202 |
|
|
Annotation result = (Annotation)super.clone();
|
203 |
a784f00f
|
Katja Luther
|
result.setCommentator(this.getCommentator());
|
204 |
|
|
result.setAnnotationType(this.getAnnotationType());
|
205 |
5d73efbd
|
Andreas Kohlbecker
|
result.setLinkbackUri(this.linkbackUri);
|
206 |
835c12dd
|
Andreas Müller
|
return result;
|
207 |
|
|
}
|
208 |
3dc3440e
|
Andreas Müller
|
|
209 |
|
|
|
210 |
835c12dd
|
Andreas Müller
|
/**
|
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 |
9479da48
|
Andreas Müller
|
}
|