Project

General

Profile

Download (4.06 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
package eu.etaxonomy.cdm.model.occurrence;
10

    
11
import javax.persistence.Entity;
12
import javax.persistence.FetchType;
13
import javax.persistence.ManyToOne;
14
import javax.xml.bind.annotation.XmlAccessType;
15
import javax.xml.bind.annotation.XmlAccessorType;
16
import javax.xml.bind.annotation.XmlElement;
17
import javax.xml.bind.annotation.XmlIDREF;
18
import javax.xml.bind.annotation.XmlSchemaType;
19
import javax.xml.bind.annotation.XmlType;
20

    
21
import org.apache.log4j.Logger;
22
import org.hibernate.envers.Audited;
23

    
24
import eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26
import eu.etaxonomy.cdm.model.term.DefinedTerm;
27

    
28
/**
29
 * The class representing the assignment of a occurrence status to a
30
 * {@link DerivedUnit derived unit}. This includes an {@link OccurrenceStatusType occurrence status type}
31
 * (for instance "destroyed", "lost" or "not seen by ...").
32
 *
33
 * @author m.doering
34
 * @since 08-Nov-2007 13:06:39
35
 */
36
@XmlAccessorType(XmlAccessType.FIELD)
37
@XmlType(name = "OccurrenceStatus", propOrder = {
38
    "unit",
39
    "type"
40
})
41
@Entity
42
@Audited
43
public class OccurrenceStatus
44
        extends SingleSourcedEntityBase {
45

    
46
    private static final long serialVersionUID = 623891726208046243L;
47
    private static Logger logger = Logger.getLogger(OccurrenceStatus.class);
48

    
49
	@XmlElement(name = "OccurrenceStatusType")
50
    @XmlIDREF
51
    @XmlSchemaType(name = "IDREF")
52
    @ManyToOne(fetch = FetchType.LAZY)
53
	private DefinedTerm type;
54

    
55
    @XmlElement(name = "Name")
56
    @XmlIDREF
57
    @XmlSchemaType(name = "IDREF")
58
    @ManyToOne(fetch = FetchType.LAZY)
59
    private DerivedUnit unit;
60

    
61
// ************************** FACTORY *********************************/
62

    
63
    /**
64
	 * Creates a new occurrence status instance with a given
65
	 * occurrence status type.
66
	 *
67
	 * @see #OccurrenceStatus()
68
	 */
69
	public static OccurrenceStatus NewInstance(DefinedTerm occurrenceStatusType){
70
		return NewInstance(occurrenceStatusType, null, null);
71
	}
72

    
73

    
74
	/**
75
	 * Creates a new occurrence status instance with a given
76
	 * occurrence status type.
77
	 *
78
	 * @see #OccurrenceStatus()
79
	 */
80
	public static OccurrenceStatus NewInstance(DefinedTerm occurrenceStatusType, Reference citation, String microCitation){
81
		OccurrenceStatus status = new OccurrenceStatus();
82
		status.setType(occurrenceStatusType);
83
		status.setCitation(citation);
84
		status.setCitationMicroReference(microCitation);
85
		return status;
86
	}
87

    
88
// ************************ CONSTRUCTOR *************************/
89

    
90
	protected OccurrenceStatus() {
91
        super();
92
    }
93

    
94
// ************************ GETTER / SETTER ************************/
95

    
96
    public DerivedUnit getUnit() {
97
        return unit;
98
    }
99
    protected void setUnit(DerivedUnit unit) {
100
        if (this.unit != null && !this.unit.equals(unit)){
101
            this.unit.removeStatus(this);
102
        }
103
        this.unit = unit;
104
        if (unit != null){
105
            unit.addStatus(this);
106
        }
107
    }
108

    
109
	/**
110
	 * Returns the occurrence status type of <i>this</i>
111
	 * occurrence status.
112
	 */
113
	public DefinedTerm getType(){
114
		return this.type;
115
	}
116
	/**
117
	 * @see  #getType()
118
	 */
119
	public void setType(DefinedTerm type){
120
		this.type = type;
121
	}
122

    
123
//*********************** CLONE ********************************************************/
124

    
125
	/**
126
	 * Clones <i>this</i> occurrence status. This is a shortcut that enables to create
127
	 * a new instance that differs only slightly from <i>this</i> occurrence status by
128
	 * modifying only some of the attributes.
129
	 *
130
	 * @see eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase#clone()
131
	 * @see java.lang.Object#clone()
132
	 */
133
	@Override
134
	public OccurrenceStatus clone() {
135
		try {
136
			OccurrenceStatus result = (OccurrenceStatus)super.clone();
137
	        //no changes to: type
138
			return result;
139
		} catch (CloneNotSupportedException e) {
140
			logger.warn("Object does not implement cloneable");
141
			e.printStackTrace();
142
			return null;
143
		}
144
	}
145
}
(10-10/15)