(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / Annotation.java
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 eu.etaxonomy.cdm.model.agent.Person;
13 import org.apache.log4j.Logger;
14 import org.hibernate.annotations.Cascade;
15 import org.hibernate.annotations.CascadeType;
16
17 import java.net.MalformedURLException;
18 import java.net.URL;
19 import javax.persistence.*;
20
21 /**
22 * @author m.doering
23 * @version 1.0
24 * @created 08-Nov-2007 13:06:10
25 */
26 @Entity
27 public class Annotation extends LanguageStringBase {
28 private static final Logger logger = Logger.getLogger(Annotation.class);
29
30
31 /**
32 * Factory method.
33 * @param text
34 * @param lang
35 * @return
36 */
37 public static Annotation NewInstance(String text, Language lang){
38 return new Annotation(text, lang);
39 }
40
41 /**
42 * Factory method. Using default language.
43 * @param text
44 * @return
45 */
46 public static Annotation NewDefaultLanguageInstance(String text){
47 return new Annotation(text, Language.DEFAULT());
48 }
49
50 private Annotation(){
51 super();
52 }
53
54 /**
55 * Constructor
56 * @param text
57 * @param lang
58 */
59 protected Annotation(String text, Language language) {
60 super(text, language);
61 }
62
63
64
65 //Human annotation
66 private Person commentator;
67 private AnnotatableEntity annotatedObj;
68 // for external annotations/comments the URL of these can be set.
69 // should be useful to implement trackback, pingback or linkback:
70 // http://en.wikipedia.org/wiki/Linkback
71 private URL linkbackUrl;
72
73 @Transient
74 public AnnotatableEntity getAnnotatedObj() {
75 return annotatedObj;
76 }
77 protected void setAnnotatedObj(AnnotatableEntity newAnnotatedObj) {
78 this.annotatedObj = newAnnotatedObj;
79 }
80
81 @ManyToOne
82 @Cascade({CascadeType.SAVE_UPDATE})
83 public Person getCommentator(){
84 return this.commentator;
85 }
86 public void setCommentator(Person commentator){
87 this.commentator = commentator;
88 }
89
90 @Transient
91 public URL getLinkbackUrl() {
92 return linkbackUrl;
93 }
94 public void setLinkbackUrl(URL linkbackUrl) {
95 this.linkbackUrl = linkbackUrl;
96 }
97
98 /**
99 * private get/set methods for Hibernate that allows us to save the URL as strings
100 * @return
101 */
102 private String getLinkbackUrlStr() {
103 if (linkbackUrl == null){
104 return null;
105 }
106 return linkbackUrl.toString();
107 }
108 private void setLinkbackUrlStr(String linkbackUrlString) {
109 if (linkbackUrlString == null){
110 this.linkbackUrl = null;
111 }else{
112 try {
113 this.linkbackUrl = new URL(linkbackUrlString);
114 } catch (MalformedURLException e) { //can't be thrown as otherwise Hibernate throws PropertyAccessExceptioin
115 logger.warn("Runtime error occurred in setLinkbackUrlStr");
116 e.printStackTrace();
117 }
118 }
119 }
120 }