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