Revision 52c34f45
Added by Andreas Müller almost 8 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Extension.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
10 | 10 |
package eu.etaxonomy.cdm.model.common; |
11 | 11 |
|
12 | 12 |
|
13 |
import javax.persistence.Column; |
|
14 | 13 |
import javax.persistence.Entity; |
15 | 14 |
import javax.persistence.FetchType; |
16 |
import javax.persistence.JoinColumn; |
|
17 | 15 |
import javax.persistence.Lob; |
18 | 16 |
import javax.persistence.ManyToOne; |
19 | 17 |
import javax.xml.bind.annotation.XmlAccessType; |
... | ... | |
25 | 23 |
|
26 | 24 |
import org.apache.commons.lang.StringUtils; |
27 | 25 |
import org.apache.log4j.Logger; |
28 |
import org.hibernate.annotations.Any; |
|
29 | 26 |
import org.hibernate.envers.Audited; |
30 |
import org.hibernate.envers.NotAudited; |
|
31 | 27 |
|
32 | 28 |
/** |
33 | 29 |
* This class aims to make available more "attributes" for identifiable entities |
... | ... | |
41 | 37 |
@XmlAccessorType(XmlAccessType.FIELD) |
42 | 38 |
@XmlType(name = "Extension", propOrder = { |
43 | 39 |
"value", |
44 |
"type", |
|
45 |
"extendedObj" |
|
40 |
"type" |
|
46 | 41 |
}) |
47 | 42 |
@Entity |
48 | 43 |
@Audited |
... | ... | |
50 | 45 |
private static final long serialVersionUID = -857207737641432202L; |
51 | 46 |
@SuppressWarnings("unused") |
52 | 47 |
private static final Logger logger = Logger.getLogger(Extension.class); |
53 |
|
|
48 |
|
|
54 | 49 |
@XmlElement(name = "Value") |
55 | 50 |
@Lob |
56 | 51 |
private String value; |
57 |
|
|
52 |
|
|
58 | 53 |
@XmlElement(name = "ExtensionType") |
59 | 54 |
@XmlIDREF |
60 | 55 |
@XmlSchemaType(name = "IDREF") |
61 | 56 |
@ManyToOne(fetch = FetchType.LAZY) |
62 | 57 |
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 |
|
|
58 |
|
|
75 | 59 |
public static Extension NewInstance(){ |
76 | 60 |
return new Extension(); |
77 | 61 |
} |
78 |
|
|
62 |
|
|
79 | 63 |
/** |
80 | 64 |
* Creates a new extension and adds it to the extended object. |
81 | 65 |
* @param extendedObject |
... | ... | |
90 | 74 |
extendedObject.addExtension(extension); |
91 | 75 |
return extension; |
92 | 76 |
} |
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 |
protected void setExtendedObj(IdentifiableEntity extendedObj) { |
|
105 |
this.extendedObj = extendedObj; |
|
106 |
} |
|
107 | 77 |
|
108 |
|
|
78 |
// *************************** GETTER / SETTER ********************************/ |
|
79 |
|
|
80 |
//type |
|
109 | 81 |
public ExtensionType getType(){ |
110 | 82 |
return this.type; |
111 | 83 |
} |
112 |
|
|
113 |
/** |
|
114 |
* |
|
115 |
* @param type type |
|
116 |
*/ |
|
117 | 84 |
public void setType(ExtensionType type){ |
118 | 85 |
this.type = type; |
119 | 86 |
} |
120 | 87 |
|
88 |
//value |
|
121 | 89 |
public String getValue(){ |
122 | 90 |
return this.value; |
123 | 91 |
} |
124 |
|
|
125 |
/** |
|
126 |
* |
|
127 |
* @param value value |
|
128 |
*/ |
|
129 | 92 |
public void setValue(String value){ |
130 | 93 |
this.value = value; |
131 | 94 |
} |
132 | 95 |
|
133 | 96 |
//***************************** TO STRING *********************************** |
134 |
|
|
97 |
|
|
135 | 98 |
@Override |
136 | 99 |
public String toString() { |
137 | 100 |
if (StringUtils.isNotBlank(this.value)){ |
... | ... | |
140 | 103 |
return super.toString(); |
141 | 104 |
} |
142 | 105 |
} |
143 |
|
|
144 |
|
|
106 |
|
|
107 |
|
|
145 | 108 |
//****************** CLONE ************************************************/ |
146 |
|
|
109 |
|
|
147 | 110 |
@Override |
148 | 111 |
public Object clone() throws CloneNotSupportedException{ |
149 |
Extension result = (Extension)super.clone();
|
|
112 |
Extension result = (Extension)super.clone(); |
|
150 | 113 |
//no changes to: type, value |
151 | 114 |
return result; |
152 | 115 |
} |
153 |
|
|
154 |
/** |
|
155 |
* Clones this extension and sets the clone's extended object to 'extendedObject' |
|
156 |
* @see java.lang.Object#clone() |
|
157 |
*/ |
|
158 |
public Extension clone(IdentifiableEntity extendedObject) throws CloneNotSupportedException{ |
|
159 |
Extension result = (Extension)clone(); |
|
160 |
result.setExtendedObj(extendedObject); |
|
161 |
return result; |
|
162 |
} |
|
163 | 116 |
|
164 | 117 |
} |
Also available in: Unified diff
Remove bidirectionality for supplemental data #5743