Project

General

Profile

« Previous | Next » 

Revision 664e623c

Added by Andreas Müller almost 8 years ago

Clean up DescriptionElementSource.java

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionElementSource.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.model.description;
12

  
13
import javax.persistence.Column;
14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.JoinColumn;
17
import javax.persistence.ManyToOne;
18
import javax.xml.bind.annotation.XmlElement;
19
import javax.xml.bind.annotation.XmlIDREF;
20
import javax.xml.bind.annotation.XmlSchemaType;
21
import javax.xml.bind.annotation.XmlType;
22

  
23
import org.apache.log4j.Logger;
24
import org.hibernate.annotations.Any;
25
import org.hibernate.annotations.Cascade;
26
import org.hibernate.annotations.CascadeType;
27
import org.hibernate.envers.Audited;
28
import org.hibernate.envers.NotAudited;
29

  
30
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
31
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
32
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
33
import eu.etaxonomy.cdm.model.reference.Reference;
34

  
35
/**
36
 * This class represents an {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource}
37
 * that can be used with {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase description elements}.
38
 * Additionally to the core functionally of IOriginalSource a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}
39
 * can be stored that points to the name used in the source. This is needed because description always belong
40
 * to accepted taxa while the referenced citations may use synonym names.
41
 * </BR>
42
 * The use of "originalNameString" within a DescriptionElementSource has to be discussed.
43
 * In general this string is to be used for different representations of the sourced object. In this classes
44
 * context it could also stand for the string representation of the taxon name used in the source. This
45
 * may make sense if the taxon name is not available in the CDM and the user for some reason does not want
46
 * to create a new ful {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}.
47
 *
48
 * @author a.mueller
49
 * @created 18.09.2009
50
 */
51
@XmlType(name = "DescriptionElementSource", propOrder = {
52
	    "sourcedObj",
53
	    "nameUsedInSource"
54
	})
55
@Entity
56
@Audited
57
public class DescriptionElementSource extends OriginalSourceBase<DescriptionElementBase>{
58
	private static final long serialVersionUID = -8487673428764273806L;
59
	@SuppressWarnings("unused")
60
	private static final Logger logger = Logger.getLogger(DescriptionElementSource.class);
61

  
62
	/**
63
	 * Factory method
64
	 * @return
65
	 */
66
	public static DescriptionElementSource NewInstance(OriginalSourceType type){
67
		return new DescriptionElementSource(type);
68
	}
69

  
70
	public static DescriptionElementSource NewDataImportInstance(String id){
71
		DescriptionElementSource result = new DescriptionElementSource(OriginalSourceType.Import);
72
		result.setIdInSource(id);
73
		return result;
74
	}
75

  
76
	public static DescriptionElementSource NewDataImportInstance(String id, String idNamespace){
77
		DescriptionElementSource result = NewDataImportInstance(id);
78
		result.setIdNamespace(idNamespace);
79
		return result;
80
	}
81

  
82
	public static DescriptionElementSource NewDataImportInstance(String id, String idNamespace, Reference ref){
83
		DescriptionElementSource result = NewDataImportInstance(id, idNamespace);
84
		result.setCitation(ref);
85
		return result;
86
	}
87

  
88
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation){
89
		DescriptionElementSource result = NewInstance(type);
90
		result.setIdInSource(id);
91
		result.setIdNamespace(idNamespace);
92
		result.setCitation(citation);
93
		return result;
94
	}
95

  
96
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation){
97
		DescriptionElementSource result = NewInstance(type, id, idNamespace, citation);
98
		result.setCitationMicroReference(microCitation);
99
		return result;
100
	}
101

  
102
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){
103
		DescriptionElementSource result = NewInstance(type, id, idNamespace, citation, microReference);
104
		result.setNameUsedInSource(nameUsedInSource);
105
		result.setOriginalNameString(originalNameString);
106
		return result;
107
	}
108

  
109
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microCitation){
110
		DescriptionElementSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
111
		result.setCitation(citation);
112
		result.setCitationMicroReference(microCitation);
113
		return result;
114
	}
115

  
116
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){
117
		DescriptionElementSource result = NewPrimarySourceInstance(citation, microReference);
118
		result.setNameUsedInSource(nameUsedInSource);
119
		result.setOriginalNameString(originalNameString);
120
		return result;
121
	}
122

  
123

  
124

  
125
	@XmlElement(name = "SourcedObject")
126
    @XmlIDREF
127
    @XmlSchemaType(name = "IDREF")
128
	@Any(metaDef = "CdmBase",
129
	    	 metaColumn=@Column(name = "sourcedObj_type"),
130
	    	 fetch = FetchType.LAZY,
131
	    	 optional = false)
132
	@JoinColumn(name = "sourcedObj_id")
133
	@ManyToOne(fetch = FetchType.LAZY)
134
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
135
	@NotAudited
136
	private DescriptionElementBase sourcedObj;
