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
;
12 import java
.util
.HashSet
;
15 import javax
.persistence
.Entity
;
16 import javax
.persistence
.FetchType
;
17 import javax
.persistence
.ManyToMany
;
18 import javax
.persistence
.ManyToOne
;
19 import javax
.persistence
.OneToMany
;
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
.XmlElementWrapper
;
24 import javax
.xml
.bind
.annotation
.XmlIDREF
;
25 import javax
.xml
.bind
.annotation
.XmlRootElement
;
26 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
27 import javax
.xml
.bind
.annotation
.XmlType
;
29 import org
.apache
.log4j
.Logger
;
30 import org
.hibernate
.annotations
.Cascade
;
31 import org
.hibernate
.annotations
.CascadeType
;
32 import org
.hibernate
.envers
.Audited
;
33 import org
.hibernate
.search
.annotations
.Indexed
;
34 import org
.hibernate
.search
.annotations
.IndexedEmbedded
;
36 import eu
.etaxonomy
.cdm
.model
.common
.EventBase
;
43 @XmlAccessorType(XmlAccessType
.FIELD
)
44 @XmlType(name
= "DerivationEvent", propOrder
= {
49 @XmlRootElement(name
= "DerivationEvent")
53 public class DerivationEvent
extends EventBase
implements Cloneable
{
55 static Logger logger
= Logger
.getLogger(DerivationEvent
.class);
57 @XmlElementWrapper(name
= "Originals")
58 @XmlElement(name
= "Original")
60 @XmlSchemaType(name
= "IDREF")
61 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
})
62 @ManyToMany(fetch
= FetchType
.LAZY
,mappedBy
="derivationEvents")
63 @IndexedEmbedded(depth
= 3)
64 protected Set
<SpecimenOrObservationBase
> originals
= new HashSet
<SpecimenOrObservationBase
>();
66 @XmlElementWrapper(name
= "Derivatives")
67 @XmlElement(name
= "Derivative")
69 @XmlSchemaType(name
= "IDREF")
70 @OneToMany(fetch
=FetchType
.LAZY
, mappedBy
="derivationEvent")
71 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.MERGE
})
72 protected Set
<DerivedUnitBase
> derivatives
= new HashSet
<DerivedUnitBase
>();
74 @XmlElement(name
= "DerivationEventType")
76 @XmlSchemaType(name
= "IDREF")
77 @ManyToOne(fetch
= FetchType
.LAZY
)
78 private DerivationEventType type
;
84 public static DerivationEvent
NewInstance(){
85 return new DerivationEvent();
91 protected DerivationEvent() {
97 * The specimen or observations that are the input for this derviation event.
100 public Set
<SpecimenOrObservationBase
> getOriginals() {
106 * Adds a new input specimen or observation for this derviation event.
107 * @see #getOriginals()
110 public void addOriginal(SpecimenOrObservationBase original
) {
111 if (! this.originals
.contains(original
)){
112 this.originals
.add(original
);
113 original
.addDerivationEvent(this);
117 * Removes an input specimen or observation for this derviation event.
118 * @see #getOriginals()
121 public void removeOriginal(SpecimenOrObservationBase original
) {
122 this.originals
.remove(original
);
127 * The specimen or observations that are the output for this derviation event.
130 public Set
<DerivedUnitBase
> getDerivatives() {
136 * Adds a new output specimen or observation for this derviation event.
137 * @see #getDerivatives()
140 public void addDerivative(DerivedUnitBase derivative
) {
141 if (derivative
!= null){
142 boolean notExisting
= derivatives
.add(derivative
);
144 derivative
.setDerivedFrom(this);
149 * Removes an output specimen or observation for this derviation event.
150 * @see #getDerivatives()
153 public void removeDerivative(DerivedUnitBase derivative
) {
154 if (derivative
!= null){
155 derivative
.setDerivedFrom(null);
157 derivatives
.remove(derivative
);
161 * Returns the derivation event type
164 public DerivationEventType
getType() {
168 public void setType(DerivationEventType type
) {
172 //*********** CLONE **********************************/
175 * Clones <i>this</i> derivation event. This is a shortcut that enables to
176 * create a new instance that differs only slightly from <i>this</i> derivation event
177 * by modifying only some of the attributes.<BR>
178 * This method overrides the clone method from {@link EventBase EventBase}.
180 * @see EventBase#clone()
181 * @see java.lang.Object#clone()
184 public Object
clone() throws CloneNotSupportedException
{
186 DerivationEvent result
= (DerivationEvent
)super.clone();
188 result
.setType(this.getType());
190 result
.derivatives
= new HashSet
<DerivedUnitBase
>();
191 for(DerivedUnitBase derivative
: this.derivatives
) {
192 result
.addDerivative(derivative
);
195 result
.originals
= new HashSet
<SpecimenOrObservationBase
>();
196 for(SpecimenOrObservationBase original
: this.originals
) {
197 result
.addOriginal(original
);
201 } catch (CloneNotSupportedException e
) {
202 logger
.warn("Object does not implement cloneable");