2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.common
;
12 import java
.net
.MalformedURLException
;
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
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.hibernate
.annotations
.Any
;
29 import org
.hibernate
.annotations
.Cascade
;
30 import org
.hibernate
.annotations
.CascadeType
;
31 import org
.hibernate
.envers
.Audited
;
32 import org
.hibernate
.envers
.NotAudited
;
34 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
39 * @created 08-Nov-2007 13:06:10
41 @XmlAccessorType(XmlAccessType
.FIELD
)
42 @XmlType(name
= "Annotation", propOrder
= {
50 public class Annotation
extends LanguageStringBase
implements Cloneable
{
51 private static final long serialVersionUID
= -4484677078599520233L;
52 private static final Logger logger
= Logger
.getLogger(Annotation
.class);
61 public static Annotation
NewInstance(String text
, Language lang
){
62 return new Annotation(text
, lang
);
65 public static Annotation
NewInstance(String text
, AnnotationType annotationType
, Language lang
){
66 Annotation annotation
= new Annotation(text
, lang
);
67 annotation
.setAnnotationType(annotationType
);
72 * Factory method. Using default language.
76 public static Annotation
NewDefaultLanguageInstance(String text
){
77 return new Annotation(text
, Language
.DEFAULT());
80 protected Annotation(){
89 protected Annotation(String text
, Language language
) {
90 super(text
, language
);
95 @XmlElement(name
= "Commentator")
97 @XmlSchemaType(name
= "IDREF")
98 @ManyToOne(fetch
= FetchType
.LAZY
)
99 @Cascade(CascadeType
.SAVE_UPDATE
)
100 private Person commentator
;
102 @XmlElement(name
= "AnnotatedObject")
104 @XmlSchemaType(name
= "IDREF")
105 @Any(metaDef
= "CdmBase",
106 metaColumn
=@Column(name
= "annotatedObj_type"),
107 fetch
= FetchType
.EAGER
,
109 @JoinColumn(name
= "annotatedObj_id")
111 private AnnotatableEntity annotatedObj
;
113 @XmlElement(name
= "AnnotationType")
115 @XmlSchemaType(name
= "IDREF")
116 @ManyToOne(fetch
= FetchType
.LAZY
)
117 private AnnotationType annotationType
;
119 // for external annotations/comments the URL of these can be set.
120 // should be useful to implement trackback, pingback or linkback:
121 // http://en.wikipedia.org/wiki/Linkback
122 @XmlElement(name
= "LinkbackURL")
123 private URL linkbackUrl
;
126 * Currently envers does not support @Any
129 public AnnotatableEntity
getAnnotatedObj() {
133 //TODO make not public, but TaxonTaoHibernateImpl.delete has to be changed then
136 * @param newAnnotatedObj
137 * @deprecated should not be used, is only public for internal reasons
140 public void setAnnotatedObj(AnnotatableEntity newAnnotatedObj
) {
141 this.annotatedObj
= newAnnotatedObj
;
144 public AnnotationType
getAnnotationType() {
145 return annotationType
;
148 public void setAnnotationType(AnnotationType annotationType
) {
149 this.annotationType
= annotationType
;
152 public Person
getCommentator(){
153 return this.commentator
;
155 public void setCommentator(Person commentator
){
156 this.commentator
= commentator
;
160 public URL
getLinkbackUrl() {
163 public void setLinkbackUrl(URL linkbackUrl
) {
164 this.linkbackUrl
= linkbackUrl
;
168 * private get/set methods for Hibernate that allows us to save the URL as strings
171 private String
getLinkbackUrlStr() {
172 if (linkbackUrl
== null){
175 return linkbackUrl
.toString();
177 private void setLinkbackUrlStr(String linkbackUrlString
) {
178 if (linkbackUrlString
== null){
179 this.linkbackUrl
= null;
182 this.linkbackUrl
= new URL(linkbackUrlString
);
183 } catch (MalformedURLException e
) { //can't be thrown as otherwise Hibernate throws PropertyAccessExceptioin
184 logger
.warn("Runtime error occurred in setLinkbackUrlStr");
191 //****************** CLONE ************************************************/
194 * @see java.lang.Object#clone()
197 public Object
clone() throws CloneNotSupportedException
{
198 Annotation result
= (Annotation
)super.clone();
199 result
.setCommentator(this.getCommentator());
200 result
.setAnnotationType(this.getAnnotationType());
201 result
.setLinkbackUrl(this.linkbackUrl
);
206 * Clones this annotation and sets the clone's annotated object to 'annotatedObject'
207 * @see java.lang.Object#clone()
209 public Annotation
clone(AnnotatableEntity annotatedObject
) throws CloneNotSupportedException
{
210 Annotation result
= (Annotation
)clone();
211 result
.setAnnotatedObj(annotatedObject
);