137

  
138
	@XmlElement(name = "nameUsedInSource")
139
	@XmlIDREF
140
	@XmlSchemaType(name = "IDREF")
141
	@ManyToOne(fetch = FetchType.LAZY)
142
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
143
	private TaxonNameBase<?,?> nameUsedInSource;
144

  
145
//*********************** CONSTRUCTOR ******************************/
146

  
147
	//for hibernate use only
148
	private DescriptionElementSource(){
149
		super();
150
	}
151

  
152
	private DescriptionElementSource(OriginalSourceType type){
153
		super(type);
154
	}
155

  
156

  
157
// **************************  GETTER / SETTER ***************************/
158

  
159

  
160
	/* (non-Javadoc)
161
	 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#getSourcedObj()
162
	 */
163
	@Override
164
    public DescriptionElementBase getSourcedObj() {
165
		return sourcedObj;
166
	}
167

  
168
	/* (non-Javadoc)
169
	 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#setSourcedObj(eu.etaxonomy.cdm.model.common.ISourceable)
170
	 */
171
	@Override
172
    public void setSourcedObj(DescriptionElementBase sourcedObj) {
173
		this.sourcedObj = sourcedObj;
174
	}
175

  
176

  
177
	/**
178
	 * @return the taxonNameUsedInSource
179
	 */
180
	public TaxonNameBase getNameUsedInSource() {
181
		return nameUsedInSource;
182
	}
183

  
184
	/**
185
	 * @param nameUsedInReference the nameUsedInReference to set
186
	 */
187
	public void setNameUsedInSource(TaxonNameBase nameUsedInSource) {
188
		this.nameUsedInSource = nameUsedInSource;
189
	}
190

  
191

  
192
//*********************************** CLONE *********************************************************/
193

  
194

  
195
	/**
196
	 * Clones this original source and sets the clones sourced object to 'sourceObj'
197
	 * @see java.lang.Object#clone()
198
	 */
199
	public DescriptionElementSource clone(DescriptionElementBase sourcedObj) throws CloneNotSupportedException{
200
		DescriptionElementSource result = (DescriptionElementSource)clone();
201
		result.setSourcedObj(sourcedObj);
202
		return result;
203
	}
204

  
205

  
206
	/* (non-Javadoc)
207
	 * @see eu.etaxonomy.cdm.model.common.OriginalSourceBase#clone()
208
	 * @see java.lang.Object#clone()
209
	 */
210
	@Override
211
	public Object clone() throws CloneNotSupportedException{
212
		DescriptionElementSource result = (DescriptionElementSource)super.clone();
213

  
214
		//no changes to: sourcedObj
215
		return result;
216
	}
217

  
218

  
219

  
220
}
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.model.description;
12

  
13
import javax.persistence.Column;
14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.JoinColumn;
17
import javax.persistence.ManyToOne;
18
import javax.xml.bind.annotation.XmlElement;
19
import javax.xml.bind.annotation.XmlIDREF;
20
import javax.xml.bind.annotation.XmlSchemaType;
21
import javax.xml.bind.annotation.XmlType;
22

  
23
import org.apache.log4j.Logger;
24
import org.hibernate.annotations.Any;
25
import org.hibernate.annotations.Cascade;
26
import org.hibernate.annotations.CascadeType;
27
import org.hibernate.envers.Audited;
28
import org.hibernate.envers.NotAudited;
29

  
30
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
31
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
32
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
33
import eu.etaxonomy.cdm.model.reference.Reference;
34

  
35
/**
36
 * This class represents an {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource}
37
 * that can be used with {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase description elements}.
38
 * Additionally to the core functionally of IOriginalSource a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}
39
 * can be stored that points to the name used in the source. This is needed because description always belong
40
 * to accepted taxa while the referenced citations may use synonym names.
41
 * </BR>
42
 * The use of "originalNameString" within a DescriptionElementSource has to be discussed.
43
 * In general this string is to be used for different representations of the sourced object. In this classes
44
 * context it could also stand for the string representation of the taxon name used in the source. This
45
 * may make sense if the taxon name is not available in the CDM and the user for some reason does not want
46
 * to create a new ful {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}.
47
 *
48
 * @author a.mueller
49
 * @created 18.09.2009
50
 */
51
@XmlType(name = "DescriptionElementSource", propOrder = {
52
	    "sourcedObj",
53
	    "nameUsedInSource"
54
	})
