Project

General

Profile

Download (4.43 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
 * @since 08-Nov-2007 13:06:49
30
 */
31

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

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

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

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

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

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

    
78

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

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

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

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

    
107

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

    
122

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

    
134
//*********************** CLONE ********************************************************/
135

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

    
156
    }
157
}
(65-65/80)