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
.ManyToOne
;
18 import javax
.xml
.bind
.annotation
.XmlAccessType
;
19 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
20 import javax
.xml
.bind
.annotation
.XmlElement
;
21 import javax
.xml
.bind
.annotation
.XmlIDREF
;
22 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
23 import javax
.xml
.bind
.annotation
.XmlType
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.hibernate
.annotations
.Any
;
27 import org
.hibernate
.envers
.Audited
;
28 import org
.hibernate
.envers
.NotAudited
;
31 * This class aims to make available more "attributes" for identifiable entities
32 * in a flexible way. Application developers (and even users) can define their own
33 * "attributes" as an ExtensionType and add data to Identifiable instances via
34 * Extension instances.
37 * @created 08-Nov-2007 13:06:23
39 @XmlAccessorType(XmlAccessType
.FIELD
)
40 @XmlType(name
= "Extension", propOrder
= {
47 public class Extension
extends VersionableEntity
implements Cloneable
{
48 private static final long serialVersionUID
= -857207737641432202L;
49 @SuppressWarnings("unused")
50 private static final Logger logger
= Logger
.getLogger(Extension
.class);
52 @XmlElement(name
= "Value")
55 @XmlElement(name
= "ExtensionType")
57 @XmlSchemaType(name
= "IDREF")
58 @ManyToOne(fetch
= FetchType
.LAZY
)
59 private ExtensionType type
;
61 @XmlElement(name
= "ExtendedObject")
63 @XmlSchemaType(name
= "IDREF")
64 @Any(metaDef
= "CdmBase",
65 metaColumn
=@Column(name
= "extendedObj_type"),
66 fetch
= FetchType
.LAZY
,
68 @JoinColumn(name
= "extendedObj_id")
70 private IdentifiableEntity extendedObj
;
72 public static Extension
NewInstance(){
73 return new Extension();
76 public static Extension
NewInstance(IdentifiableEntity
<?
> extendedObject
, String value
, ExtensionType extensionType
){
77 Extension extension
= new Extension();
78 extension
.setValue(value
);
79 extension
.setType(extensionType
);
80 extendedObject
.addExtension(extension
);
85 * TODO should not be private but throws error in persistence/io test
88 protected Extension(){
91 public IdentifiableEntity
getExtendedObj() {
94 //for hibernate use only
95 protected void setExtendedObj(IdentifiableEntity extendedObj
) {
96 this.extendedObj
= extendedObj
;
100 public ExtensionType
getType(){
108 public void setType(ExtensionType type
){
112 public String
getValue(){
120 public void setValue(String value
){
124 //****************** CLONE ************************************************/
127 * @see java.lang.Object#clone()
130 public Object
clone() throws CloneNotSupportedException
{
131 Extension result
= (Extension
)super.clone();
132 //no changes to: type, value
137 * Clones this extension and sets the clone's extended object to 'extendedObject'
138 * @see java.lang.Object#clone()
140 public Extension
clone(IdentifiableEntity extendedObject
) throws CloneNotSupportedException
{
141 Extension result
= (Extension
)clone();
142 result
.setExtendedObj(extendedObject
);