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 eu
.etaxonomy
.cdm
.model
.agent
.Person
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.hibernate
.annotations
.Cascade
;
15 import org
.hibernate
.annotations
.CascadeType
;
17 import java
.net
.MalformedURLException
;
19 import javax
.persistence
.*;
24 * @created 08-Nov-2007 13:06:10
27 public class Annotation
extends LanguageString
{
28 private static final Logger logger
= Logger
.getLogger(Annotation
.class);
37 public static Annotation
NewInstance(String text
, Language lang
){
38 return new Annotation(text
, lang
);
46 protected Annotation(String text
, Language lang
) {
51 private Person commentator
;
52 private AnnotatableEntity annotatedObj
;
53 // for external annotations/comments the URL of these can be set.
54 // should be useful to implement trackback, pingback or linkback:
55 // http://en.wikipedia.org/wiki/Linkback
56 private URL linkbackUrl
;
59 public AnnotatableEntity
getAnnotatedObj() {
62 protected void setAnnotatedObj(AnnotatableEntity newAnnotatedObj
) {
63 // Hibernate bidirectional cascade hack:
64 // http://opensource.atlassian.com/projects/hibernate/browse/HHH-1054
65 if(this.annotatedObj
== newAnnotatedObj
) return;
66 if (annotatedObj
!= null) {
67 annotatedObj
.annotations
.remove(this);
69 if (newAnnotatedObj
!= null) {
70 newAnnotatedObj
.annotations
.add(this);
72 this.annotatedObj
= newAnnotatedObj
;
76 @Cascade({CascadeType
.SAVE_UPDATE
})
77 public Person
getCommentator(){
78 return this.commentator
;
80 public void setCommentator(Person commentator
){
81 this.commentator
= commentator
;
85 public URL
getLinkbackUrl() {
88 public void setLinkbackUrl(URL linkbackUrl
) {
89 this.linkbackUrl
= linkbackUrl
;
93 * private get/set methods for Hibernate that allows us to save the URL as strings
96 private String
getLinkbackUrlStr() {
97 if (linkbackUrl
== null){
100 return linkbackUrl
.toString();
102 private void setLinkbackUrlStr(String linkbackUrlString
) {
103 if (linkbackUrlString
== null){
104 this.linkbackUrl
= null;
107 this.linkbackUrl
= new URL(linkbackUrlString
);
108 } catch (MalformedURLException e
) { //can't be thrown as otherwise Hibernate throws PropertyAccessExceptioin
109 logger
.warn("Runtime error occurred in setLinkbackUrlStr");