| 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.occurrence; |
|---|
| 11 | |
|---|
| 12 | import javax.persistence.Entity; |
|---|
| 13 | import javax.persistence.FetchType; |
|---|
| 14 | import javax.persistence.ManyToOne; |
|---|
| 15 | import javax.validation.constraints.Size; |
|---|
| 16 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 17 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 18 | import javax.xml.bind.annotation.XmlElement; |
|---|
| 19 | import javax.xml.bind.annotation.XmlIDREF; |
|---|
| 20 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 21 | import javax.xml.bind.annotation.XmlSchemaType; |
|---|
| 22 | import javax.xml.bind.annotation.XmlType; |
|---|
| 23 | |
|---|
| 24 | import org.apache.log4j.Logger; |
|---|
| 25 | import org.hibernate.envers.Audited; |
|---|
| 26 | import org.hibernate.search.annotations.Field; |
|---|
| 27 | import org.hibernate.search.annotations.Index; |
|---|
| 28 | import org.hibernate.search.annotations.Indexed; |
|---|
| 29 | import org.springframework.beans.factory.annotation.Configurable; |
|---|
| 30 | |
|---|
| 31 | import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
|---|
| 32 | import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy; |
|---|
| 33 | import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty; |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * A specimen is regarded as derived from an field observation, |
|---|
| 37 | * so locality and gathering related information is captured as a separate FieldObservation object |
|---|
| 38 | * related to a specimen via a derivation event |
|---|
| 39 | * @author m.doering |
|---|
| 40 | * @version 1.0 |
|---|
| 41 | * @created 08-Nov-2007 13:06:52 |
|---|
| 42 | */ |
|---|
| 43 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 44 | @XmlType(name = "Specimen", propOrder = { |
|---|
| 45 | "preservation", |
|---|
| 46 | "exsiccatum" |
|---|
| 47 | }) |
|---|
| 48 | @XmlRootElement(name = "Specimen") |
|---|
| 49 | @Entity |
|---|
| 50 | @Indexed(index = "eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase") |
|---|
| 51 | @Audited |
|---|
| 52 | @Configurable |
|---|
| 53 | public class Specimen extends DerivedUnitBase<IIdentifiableEntityCacheStrategy<Specimen>> implements Cloneable { |
|---|
| 54 | private static final long serialVersionUID = -504050482700773061L; |
|---|
| 55 | private static final Logger logger = Logger.getLogger(Specimen.class); |
|---|
| 56 | |
|---|
| 57 | @XmlElement(name = "Preservation") |
|---|
| 58 | @XmlIDREF |
|---|
| 59 | @XmlSchemaType(name = "IDREF") |
|---|
| 60 | @ManyToOne(fetch = FetchType.LAZY) |
|---|
| 61 | private PreservationMethod preservation; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | @XmlElement(name = "Exsiccatum") |
|---|
| 65 | @NullOrNotEmpty |
|---|
| 66 | @Field(index=Index.TOKENIZED) |
|---|
| 67 | @Size(max = 255) |
|---|
| 68 | private String exsiccatum; |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | /** |
|---|
| 72 | * Factory method |
|---|
| 73 | * @return |
|---|
| 74 | */ |
|---|
| 75 | public static Specimen NewInstance(){ |
|---|
| 76 | return new Specimen(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * Constructor |
|---|
| 81 | */ |
|---|
| 82 | protected Specimen() { |
|---|
| 83 | super(); |
|---|
| 84 | this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<Specimen>(); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | //***************************** GETTER / SETTER ************************************** |
|---|
| 88 | |
|---|
| 89 | public PreservationMethod getPreservation(){ |
|---|
| 90 | return this.preservation; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | public void setPreservation(PreservationMethod preservation){ |
|---|
| 94 | this.preservation = preservation; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | public void setExsiccatum(String exsiccatum) { |
|---|
| 99 | this.exsiccatum = exsiccatum; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | public String getExsiccatum() { |
|---|
| 103 | return exsiccatum; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | //*********** CLONE **********************************/ |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * Clones <i>this</i> specimen. This is a shortcut that enables to |
|---|
| 111 | * create a new instance that differs only slightly from <i>this</i> specimen |
|---|
| 112 | * by modifying only some of the attributes.<BR> |
|---|
| 113 | * This method overrides the clone method from {@link DerivedUnitBase DerivedUnitBase}. |
|---|
| 114 | * |
|---|
| 115 | * @see DerivedUnitBase#clone() |
|---|
| 116 | * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone() |
|---|
| 117 | * @see java.lang.Object#clone() |
|---|
| 118 | */ |
|---|
| 119 | @Override |
|---|
| 120 | public Object clone(){ |
|---|
| 121 | try{ |
|---|
| 122 | Specimen result = (Specimen)super.clone(); |
|---|
| 123 | result.setPreservation(this.preservation); |
|---|
| 124 | //no changes to: - |
|---|
| 125 | return result; |
|---|
| 126 | } catch (CloneNotSupportedException e) { |
|---|
| 127 | logger.warn("Object does not implement cloneable"); |
|---|
| 128 | e.printStackTrace(); |
|---|
| 129 | return null; |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | } |
|---|