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.description;
|
11
|
|
12
|
|
13
|
import javax.persistence.Entity;
|
14
|
import javax.persistence.FetchType;
|
15
|
import javax.persistence.ManyToOne;
|
16
|
import javax.xml.bind.annotation.XmlAccessType;
|
17
|
import javax.xml.bind.annotation.XmlAccessorType;
|
18
|
import javax.xml.bind.annotation.XmlElement;
|
19
|
import javax.xml.bind.annotation.XmlIDREF;
|
20
|
import javax.xml.bind.annotation.XmlRootElement;
|
21
|
import javax.xml.bind.annotation.XmlSchemaType;
|
22
|
import javax.xml.bind.annotation.XmlType;
|
23
|
|
24
|
import org.apache.commons.lang.StringUtils;
|
25
|
import org.apache.log4j.Logger;
|
26
|
import org.hibernate.envers.Audited;
|
27
|
import org.hibernate.search.annotations.Field;
|
28
|
import org.hibernate.search.annotations.Index;
|
29
|
import org.hibernate.search.annotations.Indexed;
|
30
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
31
|
|
32
|
import eu.etaxonomy.cdm.model.common.Language;
|
33
|
import eu.etaxonomy.cdm.model.common.MultilanguageText;
|
34
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
35
|
|
36
|
/**
|
37
|
* This class represents common or vernacular names for {@link Taxon taxa}.
|
38
|
* Only {@link TaxonDescription taxon descriptions} may contain common names.
|
39
|
* Common names vary not only according to the {@link Language language} but also sometimes
|
40
|
* according to {@link TaxonDescription#getGeoScopes() geospatial areas}. Furthermore there might be several
|
41
|
* distinct common names in one language and in the same geospatial area to
|
42
|
* designate the same taxon. Therefore using a {@link MultilanguageText multilanguage text}
|
43
|
* would not have been adequate.
|
44
|
*
|
45
|
* @author m.doering
|
46
|
* @version 1.0
|
47
|
* @created 08-Nov-2007 13:06:17
|
48
|
*/
|
49
|
@XmlAccessorType(XmlAccessType.FIELD)
|
50
|
@XmlType(name = "CommonTaxonName", propOrder = {
|
51
|
"name",
|
52
|
"language",
|
53
|
"area"
|
54
|
})
|
55
|
@XmlRootElement(name = "CommonTaxonName")
|
56
|
@Entity
|
57
|
@Audited
|
58
|
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
|
59
|
public class CommonTaxonName extends DescriptionElementBase implements Cloneable {
|
60
|
private static final long serialVersionUID = 2643808051976643339L;
|
61
|
private static final Logger logger = Logger.getLogger(CommonTaxonName.class);
|
62
|
|
63
|
@XmlElement(name = "Name")
|
64
|
@Field(index = Index.TOKENIZED)
|
65
|
private String name;
|
66
|
|
67
|
@XmlElement(name = "Language")
|
68
|
@XmlIDREF
|
69
|
@XmlSchemaType(name = "IDREF")
|
70
|
@ManyToOne(fetch = FetchType.LAZY)
|
71
|
@IndexedEmbedded(depth = 2)
|
72
|
private Language language;
|
73
|
|
74
|
@XmlElement(name = "Area")
|
75
|
@XmlIDREF
|
76
|
@XmlSchemaType(name = "IDREF")
|
77
|
@ManyToOne(fetch = FetchType.LAZY)
|
78
|
private NamedArea area;
|
79
|
|
80
|
/**
|
81
|
* Class constructor: creates a new empty common name instance.
|
82
|
* The corresponding {@link Feature feature} is set to {@link Feature#COMMON_NAME() COMMON_NAME}.
|
83
|
*/
|
84
|
protected CommonTaxonName(){
|
85
|
super(Feature.COMMON_NAME());
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Creates a common name instance with the given name string and the given
|
90
|
* {@link Language language}. The corresponding {@link Feature feature} is set to
|
91
|
* {@link Feature#COMMON_NAME() COMMON_NAME}.
|
92
|
*
|
93
|
* @param name the name string
|
94
|
* @param language the language of the name string
|
95
|
*/
|
96
|
public static CommonTaxonName NewInstance(String name, Language language){
|
97
|
logger.debug("NewInstance");
|
98
|
CommonTaxonName result = new CommonTaxonName();
|
99
|
result.setName(name);
|
100
|
result.setLanguage(language);
|
101
|
return result;
|
102
|
}
|
103
|
|
104
|
|
105
|
|
106
|
|
107
|
/**
|
108
|
* Deprecated because {@link Feature feature} should always be {@link Feature#COMMON_NAME() COMMON_NAME}
|
109
|
* for all common name instances.
|
110
|
*/
|
111
|
/* (non-Javadoc)
|
112
|
* @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
|
113
|
*/
|
114
|
@Override
|
115
|
@Deprecated
|
116
|
public void setFeature(Feature feature) {
|
117
|
super.setFeature(feature);
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Returns the {@link Language language} used for <i>this</i> common name.
|
122
|
*/
|
123
|
public Language getLanguage(){
|
124
|
return this.language;
|
125
|
}
|
126
|
/**
|
127
|
* @see #getLanguage()
|
128
|
*/
|
129
|
public void setLanguage(Language language){
|
130
|
this.language = language;
|
131
|
}
|
132
|
|
133
|
/**
|
134
|
* Returns the name string of <i>this</i> common name.
|
135
|
*/
|
136
|
public String getName(){
|
137
|
return this.name;
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* @see #getName()
|
142
|
*/
|
143
|
public void setName(String name){
|
144
|
this.name = name;
|
145
|
}
|
146
|
|
147
|
/**
|
148
|
* The area where the name is used
|
149
|
* @return
|
150
|
*/
|
151
|
public NamedArea getArea() {
|
152
|
return area;
|
153
|
}
|
154
|
|
155
|
/**
|
156
|
* @see #getArea()
|
157
|
* @param area
|
158
|
*/
|
159
|
public void setArea(NamedArea area) {
|
160
|
this.area = area;
|
161
|
}
|
162
|
|
163
|
|
164
|
//*********************************** CLONE *****************************************/
|
165
|
|
166
|
@Override
|
167
|
public Object clone() throws CloneNotSupportedException {
|
168
|
//no changes to name, language, area
|
169
|
return super.clone();
|
170
|
}
|
171
|
|
172
|
//*********************************** toString *****************************************/
|
173
|
|
174
|
@Override
|
175
|
public String toString(){
|
176
|
if (StringUtils.isNotBlank(name)){
|
177
|
return name;
|
178
|
}else{
|
179
|
return super.toString();
|
180
|
}
|
181
|
}
|
182
|
}
|