TermBase and descendants indexed using hibernate search
[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.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.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 @Lob
55 private String value;
56
57 @XmlElement(name = "ExtensionType")
58 @XmlIDREF
59 @XmlSchemaType(name = "IDREF")
60 @ManyToOne(fetch = FetchType.LAZY)
61 private ExtensionType type;
62
63 @XmlElement(name = "ExtendedObject")
64 @XmlIDREF
65 @XmlSchemaType(name = "IDREF")
66 @Any(metaDef = "CdmBase",
67 metaColumn=@Column(name = "extendedObj_type"),
68 fetch = FetchType.LAZY,
69 optional = false)
70 @JoinColumn(name = "extendedObj_id")
71 @NotAudited
72 private IdentifiableEntity extendedObj;
73
74 public static Extension NewInstance(){
75 return new Extension();
76 }
77
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);
83 return extension;
84 }
85
86 /**
87 * TODO should not be private but throws error in persistence/io test
88 * Constructor
89 */
90 protected Extension(){
91 }
92
93 public IdentifiableEntity getExtendedObj() {
94 return extendedObj;
95 }
96 //TODO make not public, but TaxonTaoHibernateImpl.delete has to be changed then
97 public void setExtendedObj(IdentifiableEntity extendedObj) {
98 this.extendedObj = extendedObj;
99 }
100
101
102 public ExtensionType getType(){
103 return this.type;
104 }
105
106 /**
107 *
108 * @param type type
109 */
110 public void setType(ExtensionType type){
111 this.type = type;
112 }
113
114 public String getValue(){
115 return this.value;
116 }
117
118 /**
119 *
120 * @param value value
121 */
122 public void setValue(String value){
123 this.value = value;
124 }
125
126 //****************** CLONE ************************************************/
127
128 /* (non-Javadoc)
129 * @see java.lang.Object#clone()
130 */
131 @Override
132 public Object clone() throws CloneNotSupportedException{
133 Extension result = (Extension)super.clone();
134 //no changes to: type, value
135 return result;
136 }
137
138 /**
139 * Clones this extension and sets the clone's extended object to 'extendedObject'
140 * @see java.lang.Object#clone()
141 */
142 public Extension clone(IdentifiableEntity extendedObject) throws CloneNotSupportedException{
143 Extension result = (Extension)clone();
144 result.setExtendedObj(extendedObject);
145 return result;
146 }
147
148 }