Project

General

Profile

Download (3.03 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

    
13
import javax.persistence.Entity;
14
import javax.persistence.FetchType;
15
import javax.persistence.Lob;
16
import javax.persistence.ManyToOne;
17
import javax.xml.bind.annotation.XmlAccessType;
18
import javax.xml.bind.annotation.XmlAccessorType;
19
import javax.xml.bind.annotation.XmlElement;
20
import javax.xml.bind.annotation.XmlIDREF;
21
import javax.xml.bind.annotation.XmlSchemaType;
22
import javax.xml.bind.annotation.XmlType;
23

    
24
import org.apache.commons.lang.StringUtils;
25
import org.apache.log4j.Logger;
26
import org.hibernate.envers.Audited;
27

    
28
/**
29
 * This class aims to make available more "attributes" for identifiable entities
30
 * in a flexible way. Application developers (and even users) can define their own
31
 * "attributes" as an ExtensionType and add data to Identifiable instances via
32
 * Extension instances.
33
 * @author m.doering
34
 * @version 1.0
35
 * @created 08-Nov-2007 13:06:23
36
 */
37
@XmlAccessorType(XmlAccessType.FIELD)
38
@XmlType(name = "Extension", propOrder = {
39
    "value",
40
    "type"
41
})
42
@Entity
43
@Audited
44
public class Extension extends VersionableEntity implements Cloneable {
45
	private static final long serialVersionUID = -857207737641432202L;
46
	@SuppressWarnings("unused")
47
	private static final  Logger logger = Logger.getLogger(Extension.class);
48

    
49
    @XmlElement(name = "Value")
50
	@Lob
51
    private String value;
52

    
53
    @XmlElement(name = "ExtensionType")
54
    @XmlIDREF
55
    @XmlSchemaType(name = "IDREF")
56
    @ManyToOne(fetch = FetchType.LAZY)
57
    private ExtensionType type;
58

    
59
	public static Extension NewInstance(){
60
		return new Extension();
61
	}
62

    
63
	/**
64
	 * Creates a new extension and adds it to the extended object.
65
	 * @param extendedObject
66
	 * @param value
67
	 * @param extensionType
68
	 * @return
69
	 */
70
	public static Extension NewInstance(IdentifiableEntity<?> extendedObject, String value, ExtensionType extensionType){
71
		Extension extension = new Extension();
72
		extension.setValue(value);
73
		extension.setType(extensionType);
74
		extendedObject.addExtension(extension);
75
		return extension;
76
	}
77

    
78
// *************************** GETTER / SETTER ********************************/
79

    
80
	//type
81
	public ExtensionType getType(){
82
		return this.type;
83
	}
84
	public void setType(ExtensionType type){
85
		this.type = type;
86
	}
87

    
88
	//value
89
	public String getValue(){
90
		return this.value;
91
	}
92
	public void setValue(String value){
93
		this.value = value;
94
	}
95

    
96
//***************************** TO STRING ***********************************
97

    
98
	@Override
99
	public String toString() {
100
		if (StringUtils.isNotBlank(this.value)){
101
			return "Ext.: " + this.value;
102
		}else{
103
			return super.toString();
104
		}
105
	}
106

    
107

    
108
//****************** CLONE ************************************************/
109

    
110
	@Override
111
	public Object clone() throws CloneNotSupportedException{
112
		Extension result = (Extension)super.clone();
113
		//no changes to: type, value
114
		return result;
115
	}
116

    
117
}
(11-11/72)