2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.occurrence
;
13 import java
.beans
.PropertyChangeEvent
;
14 import java
.beans
.PropertyChangeListener
;
16 import javax
.persistence
.Entity
;
17 import javax
.persistence
.FetchType
;
18 import javax
.persistence
.ManyToOne
;
19 import javax
.validation
.Valid
;
20 import javax
.xml
.bind
.annotation
.XmlAccessType
;
21 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
22 import javax
.xml
.bind
.annotation
.XmlElement
;
23 import javax
.xml
.bind
.annotation
.XmlIDREF
;
24 import javax
.xml
.bind
.annotation
.XmlRootElement
;
25 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
26 import javax
.xml
.bind
.annotation
.XmlType
;
28 import org
.apache
.log4j
.Logger
;
29 import org
.hibernate
.annotations
.Cascade
;
30 import org
.hibernate
.annotations
.CascadeType
;
31 import org
.hibernate
.envers
.Audited
;
32 import org
.hibernate
.search
.annotations
.Field
;
33 import org
.hibernate
.search
.annotations
.Index
;
34 import org
.hibernate
.search
.annotations
.Indexed
;
35 import org
.hibernate
.search
.annotations
.IndexedEmbedded
;
36 import org
.hibernate
.validator
.constraints
.Length
;
37 import org
.springframework
.beans
.factory
.annotation
.Configurable
;
39 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
40 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IdentifiableEntityDefaultCacheStrategy
;
41 import eu
.etaxonomy
.cdm
.validation
.annotation
.NullOrNotEmpty
;
44 * In situ observation of a taxon in the field. If a specimen exists,
45 * in most cases a parallel field observation object should be instantiated and the specimen then is "derived" from the field unit
48 * @created 08-Nov-2007 13:06:40
50 @XmlAccessorType(XmlAccessType
.FIELD
)
51 @XmlType(name
= "FieldObservation", propOrder
= {
56 @XmlRootElement(name
= "FieldObservation")
58 @Indexed(index
= "eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase")
61 public class FieldObservation
extends SpecimenOrObservationBase
<IIdentifiableEntityCacheStrategy
<FieldObservation
>> implements Cloneable
{
62 private static final Logger logger
= Logger
.getLogger(FieldObservation
.class);
64 @XmlElement(name
= "FieldNumber")
65 @Field(index
=Index
.TOKENIZED
)
68 private String fieldNumber
;
70 @XmlElement(name
= "FieldNotes")
71 @Field(index
=Index
.TOKENIZED
)
74 private String fieldNotes
;
76 @XmlElement(name
= "GatheringEvent")
78 @XmlSchemaType(name
= "IDREF")
79 @ManyToOne(fetch
= FetchType
.LAZY
)
80 @Cascade( { CascadeType
.SAVE_UPDATE
})
81 @IndexedEmbedded(depth
= 2)
83 private GatheringEvent gatheringEvent
;
89 public static FieldObservation
NewInstance(){
90 return new FieldObservation();
96 protected FieldObservation(){
98 this.cacheStrategy
= new IdentifiableEntityDefaultCacheStrategy
<FieldObservation
>();
101 public GatheringEvent
getGatheringEvent() {
102 return gatheringEvent
;
105 public void setGatheringEvent(GatheringEvent gatheringEvent
) {
106 this.gatheringEvent
= gatheringEvent
;
107 addGatheringEventPropertyChangeListener();
111 private void addGatheringEventPropertyChangeListener() {
112 if (gatheringEvent
!= null){
113 gatheringEvent
.addPropertyChangeListener(getNewGatheringEventPropChangeListener());
117 public String
getFieldNumber() {
121 public void setFieldNumber(String fieldNumber
) {
122 this.fieldNumber
= fieldNumber
;
125 public String
getFieldNotes() {
129 public void setFieldNotes(String fieldNotes
) {
130 this.fieldNotes
= fieldNotes
;
133 // *********** Listener *****************************/
135 private PropertyChangeListener
getNewGatheringEventPropChangeListener() {
136 PropertyChangeListener listener
= new PropertyChangeListener(){
138 public void propertyChange(PropertyChangeEvent event
) {
139 firePropertyChange(event
);
146 //*********** CLONE **********************************/
149 * Clones <i>this</i> field observation. This is a shortcut that enables to
150 * create a new instance that differs only slightly from <i>this</i> field observation
151 * by modifying only some of the attributes.<BR>
152 * This method overrides the clone method from {@link SpecimenOrObservationBase SpecimenOrObservationBase}.
154 * @see SpecimenOrObservationBase#clone()
155 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
156 * @see java.lang.Object#clone()
159 public FieldObservation
clone(){
161 FieldObservation result
= (FieldObservation
)super.clone();
162 //no changes to: fieldNotes, fieldNumber
164 } catch (CloneNotSupportedException e
) {
165 logger
.warn("Object does not implement cloneable");