root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/Extension.java

Revision 12649, 4.2 kB (checked in by a.mueller, 10 months ago)

toString for Annotation and Extension

  • Property svn:keywords set to Id
Line 
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
10package eu.etaxonomy.cdm.model.common;
11
12
13import javax.persistence.Column;
14import javax.persistence.Entity;
15import javax.persistence.FetchType;
16import javax.persistence.JoinColumn;
17import javax.persistence.Lob;
18import javax.persistence.ManyToOne;
19import javax.xml.bind.annotation.XmlAccessType;
20import javax.xml.bind.annotation.XmlAccessorType;
21import javax.xml.bind.annotation.XmlElement;
22import javax.xml.bind.annotation.XmlIDREF;
23import javax.xml.bind.annotation.XmlSchemaType;
24import javax.xml.bind.annotation.XmlType;
25
26import org.apache.commons.lang.StringUtils;
27import org.apache.log4j.Logger;
28import org.hibernate.annotations.Any;
29import org.hibernate.envers.Audited;
30import org.hibernate.envers.NotAudited;
31
32/**
33 * This class aims to make available more "attributes" for identifiable entities
34 * in a flexible way. Application developers (and even users) can define their own
35 * "attributes" as an ExtensionType and add data to Identifiable instances via
36 * Extension instances.
37 * @author m.doering
38 * @version 1.0
39 * @created 08-Nov-2007 13:06:23
40 */
41@XmlAccessorType(XmlAccessType.FIELD)
42@XmlType(name = "Extension", propOrder = {
43    "value",
44    "type",
45    "extendedObj"
46})
47@Entity
48@Audited
49public class Extension extends VersionableEntity implements Cloneable {
50        private static final long serialVersionUID = -857207737641432202L;
51        @SuppressWarnings("unused")
52        private static final  Logger logger = Logger.getLogger(Extension.class);
53       
54    @XmlElement(name = "Value")
55        @Lob
56    private String value;
57       
58    @XmlElement(name = "ExtensionType")
59    @XmlIDREF
60    @XmlSchemaType(name = "IDREF")
61    @ManyToOne(fetch = FetchType.LAZY)
62        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       
75        public static Extension NewInstance(){
76                return new Extension();
77        }
78       
79        public static Extension NewInstance(IdentifiableEntity<?> extendedObject, String value, ExtensionType extensionType){
80                Extension extension = new Extension();
81                extension.setValue(value);
82                extension.setType(extensionType);
83                extendedObject.addExtension(extension);
84                return extension;
85        }
86       
87        /**
88         * TODO should not be private but throws error in persistence/io test
89         * Constructor
90         */
91        protected Extension(){
92        }
93       
94        public IdentifiableEntity getExtendedObj() {
95                return extendedObj;
96        }
97        //TODO make not public, but TaxonTaoHibernateImpl.delete has to be changed then
98        public void setExtendedObj(IdentifiableEntity extendedObj) {
99                this.extendedObj = extendedObj;
100        }
101
102       
103        public ExtensionType getType(){
104                return this.type;
105        }
106
107        /**
108         *
109         * @param type    type
110         */
111        public void setType(ExtensionType type){
112                this.type = type;
113        }
114
115        public String getValue(){
116                return this.value;
117        }
118
119        /**
120         *
121         * @param value    value
122         */
123        public void setValue(String value){
124                this.value = value;
125        }
126
127//***************************** TO STRING ***********************************
128       
129        /* (non-Javadoc)
130         * @see eu.etaxonomy.cdm.model.common.CdmBase#toString()
131         */
132        @Override
133        public String toString() {
134                if (StringUtils.isNotBlank(this.value)){
135                        return "Ext.: " + this.value;
136                }else{
137                        return super.toString();
138                }
139        }
140       
141       
142//****************** CLONE ************************************************/
143         
144        /* (non-Javadoc)
145         * @see java.lang.Object#clone()
146         */
147        @Override
148        public Object clone() throws CloneNotSupportedException{
149                Extension result = (Extension)super.clone();   
150                //no changes to: type, value
151                return result;
152        }
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
164}
Note: See TracBrowser for help on using the browser.