9d55d33b64eb0865700d3417220f186c3f0058b4
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / Extension.java
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.ManyToOne;
18 import javax.persistence.Transient;
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.log4j.Logger;
27 import org.hibernate.annotations.Any;
28 import org.hibernate.envers.Audited;
29 import org.hibernate.envers.NotAudited;
30
31 /**
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.
36 * @author m.doering
37 * @version 1.0
38 * @created 08-Nov-2007 13:06:23
39 */
40 @XmlAccessorType(XmlAccessType.FIELD)
41 @XmlType(name = "Extension", propOrder = {
42 "value",
43 "type",
44 "extendedObj"
45 })
46 @Entity
47 @Audited
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);
52
53 @XmlElement(name = "Value")
54 private String value;
55
56 @XmlElement(name = "ExtensionType")
57 @XmlIDREF
58 @XmlSchemaType(name = "IDREF")
59 @ManyToOne(fetch = FetchType.LAZY)
60 private ExtensionType type;
61
62 @XmlElement(name = "ExtendedObject")
63 @XmlIDREF
64 @XmlSchemaType(name = "IDREF")
65 @Any(metaDef = "CdmBase",
66 metaColumn=@Column(name = "extendedObj_type"),
67 fetch = FetchType.LAZY,
68 optional = false)
69 @JoinColumn(name = "extendedObj_id")
70 @NotAudited
71 private IdentifiableEntity extendedObj;
72
73 public static Extension NewInstance(){
74 return new Extension();
75 }
76
77 /**
78 * TODO should not be private but throws error in persistence/io test
79 * Constructor
80 */
81 protected Extension(){
82
83 }
84
85 public IdentifiableEntity getExtendedObj() {
86 return extendedObj;
87 }
88 public void setExtendedObj(IdentifiableEntity extendedObj) {
89 this.extendedObj = extendedObj;
90 }
91
92
93 public ExtensionType getType(){
94 return this.type;
95 }
96
97 /**
98 *
99 * @param type type
100 */
101 public void setType(ExtensionType type){
102 this.type = type;
103 }
104
105 public String getValue(){
106 return this.value;
107 }
108
109 /**
110 *
111 * @param value value
112 */
113 public void setValue(String value){
114 this.value = value;
115 }
116
117 //****************** CLONE ************************************************/
118
119 /* (non-Javadoc)
120 * @see java.lang.Object#clone()
121 */
122 @Override
123 public Object clone() throws CloneNotSupportedException{
124 Extension result = (Extension)super.clone();
125 //no changes to: type, value
126 return result;
127 }
128
129 /**
130 * Clones this extension and sets the clone's extended object to 'extendedObject'
131 * @see java.lang.Object#clone()
132 */
133 public Extension clone(IdentifiableEntity extendedObject) throws CloneNotSupportedException{
134 Extension result = (Extension)clone();
135 result.setExtendedObj(extendedObject);
136 return result;
137 }
138
139 }