3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.model
.common
;
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
;
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
;
30 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
31 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
35 * This class represents an {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource}
36 * that can be used with {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase description elements}.
37 * Additionally to the core functionally of IOriginalSource a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}
38 * can be stored that points to the name used in the source. This is needed because description always belong
39 * to accepted taxa while the referenced citations may use synonym names.
41 * The use of "originalNameString" within a DescriptionElementSource has to be discussed.
42 * In general this string is to be used for different representations of the sourced object. In this classes
43 * context it could also stand for the string representation of the taxon name used in the source. This
44 * may make sense if the taxon name is not available in the CDM and the user for some reason does not want
45 * to create a new ful {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name}.
51 @XmlType(name
= "DescriptionElementSource", propOrder
= {
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);
66 public static DescriptionElementSource
NewInstance(OriginalSourceType type
){
67 return new DescriptionElementSource(type
);
70 public static DescriptionElementSource
NewDataImportInstance(String id
){
71 DescriptionElementSource result
= new DescriptionElementSource(OriginalSourceType
.Import
);
72 result
.setIdInSource(id
);
76 public static DescriptionElementSource
NewDataImportInstance(String id
, String idNamespace
){
77 DescriptionElementSource result
= NewDataImportInstance(id
);
78 result
.setIdNamespace(idNamespace
);
82 public static DescriptionElementSource
NewDataImportInstance(String id
, String idNamespace
, Reference ref
){
83 DescriptionElementSource result
= NewDataImportInstance(id
, idNamespace
);
84 result
.setCitation(ref
);
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
);
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
);
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
);
109 public static DescriptionElementSource
NewPrimarySourceInstance(Reference citation
, String microCitation
){
110 DescriptionElementSource result
= NewInstance(OriginalSourceType
.PrimaryTaxonomicSource
);
111 result
.setCitation(citation
);
112 result
.setCitationMicroReference(microCitation
);
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
);
125 @XmlElement(name
= "SourcedObject")
127 @XmlSchemaType(name
= "IDREF")
128 @Any(metaDef
= "CdmBase",
129 metaColumn
=@Column(name
= "sourcedObj_type"),
130 fetch
= FetchType
.LAZY
,
132 @JoinColumn(name
= "sourcedObj_id")
134 private DescriptionElementBase sourcedObj
;
136 @XmlElement(name
= "nameUsedInSource")
138 @XmlSchemaType(name
= "IDREF")
139 @ManyToOne(fetch
= FetchType
.LAZY
)
140 @Cascade({CascadeType
.SAVE_UPDATE
})
141 private TaxonNameBase
<?
,?
> nameUsedInSource
;
143 private DescriptionElementSource(OriginalSourceType type
){
148 // ************************** GETTER / SETTER ****************************************************/
152 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#getSourcedObj()
154 public DescriptionElementBase
getSourcedObj() {
159 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#setSourcedObj(eu.etaxonomy.cdm.model.common.ISourceable)
161 public void setSourcedObj(DescriptionElementBase sourcedObj
) {
162 this.sourcedObj
= sourcedObj
;
167 * @return the taxonNameUsedInSource
169 public TaxonNameBase
getNameUsedInSource() {
170 return nameUsedInSource
;
174 * @param nameUsedInReference the nameUsedInReference to set
176 public void setNameUsedInSource(TaxonNameBase nameUsedInSource
) {
177 this.nameUsedInSource
= nameUsedInSource
;
181 //*********************************** CLONE *********************************************************/
185 * Clones this original source and sets the clones sourced object to 'sourceObj'
186 * @see java.lang.Object#clone()
188 public DescriptionElementSource
clone(DescriptionElementBase sourcedObj
) throws CloneNotSupportedException
{
189 DescriptionElementSource result
= (DescriptionElementSource
)clone();
190 result
.setSourcedObj(sourcedObj
);
196 * @see eu.etaxonomy.cdm.model.common.OriginalSourceBase#clone()
197 * @see java.lang.Object#clone()
200 public Object
clone() throws CloneNotSupportedException
{
201 DescriptionElementSource result
= (DescriptionElementSource
)super.clone();
203 //no changes to: sourcedObj