(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / LanguageStringBase.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 import org.apache.log4j.Logger;
13 import javax.persistence.*;
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlIDREF;
18 import javax.xml.bind.annotation.XmlSchemaType;
19 import javax.xml.bind.annotation.XmlType;
20
21 /**
22 * @author a.mueller
23 * @version 1.0
24 * @created 25.04.2008
25 */
26 @XmlAccessorType(XmlAccessType.FIELD)
27 @XmlType(name = "LanguageStringBase", propOrder = {
28 "text",
29 "language"
30 })
31 @MappedSuperclass
32 public abstract class LanguageStringBase extends VersionableEntity{
33
34 static Logger logger = Logger.getLogger(LanguageStringBase.class);
35
36 @XmlElement(name = "Text")
37 protected String text;
38
39 @XmlElement(name = "Language")
40 @XmlIDREF
41 @XmlSchemaType(name = "IDREF")
42 protected Language language;
43
44 protected LanguageStringBase() {
45 super();
46 }
47
48 protected LanguageStringBase(String text, Language language) {
49 super();
50 this.setLanguage(language);
51 this.setText(text);
52
53 }
54
55 @ManyToOne
56 //@Cascade({CascadeType.SAVE_UPDATE})
57 public Language getLanguage(){
58 return this.language;
59 }
60 public void setLanguage(Language language){
61 this.language = language;
62 }
63
64 @Column(length=4096)
65 public String getText(){
66 return this.text;
67 }
68 protected void setText(String text) {
69 this.text = text;
70 }
71
72 @Transient
73 public String getLanguageLabel(){
74 if (language != null){
75 return this.language.getRepresentation(Language.DEFAULT()).getLabel();
76 }else{
77 return null;
78 }
79 }
80 @Transient
81 public String getLanguageLabel(Language lang){
82 if (language != null){
83 return this.language.getRepresentation(lang).getLabel();
84 }else{
85 return null;
86 }
87 }
88 }