| 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.common; |
|---|
| 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.description.DescriptionElementBase; |
|---|
| 31 | import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|---|
| 32 | import eu.etaxonomy.cdm.model.reference.Reference; |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 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. |
|---|
| 40 | * </BR> |
|---|
| 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}. |
|---|
| 46 | * |
|---|
| 47 | * @author a.mueller |
|---|
| 48 | * @created 18.09.2009 |
|---|
| 49 | * @version 1.0 |
|---|
| 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 | /** |
|---|
| 64 | * Factory method |
|---|
| 65 | * @return |
|---|
| 66 | */ |
|---|
| 67 | public static DescriptionElementSource NewInstance(){ |
|---|
| 68 | return new DescriptionElementSource(); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | public static DescriptionElementSource NewInstance(String id){ |
|---|
| 72 | DescriptionElementSource result = new DescriptionElementSource(); |
|---|
| 73 | result.setIdInSource(id); |
|---|
| 74 | return result; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | public static DescriptionElementSource NewInstance(String id, String idNamespace){ |
|---|
| 78 | DescriptionElementSource result = NewInstance(id); |
|---|
| 79 | result.setIdNamespace(idNamespace); |
|---|
| 80 | return result; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | public static DescriptionElementSource NewInstance(String id, String idNamespace, Reference citation){ |
|---|
| 84 | DescriptionElementSource result = NewInstance(id, idNamespace); |
|---|
| 85 | result.setCitation(citation); |
|---|
| 86 | return result; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | public static DescriptionElementSource NewInstance(String id, String idNamespace, Reference citation, String microCitation){ |
|---|
| 90 | DescriptionElementSource result = NewInstance(id, idNamespace); |
|---|
| 91 | result.setCitation(citation); |
|---|
| 92 | result.setCitationMicroReference(microCitation); |
|---|
| 93 | return result; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | public static DescriptionElementSource NewInstance(String id, String idNamespace, Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){ |
|---|
| 97 | DescriptionElementSource result = NewInstance(id, idNamespace, citation, microReference); |
|---|
| 98 | result.setNameUsedInSource(nameUsedInSource); |
|---|
| 99 | result.setOriginalNameString(originalNameString); |
|---|
| 100 | return result; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | public static DescriptionElementSource NewInstance(Reference citation, String microCitation){ |
|---|
| 104 | DescriptionElementSource result = NewInstance(); |
|---|
| 105 | result.setCitation(citation); |
|---|
| 106 | result.setCitationMicroReference(microCitation); |
|---|
| 107 | return result; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | public static DescriptionElementSource NewInstance(Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){ |
|---|
| 111 | DescriptionElementSource result = NewInstance(citation, microReference); |
|---|
| 112 | result.setNameUsedInSource(nameUsedInSource); |
|---|
| 113 | result.setOriginalNameString(originalNameString); |
|---|
| 114 | return result; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | @XmlElement(name = "SourcedObject") |
|---|
| 120 | @XmlIDREF |
|---|
| 121 | @XmlSchemaType(name = "IDREF") |
|---|
| 122 | @Any(metaDef = "CdmBase", |
|---|
| 123 | metaColumn=@Column(name = "sourcedObj_type"), |
|---|
| 124 | fetch = FetchType.LAZY, |
|---|
| 125 | optional = false) |
|---|
| 126 | @JoinColumn(name = "sourcedObj_id") |
|---|
| 127 | @NotAudited |
|---|
| 128 | private DescriptionElementBase sourcedObj; |
|---|
| 129 | |
|---|
| 130 | @XmlElement(name = "nameUsedInSource") |
|---|
| 131 | @XmlIDREF |
|---|
| 132 | @XmlSchemaType(name = "IDREF") |
|---|
| 133 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 134 | @Cascade({CascadeType.SAVE_UPDATE}) |
|---|
| 135 | private TaxonNameBase nameUsedInSource; |
|---|
| 136 | |
|---|
| 137 | private DescriptionElementSource(){ |
|---|
| 138 | |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | // ************************** GETTER / SETTER ****************************************************/ |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | /* (non-Javadoc) |
|---|
| 146 | * @see eu.etaxonomy.cdm.model.common.IOriginalSource#getSourcedObj() |
|---|
| 147 | */ |
|---|
| 148 | public DescriptionElementBase getSourcedObj() { |
|---|
| 149 | return sourcedObj; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | /* (non-Javadoc) |
|---|
| 153 | * @see eu.etaxonomy.cdm.model.common.IOriginalSource#setSourcedObj(eu.etaxonomy.cdm.model.common.ISourceable) |
|---|
| 154 | */ |
|---|
| 155 | public void setSourcedObj(DescriptionElementBase sourcedObj) { |
|---|
| 156 | this.sourcedObj = sourcedObj; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | /** |
|---|
| 161 | * @return the taxonNameUsedInSource |
|---|
| 162 | */ |
|---|
| 163 | public TaxonNameBase getNameUsedInSource() { |
|---|
| 164 | return nameUsedInSource; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | /** |
|---|
| 168 | * @param nameUsedInReference the nameUsedInReference to set |
|---|
| 169 | */ |
|---|
| 170 | public void setNameUsedInSource(TaxonNameBase nameUsedInSource) { |
|---|
| 171 | this.nameUsedInSource = nameUsedInSource; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | //*********************************** CLONE *********************************************************/ |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | /** |
|---|
| 179 | * Clones this original source and sets the clones sourced object to 'sourceObj' |
|---|
| 180 | * @see java.lang.Object#clone() |
|---|
| 181 | */ |
|---|
| 182 | public DescriptionElementSource clone(DescriptionElementBase sourcedObj) throws CloneNotSupportedException{ |
|---|
| 183 | DescriptionElementSource result = (DescriptionElementSource)clone(); |
|---|
| 184 | result.setSourcedObj(sourcedObj); |
|---|
| 185 | return result; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | /* (non-Javadoc) |
|---|
| 190 | * @see eu.etaxonomy.cdm.model.common.OriginalSourceBase#clone() |
|---|
| 191 | * @see java.lang.Object#clone() |
|---|
| 192 | */ |
|---|
| 193 | @Override |
|---|
| 194 | public Object clone() throws CloneNotSupportedException{ |
|---|
| 195 | DescriptionElementSource result = (DescriptionElementSource)super.clone(); |
|---|
| 196 | |
|---|
| 197 | //no changes to: sourcedObj |
|---|
| 198 | return result; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | } |
|---|