55
@Entity
56
@Audited
57
public class DescriptionElementSource extends OriginalSourceBase<DescriptionElementBase>{
58
	private static final long serialVersionUID = -8487673428764273806L;
59
	@SuppressWarnings("unused")
60
	private static final Logger logger = Logger.getLogger(DescriptionElementSource.class);
61

  
62
	/**
63
	 * Factory method
64
	 * @return
65
	 */
66
	public static DescriptionElementSource NewInstance(OriginalSourceType type){
67
		return new DescriptionElementSource(type);
68
	}
69

  
70
	public static DescriptionElementSource NewDataImportInstance(String id){
71
		DescriptionElementSource result = new DescriptionElementSource(OriginalSourceType.Import);
72
		result.setIdInSource(id);
73
		return result;
74
	}
75

  
76
	public static DescriptionElementSource NewDataImportInstance(String id, String idNamespace){
77
		DescriptionElementSource result = NewDataImportInstance(id);
78
		result.setIdNamespace(idNamespace);
79
		return result;
80
	}
81

  
82
	public static DescriptionElementSource NewDataImportInstance(String id, String idNamespace, Reference ref){
83
		DescriptionElementSource result = NewDataImportInstance(id, idNamespace);
84
		result.setCitation(ref);
85
		return result;
86
	}
87

  
88
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation){
89
		DescriptionElementSource result = NewInstance(type);
90
		result.setIdInSource(id);
91
		result.setIdNamespace(idNamespace);
92
		result.setCitation(citation);
93
		return result;
94
	}
95

  
96
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation){
97
		DescriptionElementSource result = NewInstance(type, id, idNamespace, citation);
98
		result.setCitationMicroReference(microCitation);
99
		return result;
100
	}
101

  
102
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){
103
		DescriptionElementSource result = NewInstance(type, id, idNamespace, citation, microReference);
104
		result.setNameUsedInSource(nameUsedInSource);
105
		result.setOriginalNameString(originalNameString);
106
		return result;
107
	}
108

  
109
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microCitation){
110
		DescriptionElementSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
111
		result.setCitation(citation);
112
		result.setCitationMicroReference(microCitation);
113
		return result;
114
	}
115

  
116
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){
117
		DescriptionElementSource result = NewPrimarySourceInstance(citation, microReference);
118
		result.setNameUsedInSource(nameUsedInSource);
119
		result.setOriginalNameString(originalNameString);
120
		return result;
121
	}
122

  
123

  
124
//TODO evtl. JoinTable http://www.programcreek.com/java-api-examples/index.php?api=org.hibernate.annotations.AnyMetaDef
125

  
126
	@XmlElement(name = "SourcedObject")
127
    @XmlIDREF
128
    @XmlSchemaType(name = "IDREF")
129
	@Any(metaDef = "CdmBase",
130
	    	 metaColumn=@Column(name = "sourcedObj_type"),
131
	    	 fetch = FetchType.LAZY,
132
	    	 optional = false)
133
	@JoinColumn(name = "sourcedObj_id")
134
	@ManyToOne(fetch = FetchType.LAZY)
135
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
136
	@NotAudited
137
	private DescriptionElementBase sourcedObj;
138

  
139
	@XmlElement(name = "nameUsedInSource")
140
	@XmlIDREF
141
	@XmlSchemaType(name = "IDREF")
142
	@ManyToOne(fetch = FetchType.LAZY)
143
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
144
	private TaxonNameBase<?,?> nameUsedInSource;
145

  
146
//*********************** CONSTRUCTOR ******************************/
147

  
148
	//for hibernate use only
149
	private DescriptionElementSource(){
150
		super();
151
	}
152

  
153
	private DescriptionElementSource(OriginalSourceType type){
154
		super(type);
155
	}
156

  
157

  
158
// **************************  GETTER / SETTER ***************************/
159

  
160

  
161
	@Override
162
    public DescriptionElementBase getSourcedObj() {
163
		return sourcedObj;
164
	}
165

  
166
	@Override
167
    public void setSourcedObj(DescriptionElementBase sourcedObj) {
168
		this.sourcedObj = sourcedObj;
169
	}
170

  
171

  
172
	/**
173
	 * @return the taxonNameUsedInSource
174
	 */
175
	public TaxonNameBase getNameUsedInSource() {
176
		return nameUsedInSource;
177
	}
178

  
179
	/**
180
	 * @param nameUsedInReference the nameUsedInReference to set
181
	 */
182
	public void setNameUsedInSource(TaxonNameBase nameUsedInSource) {
183
		this.nameUsedInSource = nameUsedInSource;
184
	}
185

  
186

  
187
//*********************************** CLONE *********************************************************/
188

  
189

  
190
	/**
191
	 * Clones this original source and sets the clones sourced object to 'sourceObj'
192
	 * @see java.lang.Object#clone()
193
	 */
194
	public DescriptionElementSource clone(DescriptionElementBase sourcedObj) throws CloneNotSupportedException{
195
		DescriptionElementSource result = (DescriptionElementSource)clone();
196
		result.setSourcedObj(sourcedObj);
197
		return result;
198
	}
199

  
200
	@Override
201
	public Object clone() throws CloneNotSupportedException{
202
		DescriptionElementSource result = (DescriptionElementSource)super.clone();
203

  
204
		//no changes to: sourcedObj
205
		return result;
206
	}
207

  
208

  
209

  
210
}

Also available in: Unified diff