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
|
import javax.persistence.Entity;
|
13
|
import javax.persistence.FetchType;
|
14
|
import javax.persistence.ManyToOne;
|
15
|
import javax.xml.bind.annotation.XmlElement;
|
16
|
import javax.xml.bind.annotation.XmlIDREF;
|
17
|
import javax.xml.bind.annotation.XmlSchemaType;
|
18
|
import javax.xml.bind.annotation.XmlType;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.hibernate.annotations.Cascade;
|
22
|
import org.hibernate.annotations.CascadeType;
|
23
|
import org.hibernate.envers.Audited;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
|
26
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
27
|
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
|
28
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
29
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
30
|
|
31
|
/**
|
32
|
* This class represents an {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource}
|
33
|
* that can be used with {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase description elements}.
|
34
|
* Additionally to the core functionally of IOriginalSource a {@link eu.etaxonomy.cdm.model.name.TaxonName taxon name}
|
35
|
* can be stored that points to the name used in the source. This is needed because description always belong
|
36
|
* to accepted taxa while the referenced citations may use synonym names.
|
37
|
* </BR>
|
38
|
* The use of "originalNameString" within a DescriptionElementSource has to be discussed.
|
39
|
* In general this string is to be used for different representations of the sourced object. In this classes
|
40
|
* context it could also stand for the string representation of the taxon name used in the source. This
|
41
|
* may make sense if the taxon name is not available in the CDM and the user for some reason does not want
|
42
|
* to create a new ful {@link eu.etaxonomy.cdm.model.name.TaxonName taxon name}.
|
43
|
*
|
44
|
* @author a.mueller
|
45
|
* @created 18.09.2009
|
46
|
*/
|
47
|
@XmlType(name = "DescriptionElementSource", propOrder = {
|
48
|
"nameUsedInSource"
|
49
|
})
|
50
|
@Entity
|
51
|
@Audited
|
52
|
public class DescriptionElementSource extends OriginalSourceBase<DescriptionElementBase>{
|
53
|
private static final long serialVersionUID = -8487673428764273806L;
|
54
|
@SuppressWarnings("unused")
|
55
|
private static final Logger logger = Logger.getLogger(DescriptionElementSource.class);
|
56
|
|
57
|
/**
|
58
|
* Factory method
|
59
|
* @return
|
60
|
*/
|
61
|
public static DescriptionElementSource NewInstance(OriginalSourceType type){
|
62
|
return new DescriptionElementSource(type);
|
63
|
}
|
64
|
|
65
|
public static DescriptionElementSource NewDataImportInstance(String id){
|
66
|
DescriptionElementSource result = new DescriptionElementSource(OriginalSourceType.Import);
|
67
|
result.setIdInSource(id);
|
68
|
return result;
|
69
|
}
|
70
|
|
71
|
public static DescriptionElementSource NewDataImportInstance(String id, String idNamespace){
|
72
|
DescriptionElementSource result = NewDataImportInstance(id);
|
73
|
result.setIdNamespace(idNamespace);
|
74
|
return result;
|
75
|
}
|
76
|
|
77
|
public static DescriptionElementSource NewDataImportInstance(String id, String idNamespace, Reference ref){
|
78
|
DescriptionElementSource result = NewDataImportInstance(id, idNamespace);
|
79
|
result.setCitation(ref);
|
80
|
return result;
|
81
|
}
|
82
|
|
83
|
public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation){
|
84
|
DescriptionElementSource result = NewInstance(type);
|
85
|
result.setIdInSource(id);
|
86
|
result.setIdNamespace(idNamespace);
|
87
|
result.setCitation(citation);
|
88
|
return result;
|
89
|
}
|
90
|
|
91
|
public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation){
|
92
|
DescriptionElementSource result = NewInstance(type, id, idNamespace, citation);
|
93
|
result.setCitationMicroReference(microCitation);
|
94
|
return result;
|
95
|
}
|
96
|
|
97
|
public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microReference, TaxonName nameUsedInSource, String originalNameString){
|
98
|
DescriptionElementSource result = NewInstance(type, id, idNamespace, citation, microReference);
|
99
|
result.setNameUsedInSource(nameUsedInSource);
|
100
|
result.setOriginalNameString(originalNameString);
|
101
|
return result;
|
102
|
}
|
103
|
|
104
|
public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microCitation){
|
105
|
DescriptionElementSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
|
106
|
result.setCitation(citation);
|
107
|
result.setCitationMicroReference(microCitation);
|
108
|
return result;
|
109
|
}
|
110
|
|
111
|
public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microReference, TaxonName nameUsedInSource, String originalNameString){
|
112
|
DescriptionElementSource result = NewPrimarySourceInstance(citation, microReference);
|
113
|
result.setNameUsedInSource(nameUsedInSource);
|
114
|
result.setOriginalNameString(originalNameString);
|
115
|
return result;
|
116
|
}
|
117
|
|
118
|
// ************************* FIELDS ********************************/
|
119
|
|
120
|
@XmlElement(name = "nameUsedInSource")
|
121
|
@XmlIDREF
|
122
|
@XmlSchemaType(name = "IDREF")
|
123
|
@ManyToOne(fetch = FetchType.LAZY)
|
124
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
125
|
private TaxonName nameUsedInSource;
|
126
|
|
127
|
//*********************** CONSTRUCTOR ******************************/
|
128
|
|
129
|
//for hibernate use only
|
130
|
private DescriptionElementSource(){
|
131
|
super();
|
132
|
}
|
133
|
|
134
|
private DescriptionElementSource(OriginalSourceType type){
|
135
|
super(type);
|
136
|
}
|
137
|
|
138
|
|
139
|
// ************************** GETTER / SETTER ***************************/
|
140
|
|
141
|
/**
|
142
|
* @return the taxonNameUsedInSource
|
143
|
*/
|
144
|
public TaxonName getNameUsedInSource() {
|
145
|
return nameUsedInSource;
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* @param nameUsedInReference the nameUsedInReference to set
|
150
|
*/
|
151
|
public void setNameUsedInSource(TaxonName nameUsedInSource) {
|
152
|
this.nameUsedInSource = nameUsedInSource;
|
153
|
}
|
154
|
|
155
|
|
156
|
//*********************************** CLONE *********************************************************/
|
157
|
|
158
|
@Override
|
159
|
public Object clone() throws CloneNotSupportedException{
|
160
|
DescriptionElementSource result = (DescriptionElementSource)super.clone();
|
161
|
|
162
|
//no changes
|
163
|
return result;
|
164
|
}
|
165
|
|
166
|
//*********************************** EQUALS *********************************************************/
|
167
|
|
168
|
/**
|
169
|
* {@inheritDoc}
|
170
|
*/
|
171
|
@Override
|
172
|
public boolean equalsByShallowCompare(ReferencedEntityBase other) {
|
173
|
|
174
|
if(!super.equalsByShallowCompare(other)) {
|
175
|
return false;
|
176
|
}
|
177
|
|
178
|
int a = -1;
|
179
|
int b = -1;
|
180
|
if(this.getNameUsedInSource() != null) {
|
181
|
a = this.getNameUsedInSource().getId();
|
182
|
}
|
183
|
DescriptionElementSource otherDescriptionElementSource = (DescriptionElementSource)other;
|
184
|
if(otherDescriptionElementSource.getNameUsedInSource() != null) {
|
185
|
b = otherDescriptionElementSource.getNameUsedInSource().getId();
|
186
|
}
|
187
|
return a == b;
|
188
|
}
|
189
|
|
190
|
|
191
|
}
|