4bbba68bf5d52daafc9ab8686ff355dfd2b2a3ac
[cdmlib.git] / 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.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 "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, TaxonNameBase 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, TaxonNameBase 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 TaxonNameBase<?,?> 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 TaxonNameBase getNameUsedInSource() {
145 return nameUsedInSource;
146 }
147
148 /**
149 * @param nameUsedInReference the nameUsedInReference to set
150 */
151 public void setNameUsedInSource(TaxonNameBase 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
167
168 }