Project

General

Profile

Download (7.32 KB) Statistics
| Branch: | Tag: | Revision:
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.Entity;
14
import javax.persistence.FetchType;
15
import javax.persistence.ManyToOne;
16
import javax.xml.bind.annotation.XmlElement;
17
import javax.xml.bind.annotation.XmlIDREF;
18
import javax.xml.bind.annotation.XmlSchemaType;
19
import javax.xml.bind.annotation.XmlType;
20

    
21
import org.apache.log4j.Logger;
22
import org.hibernate.annotations.Cascade;
23
import org.hibernate.annotations.CascadeType;
24
import org.hibernate.envers.Audited;
25

    
26
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
27
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
28
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
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.TaxonNameBase 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.TaxonNameBase taxon name}.
43
 *
44
 * @author a.mueller
45
 * @created 18.09.2009
46
 */
47
@XmlType(name = "DescriptionElementSource", propOrder = {
48
	    "sourcedObj",
49
	    "nameUsedInSource"
50
	})
51
@Entity
52
@Audited
53
public class DescriptionElementSource extends OriginalSourceBase<DescriptionElementBase>{
54
	private static final long serialVersionUID = -8487673428764273806L;
55
	@SuppressWarnings("unused")
56
	private static final Logger logger = Logger.getLogger(DescriptionElementSource.class);
57

    
58
	/**
59
	 * Factory method
60
	 * @return
61
	 */
62
	public static DescriptionElementSource NewInstance(OriginalSourceType type){
63
		return new DescriptionElementSource(type);
64
	}
65

    
66
	public static DescriptionElementSource NewDataImportInstance(String id){
67
		DescriptionElementSource result = new DescriptionElementSource(OriginalSourceType.Import);
68
		result.setIdInSource(id);
69
		return result;
70
	}
71

    
72
	public static DescriptionElementSource NewDataImportInstance(String id, String idNamespace){
73
		DescriptionElementSource result = NewDataImportInstance(id);
74
		result.setIdNamespace(idNamespace);
75
		return result;
76
	}
77

    
78
	public static DescriptionElementSource NewDataImportInstance(String id, String idNamespace, Reference ref){
79
		DescriptionElementSource result = NewDataImportInstance(id, idNamespace);
80
		result.setCitation(ref);
81
		return result;
82
	}
83

    
84
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation){
85
		DescriptionElementSource result = NewInstance(type);
86
		result.setIdInSource(id);
87
		result.setIdNamespace(idNamespace);
88
		result.setCitation(citation);
89
		return result;
90
	}
91

    
92
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation){
93
		DescriptionElementSource result = NewInstance(type, id, idNamespace, citation);
94
		result.setCitationMicroReference(microCitation);
95
		return result;
96
	}
97

    
98
	public static DescriptionElementSource NewInstance(OriginalSourceType type, String id, String idNamespace, Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){
99
		DescriptionElementSource result = NewInstance(type, id, idNamespace, citation, microReference);
100
		result.setNameUsedInSource(nameUsedInSource);
101
		result.setOriginalNameString(originalNameString);
102
		return result;
103
	}
104

    
105
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microCitation){
106
		DescriptionElementSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
107
		result.setCitation(citation);
108
		result.setCitationMicroReference(microCitation);
109
		return result;
110
	}
111

    
112
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){
113
		DescriptionElementSource result = NewPrimarySourceInstance(citation, microReference);
114
		result.setNameUsedInSource(nameUsedInSource);
115
		result.setOriginalNameString(originalNameString);
116
		return result;
117
	}
118

    
119

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

    
122
//	@XmlElement(name = "SourcedObject")
123
//    @XmlIDREF
124
//    @XmlSchemaType(name = "IDREF")
125
//	@Any(metaDef = "CdmBase",
126
//	    	 metaColumn=@Column(name = "sourcedObj_type"),
127
//	    	 fetch = FetchType.LAZY,
128
//	    	 optional = false)
129
//	@JoinTable(
130
//	        name = "DescriptionElementBase_OriginalSourceBase",
131
//	        joinColumns = @JoinColumn( name = "DescriptionElementBase_id" ),
132
//	        inverseJoinColumns = @JoinColumn( name = "sources_id" ) )
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
}
(5-5/36)