2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.common
;
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
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.hibernate
.annotations
.Any
;
28 import org
.hibernate
.envers
.Audited
;
29 import org
.hibernate
.envers
.NotAudited
;
32 * This class aims to make available more "attributes" for identifiable entities
33 * in a flexible way. Application developers (and even users) can define their own
34 * "attributes" as an ExtensionType and add data to Identifiable instances via
35 * Extension instances.
38 * @created 08-Nov-2007 13:06:23
40 @XmlAccessorType(XmlAccessType
.FIELD
)
41 @XmlType(name
= "Extension", propOrder
= {
48 public class Extension
extends VersionableEntity
implements Cloneable
{
49 private static final long serialVersionUID
= -857207737641432202L;
50 @SuppressWarnings("unused")
51 private static final Logger logger
= Logger
.getLogger(Extension
.class);
53 @XmlElement(name
= "Value")
57 @XmlElement(name
= "ExtensionType")
59 @XmlSchemaType(name
= "IDREF")
60 @ManyToOne(fetch
= FetchType
.LAZY
)
61 private ExtensionType type
;
63 @XmlElement(name
= "ExtendedObject")
65 @XmlSchemaType(name
= "IDREF")
66 @Any(metaDef
= "CdmBase",
67 metaColumn
=@Column(name
= "extendedObj_type"),
68 fetch
= FetchType
.LAZY
,
70 @JoinColumn(name
= "extendedObj_id")
72 private IdentifiableEntity extendedObj
;
74 public static Extension
NewInstance(){
75 return new Extension();
78 public static Extension
NewInstance(IdentifiableEntity
<?
> extendedObject
, String value
, ExtensionType extensionType
){
79 Extension extension
= new Extension();
80 extension
.setValue(value
);
81 extension
.setType(extensionType
);
82 extendedObject
.addExtension(extension
);
87 * TODO should not be private but throws error in persistence/io test
90 protected Extension(){
93 public IdentifiableEntity
getExtendedObj() {
96 //TODO make not public, but TaxonTaoHibernateImpl.delete has to be changed then
97 public void setExtendedObj(IdentifiableEntity extendedObj
) {
98 this.extendedObj
= extendedObj
;
102 public ExtensionType
getType(){
110 public void setType(ExtensionType type
){
114 public String
getValue(){
122 public void setValue(String value
){
126 //****************** CLONE ************************************************/
129 * @see java.lang.Object#clone()
132 public Object
clone() throws CloneNotSupportedException
{
133 Extension result
= (Extension
)super.clone();
134 //no changes to: type, value
139 * Clones this extension and sets the clone's extended object to 'extendedObject'
140 * @see java.lang.Object#clone()
142 public Extension
clone(IdentifiableEntity extendedObject
) throws CloneNotSupportedException
{
143 Extension result
= (Extension
)clone();
144 result
.setExtendedObj(extendedObject
);