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.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
25
|
import org.hibernate.envers.Audited;
|
26
|
import org.hibernate.search.annotations.Field;
|
27
|
import org.hibernate.search.annotations.Indexed;
|
28
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
29
|
import org.hibernate.search.annotations.Store;
|
30
|
|
31
|
import eu.etaxonomy.cdm.model.common.Language;
|
32
|
import eu.etaxonomy.cdm.model.common.MultilanguageText;
|
33
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
34
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
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
|
* @since 08-Nov-2007 13:06:17
|
47
|
*/
|
48
|
@XmlAccessorType(XmlAccessType.FIELD)
|
49
|
@XmlType(name = "CommonTaxonName", propOrder = {
|
50
|
"name",
|
51
|
"language",
|
52
|
"area"
|
53
|
})
|
54
|
@XmlRootElement(name = "CommonTaxonName")
|
55
|
@Entity
|
56
|
@Audited
|
57
|
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
|
58
|
public class CommonTaxonName extends DescriptionElementBase {
|
59
|
|
60
|
private static final long serialVersionUID = 2643808051976643339L;
|
61
|
private static final Logger logger = LogManager.getLogger(CommonTaxonName.class);
|
62
|
|
63
|
@XmlElement(name = "Name")
|
64
|
@Field(store=Store.YES)
|
65
|
private String name;
|
66
|
|
67
|
@XmlElement(name = "Language")
|
68
|
@XmlIDREF
|
69
|
@XmlSchemaType(name = "IDREF")
|
70
|
@ManyToOne(fetch = FetchType.LAZY)
|
71
|
@IndexedEmbedded(depth=1)
|
72
|
private Language language;
|
73
|
|
74
|
@XmlElement(name = "Area")
|
75
|
@XmlIDREF
|
76
|
@XmlSchemaType(name = "IDREF")
|
77
|
@ManyToOne(fetch = FetchType.LAZY)
|
78
|
@IndexedEmbedded(depth=1) // FIXME do we need a special field bridge for this type?
|
79
|
private NamedArea area;
|
80
|
|
81
|
|
82
|
/**
|
83
|
* Creates a common name instance with the given name string and the given
|
84
|
* {@link Language language}. The corresponding {@link Feature feature} is set to
|
85
|
* {@link Feature#COMMON_NAME() COMMON_NAME}.
|
86
|
*
|
87
|
* @param name the name string
|
88
|
* @param language the language of the name string
|
89
|
*/
|
90
|
public static CommonTaxonName NewInstance(String name, Language language){
|
91
|
return NewInstance(name, language, null);
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Creates a common name instance with the given name string and the given
|
96
|
* {@link Language language}. The corresponding {@link Feature feature} is set to
|
97
|
* {@link Feature#COMMON_NAME() COMMON_NAME}.
|
98
|
*
|
99
|
* @param name the name string
|
100
|
* @param language the language of the name string
|
101
|
* @param area the area where this common name is used
|
102
|
*/
|
103
|
public static CommonTaxonName NewInstance(String name, Language language, NamedArea area){
|
104
|
CommonTaxonName result = new CommonTaxonName();
|
105
|
result.setName(name);
|
106
|
result.setLanguage(language);
|
107
|
result.setArea(area);
|
108
|
return result;
|
109
|
}
|
110
|
|
111
|
|
112
|
// *************************** CONSTRUCTOR *************************************/
|
113
|
|
114
|
/**
|
115
|
* Class constructor: creates a new empty common name instance.
|
116
|
* The corresponding {@link Feature feature} is set to {@link Feature#COMMON_NAME() COMMON_NAME}.
|
117
|
*/
|
118
|
protected CommonTaxonName(){
|
119
|
super(Feature.COMMON_NAME());
|
120
|
}
|
121
|
|
122
|
// *************************** METHODS *****************************************/
|
123
|
|
124
|
/**
|
125
|
* @deprecated Deprecated because {@link Feature feature} should always be {@link Feature#COMMON_NAME() COMMON_NAME}
|
126
|
* for all common name instances.
|
127
|
*/
|
128
|
/* (non-Javadoc)
|
129
|
* @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
|
130
|
*/
|
131
|
@Override
|
132
|
@Deprecated
|
133
|
public void setFeature(Feature feature) {
|
134
|
super.setFeature(feature);
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* Returns the {@link Language language} used for <i>this</i> common name.
|
139
|
*/
|
140
|
public Language getLanguage(){
|
141
|
return this.language;
|
142
|
}
|
143
|
/**
|
144
|
* @see #getLanguage()
|
145
|
*/
|
146
|
public void setLanguage(Language language){
|
147
|
this.language = language;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Returns the name string of <i>this</i> common name.
|
152
|
*/
|
153
|
public String getName(){
|
154
|
return this.name;
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* @see #getName()
|
159
|
*/
|
160
|
public void setName(String name){
|
161
|
this.name = name;
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* The area where the name is used
|
166
|
* @return
|
167
|
*/
|
168
|
public NamedArea getArea() {
|
169
|
return area;
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* @see #getArea()
|
174
|
* @param area
|
175
|
*/
|
176
|
public void setArea(NamedArea area) {
|
177
|
this.area = area;
|
178
|
}
|
179
|
|
180
|
|
181
|
//*********************************** CLONE *****************************************/
|
182
|
|
183
|
/**
|
184
|
* Clones <i>this</i> common name. This is a shortcut that enables to create
|
185
|
* a new instance that differs only slightly from <i>this</i> common name by
|
186
|
* modifying only some of the attributes.
|
187
|
*
|
188
|
* @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
|
189
|
* @see java.lang.Object#clone()
|
190
|
*/
|
191
|
@Override
|
192
|
public CommonTaxonName clone() {
|
193
|
|
194
|
CommonTaxonName result = (CommonTaxonName)super.clone();
|
195
|
return result;
|
196
|
//no changes to name, language, area
|
197
|
}
|
198
|
|
199
|
//*********************************** toString *****************************************/
|
200
|
|
201
|
@Override
|
202
|
public String toString(){
|
203
|
if (isNotBlank(name)){
|
204
|
return name;
|
205
|
}else{
|
206
|
return super.toString();
|
207
|
}
|
208
|
}
|
209
|
}
|