Project

General

Profile

Download (4.76 KB) Statistics
| Branch: | Tag: | Revision:
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.Any;
15
import org.hibernate.annotations.Cascade;
16
import org.hibernate.annotations.CascadeType;
17

    
18
import java.net.MalformedURLException;
19
import java.net.URL;
20
import javax.persistence.*;
21
import javax.xml.bind.annotation.XmlAccessType;
22
import javax.xml.bind.annotation.XmlAccessorType;
23
import javax.xml.bind.annotation.XmlElement;
24
import javax.xml.bind.annotation.XmlIDREF;
25
import javax.xml.bind.annotation.XmlSchemaType;
26
import javax.xml.bind.annotation.XmlType;
27

    
28
/**
29
 * @author m.doering
30
 * @version 1.0
31
 * @created 08-Nov-2007 13:06:10
32
 */
33
@XmlAccessorType(XmlAccessType.FIELD)
34
@XmlType(name = "Annotation", propOrder = {
35
    "commentator",
36
    "annotatedObj",
37
    "annotationType",
38
    "linkbackUrl"
39
})
40
@Entity
41
//@Audited
42
public class Annotation extends LanguageStringBase implements Cloneable {
43
	private static final long serialVersionUID = -4484677078599520233L;
44
	private static final Logger logger = Logger.getLogger(Annotation.class);
45
	
46
	
47
	/**
48
	 * Factory method.
49
	 * @param text
50
	 * @param lang
51
	 * @return
52
	 */
53
	public static Annotation NewInstance(String text, Language lang){
54
		return new Annotation(text, lang);
55
	}
56
	
57
	/**
58
	 * Factory method. Using default language.
59
	 * @param text
60
	 * @return
61
	 */
62
	public static Annotation NewDefaultLanguageInstance(String text){
63
		return new Annotation(text, Language.DEFAULT());
64
	}
65
	
66
	private Annotation(){
67
		super();
68
	}
69
	
70
	/**
71
	 * Constructor
72
	 * @param text
73
	 * @param lang
74
	 */
75
	protected Annotation(String text, Language language) {
76
		super(text, language);
77
	}
78
	
79
	
80
	//Human annotation
81
	@XmlElement(name = "Commentator")
82
    @XmlIDREF
83
    @XmlSchemaType(name = "IDREF")
84
	private Person commentator;
85
	
86
	@XmlElement(name = "AnnotatedObject")
87
    @XmlIDREF
88
    @XmlSchemaType(name = "IDREF")
89
	private AnnotatableEntity annotatedObj;
90
	
91
    @XmlElement(name = "AnnotationType")
92
    @XmlIDREF
93
    @XmlSchemaType(name = "IDREF")
94
	private AnnotationType annotationType;
95
	
96
	// for external annotations/comments the URL of these can be set.
97
	// should be useful to implement trackback, pingback or linkback:
98
	// http://en.wikipedia.org/wiki/Linkback
99
	@XmlElement(name = "LinkbackURL")
100
	private URL linkbackUrl;
101
	
102
	/**
103
	 * Currently envers does not support @Any
104
	 * @return
105
	 */
106
	@Any(metaDef = "CdmBase",
107
	    	 metaColumn=@Column(name = "annotatedObj_type"),
108
	    	 fetch = FetchType.LAZY,
109
	    	 optional = false)
110
	@JoinColumn(name = "annotatedObj_id")
111
//	@NotAudited
112
	public AnnotatableEntity getAnnotatedObj() {
113
		return annotatedObj;
114
	}
115
	protected void setAnnotatedObj(AnnotatableEntity newAnnotatedObj) {
116
		this.annotatedObj = newAnnotatedObj;		
117
	}
118

    
119
	@ManyToOne(fetch = FetchType.LAZY)
120
	public AnnotationType getAnnotationType() {
121
		return annotationType;
122
	}
123

    
124
	public void setAnnotationType(AnnotationType annotationType) {
125
		this.annotationType = annotationType;
126
	}
127

    
128
	@ManyToOne(fetch = FetchType.LAZY)
129
	@Cascade({CascadeType.SAVE_UPDATE})
130
	public Person getCommentator(){
131
		return this.commentator;
132
	}
133
	public void setCommentator(Person commentator){
134
		this.commentator = commentator;
135
	}
136
	
137
	@Transient
138
	public URL getLinkbackUrl() {
139
		return linkbackUrl;
140
	}
141
	public void setLinkbackUrl(URL linkbackUrl) {
142
		this.linkbackUrl = linkbackUrl;
143
	}
144
	
145
	/**
146
	 * private get/set methods for Hibernate that allows us to save the URL as strings
147
	 * @return
148
	 */
149
	private String getLinkbackUrlStr() {
150
		if (linkbackUrl == null){
151
			return null;
152
		}
153
		return linkbackUrl.toString();
154
	}
155
	private void setLinkbackUrlStr(String linkbackUrlString) {
156
		if (linkbackUrlString == null){
157
			this.linkbackUrl = null;
158
		}else{
159
			try {
160
				this.linkbackUrl = new URL(linkbackUrlString);
161
			} catch (MalformedURLException e) { //can't be thrown as otherwise Hibernate throws PropertyAccessExceptioin
162
				logger.warn("Runtime error occurred in setLinkbackUrlStr");
163
				e.printStackTrace();
164
			}
165
		}
166
	}
167
	
168
	
169
//****************** CLONE ************************************************/
170
	 
171
	/* (non-Javadoc)
172
	 * @see java.lang.Object#clone()
173
	 */
174
	@Override
175
	public Object clone() throws CloneNotSupportedException{
176
		Annotation result = (Annotation)super.clone();
177
		//no changes to: type, flag
178
		return result;
179
	}
180
	
181
	/**
182
	 * Clones this annotation and sets the clone's annotated object to 'annotatedObject'
183
	 * @see java.lang.Object#clone()
184
	 */
185
	public Annotation clone(AnnotatableEntity annotatedObject) throws CloneNotSupportedException{
186
		Annotation result = (Annotation)clone();
187
		result.setAnnotatedObj(annotatedObject);
188
		return result;
189
	}
190
}
(2-2/50)