Project

General

Profile

Download (4.42 KB) Statistics
| Branch: | Tag: | Revision:
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.Entity;
14
import javax.persistence.Transient;
15
import javax.xml.bind.annotation.XmlAccessType;
16
import javax.xml.bind.annotation.XmlAccessorType;
17
import javax.xml.bind.annotation.XmlElement;
18
import javax.xml.bind.annotation.XmlRootElement;
19
import javax.xml.bind.annotation.XmlType;
20

    
21
import org.apache.log4j.Logger;
22
import org.hibernate.envers.Audited;
23
import org.hibernate.search.annotations.Field;
24
import org.hibernate.search.annotations.Store;
25

    
26
/**
27
 * workaround for enumerations
28
 * @author m.doering
29
 * @version 1.0
30
 * @created 08-Nov-2007 13:06:49
31
 */
32

    
33
@XmlAccessorType(XmlAccessType.FIELD)
34
@XmlType(name = "Representation", propOrder = {
35
    "label",
36
    "abbreviatedLabel"
37
})
38
@XmlRootElement(name = "Representation")
39
@Entity
40
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
41
//@Indexed(index = "eu.etaxonomy.cdm.model.common.Representation")
42
@Audited
43
public class Representation extends LanguageStringBase {
44
    private static final long serialVersionUID = -4202420199587324532L;
45
    private static final Logger logger = Logger.getLogger(Representation.class);
46

    
47
    @XmlElement(name = "Label")
48
    @Field(store=Store.YES)
49
    private String label;
50

    
51
    @XmlElement(name = "AbbreviatedLabel")
52
    @Field(store=Store.YES)
53
    private String abbreviatedLabel;
54

    
55
    /**
56
     * @param text
57
     * @param label
58
     * @param lang
59
     * @return
60
     */
61
    public static Representation NewInstance(String text, String label, String abbreviatedLabel, Language lang){
62
        return new Representation(text, label, abbreviatedLabel, lang);
63
    }
64

    
65
    public Representation() {
66
        super();
67
    }
68

    
69
    /**
70
     * text represents an explanation/declaration ('The name is illegitimate according to ICBN'); label a string identifier ('illegitimate name');
71
     * abbreviatedLabel a shortened string for the label ('nom. illeg.')
72
     */
73
    public Representation(String text, String label, String abbreviatedLabel, Language language) {
74
        super(text, language);
75
        this.label = label;
76
        this.abbreviatedLabel = abbreviatedLabel;
77
    }
78

    
79

    
80
    public String getLabel(){
81
        return this.label;
82
    }
83
    public void setLabel(String label){
84
        this.label = label;
85
    }
86

    
87
    public String getAbbreviatedLabel(){
88
        return this.abbreviatedLabel;
89
    }
90
    public void setAbbreviatedLabel(String abbreviatedLabel){
91
        this.abbreviatedLabel = abbreviatedLabel;
92
    }
93

    
94
    /**
95
     * Returns the description of this representation
96
     * see {@link #getText()}
97
     * @return
98
     */
99
    @Transient
100
    public String getDescription(){
101
        return getText();
102
    }
103

    
104
    protected void setDescription(String text) {
105
        super.setText(text);
106
    }
107

    
108

    
109
    /*
110
     * Overrides super.getText() only to document that here the Text attribute
111
     * should be used for a larger description of the label.
112
     */
113
    /**
114
     * Returns the description of this representation.
115
     * @see #getDescription()
116
     */
117
    @Transient
118
    @Override
119
    public String getText(){
120
        return super.getText();
121
    }
122

    
123

    
124
    @Override
125
    public String toString(){
126
        // we dont need the language returned too, do we?
127
        return getLabel();
128
//		if(getLanguage()==null || getLanguage().getLabel()==null){
129
//			return getLabel();
130
//		}else{
131
//			return getLabel()+"("+ getLanguage().getLabel()+")";
132
//		}
133
    }
134

    
135
//*********************** CLONE ********************************************************/
136

    
137
    /**
138
     * Clones <i>this</i> Representation. This is a shortcut that enables to create
139
     * a new instance that differs only slightly from <i>this</i> Representation by
140
     * modifying only some of the attributes.
141
     *
142
     * @see eu.etaxonomy.cdm.model.common.LanguageStringBase#clone()
143
     * @see java.lang.Object#clone()
144
     */
145
    @Override
146
    public Object clone() {
147
        try{
148
            Representation result = (Representation) super.clone();
149
            //no changes to abbreviatedLabel and label
150
            return result;
151
        }catch (CloneNotSupportedException e) {
152
            logger.warn("Object does not implement cloneable");
153
            e.printStackTrace();
154
            return null;
155
        }
156

    
157
    }
158
}
(61-61/72)