Project

General

Profile

Download (4.03 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 org.apache.log4j.Logger;
14
import org.hibernate.envers.Audited;
15
import org.hibernate.search.annotations.Field;
16
import org.hibernate.search.annotations.Index;
17
import org.hibernate.search.annotations.Indexed;
18

    
19
import javax.persistence.*;
20
import javax.xml.bind.annotation.XmlAccessType;
21
import javax.xml.bind.annotation.XmlAccessorType;
22
import javax.xml.bind.annotation.XmlElement;
23
import javax.xml.bind.annotation.XmlRootElement;
24
import javax.xml.bind.annotation.XmlType;
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(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(index=Index.TOKENIZED)
48
	private String label;
49
    
50
    @XmlElement(name = "AbbreviatedLabel")
51
    @Field(index=Index.TOKENIZED)
52
	private String abbreviatedLabel;
53

    
54
	/**
55
	 * @param text
56
	 * @param label
57
	 * @param lang
58
	 * @return
59
	 */
60
	public static Representation NewInstance(String text, String label, String abbreviatedLabel, Language lang){
61
		return new Representation(text, 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 text, String label, String abbreviatedLabel, Language language) {
73
		super(text, 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
}
(52-52/63)