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.Indexed;
|
29
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
30
|
import org.hibernate.search.annotations.Store;
|
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
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
36
|
|
37
|
/**
|
38
|
* This class represents common or vernacular names for {@link Taxon taxa}.
|
39
|
* Only {@link TaxonDescription taxon descriptions} may contain common names.
|
40
|
* Common names vary not only according to the {@link Language language} but also sometimes
|
41
|
* according to {@link TaxonDescription#getGeoScopes() geospatial areas}. Furthermore there might be several
|
42
|
* distinct common names in one language and in the same geospatial area to
|
43
|
* designate the same taxon. Therefore using a {@link MultilanguageText multilanguage text}
|
44
|
* would not have been adequate.
|
45
|
*
|
46
|
* @author m.doering
|
47
|
* @version 1.0
|
48
|
* @created 08-Nov-2007 13:06:17
|
49
|
*/
|
50
|
@XmlAccessorType(XmlAccessType.FIELD)
|
51
|
@XmlType(name = "CommonTaxonName", propOrder = {
|
52
|
"name",
|
53
|
"language",
|
54
|
"area"
|
55
|
})
|
56
|
@XmlRootElement(name = "CommonTaxonName")
|
57
|
@Entity
|
58
|
@Audited
|
59
|
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
|
60
|
public class CommonTaxonName extends DescriptionElementBase implements Cloneable {
|
61
|
private static final long serialVersionUID = 2643808051976643339L;
|
62
|
private static final Logger logger = Logger.getLogger(CommonTaxonName.class);
|
63
|
|
64
|
@XmlElement(name = "Name")
|
65
|
@Field(store=Store.YES)
|
66
|
private String name;
|
67
|
|
68
|
@XmlElement(name = "Language")
|
69
|
@XmlIDREF
|
70
|
@XmlSchemaType(name = "IDREF")
|
71
|
@ManyToOne(fetch = FetchType.LAZY)
|
72
|
@IndexedEmbedded(depth=1)
|
73
|
private Language language;
|
74
|
|
75
|
@XmlElement(name = "Area")
|
76
|
@XmlIDREF
|
77
|
@XmlSchemaType(name = "IDREF")
|
78
|
@ManyToOne(fetch = FetchType.LAZY)
|
79
|
@IndexedEmbedded(depth=1) // FIXME do we need a special field bridge for this type?
|
80
|
private NamedArea area;
|
81
|
|
82
|
|
83
|
/**
|
84
|
* Creates a common name instance with the given name string and the given
|
85
|
* {@link Language language}. The corresponding {@link Feature feature} is set to
|
86
|
* {@link Feature#COMMON_NAME() COMMON_NAME}.
|
87
|
*
|
88
|
* @param name the name string
|
89
|
* @param language the language of the name string
|
90
|
*/
|
91
|
public static CommonTaxonName NewInstance(String name, Language language){
|
92
|
return NewInstance(name, language, null);
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Creates a common name instance with the given name string and the given
|
97
|
* {@link Language language}. The corresponding {@link Feature feature} is set to
|
98
|
* {@link Feature#COMMON_NAME() COMMON_NAME}.
|
99
|
*
|
100
|
* @param name the name string
|
101
|
* @param language the language of the name string
|
102
|
* @param area the area where this common name is used
|
103
|
*/
|
104
|
public static CommonTaxonName NewInstance(String name, Language language, NamedArea area){
|
105
|
CommonTaxonName result = new CommonTaxonName();
|
106
|
result.setName(name);
|
107
|
result.setLanguage(language);
|
108
|
result.setArea(area);
|
109
|
return result;
|
110
|
}
|
111
|
|
112
|
|
113
|
// *************************** CONSTRUCTOR *************************************/
|
114
|
|
115
|
/**
|
116
|
* Class constructor: creates a new empty common name instance.
|
117
|
* The corresponding {@link Feature feature} is set to {@link Feature#COMMON_NAME() COMMON_NAME}.
|
118
|
*/
|
119
|
protected CommonTaxonName(){
|
120
|
super(Feature.COMMON_NAME());
|
121
|
}
|
122
|
|
123
|
// *************************** METHODS *****************************************/
|
124
|
|
125
|
/**
|
126
|
* @deprecated Deprecated because {@link Feature feature} should always be {@link Feature#COMMON_NAME() COMMON_NAME}
|
127
|
* for all common name instances.
|
128
|
*/
|
129
|
/* (non-Javadoc)
|
130
|
* @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
|
131
|
*/
|
132
|
@Override
|
133
|
@Deprecated
|
134
|
public void setFeature(Feature feature) {
|
135
|
super.setFeature(feature);
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Returns the {@link Language language} used for <i>this</i> common name.
|
140
|
*/
|
141
|
public Language getLanguage(){
|
142
|
return this.language;
|
143
|
}
|
144
|
/**
|
145
|
* @see #getLanguage()
|
146
|
*/
|
147
|
public void setLanguage(Language language){
|
148
|
this.language = language;
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* Returns the name string of <i>this</i> common name.
|
153
|
*/
|
154
|
public String getName(){
|
155
|
return this.name;
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* @see #getName()
|
160
|
*/
|
161
|
public void setName(String name){
|
162
|
this.name = name;
|
163
|
}
|
164
|
|
165
|
/**
|
166
|
* The area where the name is used
|
167
|
* @return
|
168
|
*/
|
169
|
public NamedArea getArea() {
|
170
|
return area;
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* @see #getArea()
|
175
|
* @param area
|
176
|
*/
|
177
|
public void setArea(NamedArea area) {
|
178
|
this.area = area;
|
179
|
}
|
180
|
|
181
|
|
182
|
//*********************************** CLONE *****************************************/
|
183
|
|
184
|
/**
|
185
|
* Clones <i>this</i> common name. This is a shortcut that enables to create
|
186
|
* a new instance that differs only slightly from <i>this</i> common name by
|
187
|
* modifying only some of the attributes.
|
188
|
*
|
189
|
* @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
|
190
|
* @see java.lang.Object#clone()
|
191
|
*/
|
192
|
@Override
|
193
|
public Object clone() {
|
194
|
|
195
|
try {
|
196
|
CommonTaxonName result = (CommonTaxonName)super.clone();
|
197
|
return result;
|
198
|
//no changes to name, language, area
|
199
|
} catch (CloneNotSupportedException e) {
|
200
|
logger.warn("Object does not implement cloneable");
|
201
|
e.printStackTrace();
|
202
|
return null;
|
203
|
}
|
204
|
}
|
205
|
|
206
|
//*********************************** toString *****************************************/
|
207
|
|
208
|
@Override
|
209
|
public String toString(){
|
210
|
if (StringUtils.isNotBlank(name)){
|
211
|
return name;
|
212
|
}else{
|
213
|
return super.toString();
|
214
|
}
|
215
|
}
|
216
|
}
|