Project

General

Profile

Download (4.33 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.Column;
14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.JoinColumn;
17
import javax.persistence.Lob;
18
import javax.persistence.ManyToOne;
19
import javax.xml.bind.annotation.XmlAccessType;
20
import javax.xml.bind.annotation.XmlAccessorType;
21
import javax.xml.bind.annotation.XmlElement;
22
import javax.xml.bind.annotation.XmlIDREF;
23
import javax.xml.bind.annotation.XmlSchemaType;
24
import javax.xml.bind.annotation.XmlType;
25

    
26
import org.apache.commons.lang.StringUtils;
27
import org.apache.log4j.Logger;
28
import org.hibernate.annotations.Any;
29
import org.hibernate.envers.Audited;
30
import org.hibernate.envers.NotAudited;
31

    
32
/**
33
 * This class aims to make available more "attributes" for identifiable entities
34
 * in a flexible way. Application developers (and even users) can define their own
35
 * "attributes" as an ExtensionType and add data to Identifiable instances via
36
 * Extension instances.
37
 * @author m.doering
38
 * @version 1.0
39
 * @created 08-Nov-2007 13:06:23
40
 */
41
@XmlAccessorType(XmlAccessType.FIELD)
42
@XmlType(name = "Extension", propOrder = {
43
    "value",
44
    "type",
45
    "extendedObj"
46
})
47
@Entity
48
@Audited
49
public class Extension extends VersionableEntity implements Cloneable {
50
	private static final long serialVersionUID = -857207737641432202L;
51
	@SuppressWarnings("unused")
52
	private static final  Logger logger = Logger.getLogger(Extension.class);
53
	
54
    @XmlElement(name = "Value")
55
	@Lob
56
    private String value;
57
	
58
    @XmlElement(name = "ExtensionType")
59
    @XmlIDREF
60
    @XmlSchemaType(name = "IDREF")
61
    @ManyToOne(fetch = FetchType.LAZY)
62
	private ExtensionType type;
63
	
64
    @XmlElement(name = "ExtendedObject")
65
    @XmlIDREF
66
    @XmlSchemaType(name = "IDREF")
67
    @Any(metaDef = "CdmBase",
68
	    	 metaColumn=@Column(name = "extendedObj_type"),
69
	    	 fetch = FetchType.LAZY,
70
	    	 optional = false)
71
	@JoinColumn(name = "extendedObj_id")
72
	@NotAudited
73
	private IdentifiableEntity extendedObj;
74
	
75
	public static Extension NewInstance(){
76
		return new Extension();
77
	}
78
	
79
	/**
80
	 * Creates a new extension and adds it to the extended object.
81
	 * @param extendedObject
82
	 * @param value
83
	 * @param extensionType
84
	 * @return
85
	 */
86
	public static Extension NewInstance(IdentifiableEntity<?> extendedObject, String value, ExtensionType extensionType){
87
		Extension extension = new Extension();
88
		extension.setValue(value);
89
		extension.setType(extensionType);
90
		extendedObject.addExtension(extension);
91
		return extension;
92
	}
93
	
94
	/**
95
	 * TODO should not be private but throws error in persistence/io test
96
	 * Constructor
97
	 */
98
	protected Extension(){
99
	}
100
	
101
	public IdentifiableEntity getExtendedObj() {
102
		return extendedObj;
103
	}
104
	//TODO make not public, but TaxonTaoHibernateImpl.delete has to be changed then
105
	public void setExtendedObj(IdentifiableEntity extendedObj) {
106
		this.extendedObj = extendedObj;
107
	}
108

    
109
	
110
	public ExtensionType getType(){
111
		return this.type;
112
	}
113

    
114
	/**
115
	 * 
116
	 * @param type    type
117
	 */
118
	public void setType(ExtensionType type){
119
		this.type = type;
120
	}
121

    
122
	public String getValue(){
123
		return this.value;
124
	}
125

    
126
	/**
127
	 * 
128
	 * @param value    value
129
	 */
130
	public void setValue(String value){
131
		this.value = value;
132
	}
133

    
134
//***************************** TO STRING ***********************************
135
	
136
	/* (non-Javadoc)
137
	 * @see eu.etaxonomy.cdm.model.common.CdmBase#toString()
138
	 */
139
	@Override
140
	public String toString() {
141
		if (StringUtils.isNotBlank(this.value)){
142
			return "Ext.: " + this.value;
143
		}else{
144
			return super.toString();
145
		}
146
	}
147
	
148
	
149
//****************** CLONE ************************************************/
150
	 
151
	/* (non-Javadoc)
152
	 * @see java.lang.Object#clone()
153
	 */
154
	@Override
155
	public Object clone() throws CloneNotSupportedException{
156
		Extension result = (Extension)super.clone();	
157
		//no changes to: type, value
158
		return result;
159
	}
160
	
161
	/**
162
	 * Clones this extension and sets the clone's extended object to 'extendedObject'
163
	 * @see java.lang.Object#clone()
164
	 */
165
	public Extension clone(IdentifiableEntity extendedObject) throws CloneNotSupportedException{
166
		Extension result = (Extension)clone();
167
		result.setExtendedObj(extendedObject);
168
		return result;
169
	}
170

    
171
}
(14-14/70)