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.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
25
|
import org.hibernate.envers.Audited;
|
26
|
|
27
|
/**
|
28
|
* This class aims to make available more "attributes" for identifiable entities
|
29
|
* in a flexible way. Application developers (and even users) can define their own
|
30
|
* "attributes" as an ExtensionType and add data to Identifiable instances via
|
31
|
* Extension instances.
|
32
|
* @author m.doering
|
33
|
* @since 08-Nov-2007 13:06:23
|
34
|
*/
|
35
|
@XmlAccessorType(XmlAccessType.FIELD)
|
36
|
@XmlType(name = "Extension", propOrder = {
|
37
|
"value",
|
38
|
"type"
|
39
|
})
|
40
|
@Entity
|
41
|
@Audited
|
42
|
public class Extension extends VersionableEntity implements Cloneable {
|
43
|
private static final long serialVersionUID = -857207737641432202L;
|
44
|
@SuppressWarnings("unused")
|
45
|
private static final Logger logger = LogManager.getLogger(Extension.class);
|
46
|
|
47
|
@XmlElement(name = "Value")
|
48
|
@Lob
|
49
|
private String value;
|
50
|
|
51
|
@XmlElement(name = "ExtensionType")
|
52
|
@XmlIDREF
|
53
|
@XmlSchemaType(name = "IDREF")
|
54
|
@ManyToOne(fetch = FetchType.LAZY)
|
55
|
private ExtensionType type;
|
56
|
|
57
|
public static Extension NewInstance(){
|
58
|
return new Extension();
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* Creates a new extension and adds it to the extended object.
|
63
|
* @param extendedObject
|
64
|
* @param value
|
65
|
* @param extensionType
|
66
|
* @return
|
67
|
*/
|
68
|
public static Extension NewInstance(IdentifiableEntity<?> extendedObject, String value, ExtensionType extensionType){
|
69
|
Extension extension = new Extension();
|
70
|
extension.setValue(value);
|
71
|
extension.setType(extensionType);
|
72
|
extendedObject.addExtension(extension);
|
73
|
return extension;
|
74
|
}
|
75
|
|
76
|
// *************************** GETTER / SETTER ********************************/
|
77
|
|
78
|
//type
|
79
|
public ExtensionType getType(){
|
80
|
return this.type;
|
81
|
}
|
82
|
public void setType(ExtensionType type){
|
83
|
this.type = type;
|
84
|
}
|
85
|
|
86
|
//value
|
87
|
public String getValue(){
|
88
|
return this.value;
|
89
|
}
|
90
|
public void setValue(String value){
|
91
|
this.value = value;
|
92
|
}
|
93
|
|
94
|
//***************************** TO STRING ***********************************
|
95
|
|
96
|
@Override
|
97
|
public String toString() {
|
98
|
if (isNotBlank(this.value)){
|
99
|
return "Ext.: " + this.value;
|
100
|
}else{
|
101
|
return super.toString();
|
102
|
}
|
103
|
}
|
104
|
|
105
|
//****************** CLONE ************************************************/
|
106
|
|
107
|
@Override
|
108
|
public Extension clone() throws CloneNotSupportedException{
|
109
|
Extension result = (Extension)super.clone();
|
110
|
//no changes to: type, value
|
111
|
return result;
|
112
|
}
|
113
|
}
|