Project

General

Profile

Download (2.29 KB) Statistics
| Branch: | Tag: | Revision:
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 java.util.HashSet;
13
import java.util.Set;
14

    
15
import javax.persistence.Entity;
16
import javax.persistence.ManyToMany;
17
import javax.persistence.ManyToOne;
18
import javax.persistence.OneToMany;
19

    
20
import org.apache.log4j.Logger;
21
import org.hibernate.annotations.Cascade;
22
import org.hibernate.annotations.CascadeType;
23

    
24
import eu.etaxonomy.cdm.model.common.EventBase;
25

    
26
@Entity
27
public class DerivationEvent extends EventBase{
28
	static Logger logger = Logger.getLogger(DerivationEvent.class);
29

    
30
	private Set<SpecimenOrObservationBase> originals = new HashSet<SpecimenOrObservationBase>();
31
	protected Set<DerivedUnitBase> derivatives = new HashSet<DerivedUnitBase>();
32
	private DerivationEventType type;
33
	
34
	/**
35
	 * Factory method
36
	 * @return
37
	 */
38
	public static DerivationEvent NewInstance(){
39
		return new DerivationEvent();
40
	}
41
	
42
	/**
43
	 * Constructor
44
	 */
45
	protected DerivationEvent() {
46
		super();
47
	}
48
	
49
	@ManyToMany(mappedBy="derivationEvents")
50
	@Cascade({CascadeType.SAVE_UPDATE})
51
	public Set<SpecimenOrObservationBase> getOriginals() {
52
		return originals;
53
	}
54
	protected void setOriginals(Set<SpecimenOrObservationBase> originals) {
55
		this.originals = originals;
56
	}
57
	public void addOriginal(SpecimenOrObservationBase original) {
58
		if (! this.originals.contains(original)){
59
			this.originals.add(original);
60
			original.addDerivationEvent(this);
61
		}
62
	}
63
	public void removeOriginal(SpecimenOrObservationBase original) {
64
		this.originals.remove(original);
65
	}
66
	
67
	
68
	@OneToMany(mappedBy="derivedFrom")
69
	@Cascade({CascadeType.SAVE_UPDATE})
70
	public Set<DerivedUnitBase> getDerivatives() {
71
		return derivatives;
72
	}
73
	protected void setDerivatives(Set<DerivedUnitBase> derivatives) {
74
		this.derivatives = derivatives;
75
	}
76
	public void addDerivative(DerivedUnitBase derivative) {
77
		derivative.setDerivedFrom(this);
78
	}
79
	public void removeDerivative(DerivedUnitBase derivative) {
80
		this.derivatives.remove(derivative);
81
	}
82

    
83
	
84
	@ManyToOne
85
	public DerivationEventType getType() {
86
		return type;
87
	}
88
	public void setType(DerivationEventType type) {
89
		this.type = type;
90
	}
91
}
(2-2/15)