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

Revision 11651, 3.1 kB (checked in by k.luther, 14 months ago)

clone methods for common

  • 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
12import javax.persistence.Column;
13import javax.persistence.FetchType;
14import javax.persistence.Lob;
15import javax.persistence.ManyToOne;
16import javax.persistence.MappedSuperclass;
17import javax.persistence.Transient;
18
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.XmlSeeAlso;
25import javax.xml.bind.annotation.XmlType;
26import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
27
28import org.apache.log4j.Logger;
29import org.hibernate.annotations.CascadeType;
30import org.hibernate.annotations.Cascade;
31import org.hibernate.search.annotations.Field;
32import org.hibernate.search.annotations.FieldBridge;
33import org.hibernate.search.annotations.Index;
34
35import eu.etaxonomy.cdm.hibernate.StripHtmlBridge;
36import eu.etaxonomy.cdm.jaxb.FormattedTextAdapter;
37
38/**
39 * @author a.mueller
40 * @version 1.0
41 * @created 25.04.2008
42 */
43@XmlAccessorType(XmlAccessType.FIELD)
44@XmlType(name = "LanguageStringBase", propOrder = {
45    "text",
46    "language"
47})
48@XmlSeeAlso({
49        LanguageString.class
50})
51@MappedSuperclass
52public abstract class LanguageStringBase extends AnnotatableEntity{
53        private static final long serialVersionUID = -1892526642162438277L;
54        @SuppressWarnings("unused")
55        private static final Logger logger = Logger.getLogger(LanguageStringBase.class);
56
57        @XmlElement(name = "Text")
58        @XmlJavaTypeAdapter(FormattedTextAdapter.class)
59        @Column(length=65536)
60        @Field(index=Index.TOKENIZED)
61        @FieldBridge(impl=StripHtmlBridge.class)
62        @Lob
63        protected String text;
64       
65        @XmlElement(name = "Language")
66        @XmlIDREF
67        @XmlSchemaType(name = "IDREF")
68        @ManyToOne(fetch = FetchType.EAGER)
69        @Cascade({CascadeType.MERGE})
70        protected Language language;
71
72        protected LanguageStringBase() {
73                super();
74        }
75
76        protected LanguageStringBase(String text, Language language) {
77                super();
78                this.setLanguage(language);
79                this.setText(text);
80               
81        }
82       
83        public Language getLanguage(){
84                return this.language;
85        }
86        public void setLanguage(Language language){
87                this.language = language;
88        }
89
90        public String getText(){
91                return this.text;
92        }
93       
94        public void setText(String text) {
95                this.text = text;
96        }
97       
98        @Transient
99        public String getLanguageLabel(){
100                if (language != null){
101                        return this.language.getRepresentation(Language.DEFAULT()).getLabel();
102                }else{
103                        return null;
104                }
105        }
106
107        public String getLanguageLabel(Language lang){
108                if (language != null){
109                        return this.language.getRepresentation(lang).getLabel();
110                }else{
111                        return null;
112                }
113        }
114       
115        @Override
116        public Object clone() throws CloneNotSupportedException{
117                LanguageStringBase result = (LanguageStringBase) super.clone();
118                //no changes to text and language
119                //result.setText(this.text);
120                //result.setLanguage(this.language);
121                return result;
122        }
123}
Note: See TracBrowser for help on using the browser.