Project

General

Profile

Download (6.91 KB) Statistics
| Branch: | Tag: | Revision:
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.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
21
import org.hibernate.envers.Audited;
22

    
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
25
import eu.etaxonomy.cdm.model.reference.NamedSourceBase;
26
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28

    
29
/**
30
 * This class represents an {@link eu.etaxonomy.cdm.model.reference.IOriginalSource IOriginalSource}
31
 * that can be used with {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase description elements}.
32
 * Additionally to the core functionally of IOriginalSource a {@link eu.etaxonomy.cdm.model.name.TaxonName taxon name}
33
 * can be stored that points to the name used in the source. This is needed because description always belong
34
 * to accepted taxa while the referenced citations may use synonym names.
35
 * </BR>
36
 * The use of "originalNameString" within a DescriptionElementSource has to be discussed.
37
 * In general this string is to be used for different representations of the sourced object. In this classes
38
 * context it could also stand for the string representation of the taxon name used in the source. This
39
 * may make sense if the taxon name is not available in the CDM and the user for some reason does not want
40
 * to create a new ful {@link eu.etaxonomy.cdm.model.name.TaxonName taxon name}.
41
 *
42
 * @author a.mueller
43
 * @since 18.09.2009
44
 */
45
@XmlType(name = "DescriptionElementSource", propOrder = {
46
	    "sourcedElement"
47
	})
48
@Entity
49
@Audited
50
public class DescriptionElementSource extends NamedSourceBase{
51

    
52
    private static final long serialVersionUID = -8487673428764273806L;
53
	@SuppressWarnings("unused")
54
	private static final Logger logger = LogManager.getLogger(DescriptionElementSource.class);
55

    
56
// ************************* FIELDS ********************************/
57

    
58
    @XmlElement(name = "sourcedElement")
59
    @XmlIDREF
60
    @XmlSchemaType(name = "IDREF")
61
    @ManyToOne(fetch = FetchType.LAZY)
62
    private DescriptionElementBase sourcedElement;
63

    
64
//************************* FACTORY ******************************/
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, TaxonName 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 NewInstance(OriginalSourceType type, String id, String idNamespace,
110
            Reference citation, String microReference, TaxonName nameUsedInSource, String originalNameString, ICdmTarget target){
111
        DescriptionElementSource result = NewInstance(type, id, idNamespace, citation, microReference, nameUsedInSource, originalNameString);
112
        result.setCdmSource(target);
113
        return result;
114
    }
115

    
116
    public static DescriptionElementSource NewAggregationInstance(ICdmTarget target){
117
        DescriptionElementSource result = NewInstance(OriginalSourceType.Aggregation);
118
        result.setCdmSource(target);
119
        return result;
120
    }
121

    
122
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microCitation){
123
		DescriptionElementSource result = NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
124
		result.setCitation(citation);
125
		result.setCitationMicroReference(microCitation);
126
		return result;
127
	}
128

    
129
	public static DescriptionElementSource NewPrimarySourceInstance(Reference citation, String microReference, TaxonName nameUsedInSource, String originalNameString){
130
		DescriptionElementSource result = NewPrimarySourceInstance(citation, microReference);
131
		result.setNameUsedInSource(nameUsedInSource);
132
		result.setOriginalNameString(originalNameString);
133
		return result;
134
	}
135

    
136
//*********************** CONSTRUCTOR ******************************/
137

    
138
	//for hibernate use only
139
	/**
140
	 * @deprecated for internal use only
141
	 */
142
	@Deprecated
143
	protected DescriptionElementSource(){
144
	}
145

    
146
	private DescriptionElementSource(OriginalSourceType type){
147
		super(type);
148
	}
149

    
150
//***************** GETTER / SETTER ****************************/
151

    
152
    public DescriptionElementBase getSourcedElement() {
153
        return sourcedElement;
154
    }
155

    
156
    public void setSourcedElement(DescriptionElementBase sourcedElement) {
157
        if (this.sourcedElement != sourcedElement){
158
            this.sourcedElement = sourcedElement;
159
            if (sourcedElement != null){
160
                sourcedElement.addSource(this);
161
            }
162
        }
163
    }
164

    
165
//*********************************** CLONE *********************************************************/
166

    
167
	@Override
168
	public DescriptionElementSource clone() throws CloneNotSupportedException{
169
		DescriptionElementSource result = (DescriptionElementSource)super.clone();
170
		//we don't expect the source to belong to the same description element
171
        result.sourcedElement = null;
172

    
173
		//no changes
174
		return result;
175
	}
176
}
(6-6/38)