final implementation of MaterialOrMethodEvent, Cloning, PreservationMethod, ... ...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / EventBase.java
1 /**
2 * Copyright (C) 2009 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.common;
11
12 import javax.persistence.FetchType;
13 import javax.persistence.ManyToOne;
14 import javax.persistence.MappedSuperclass;
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.annotations.Cascade;
25 import org.hibernate.annotations.CascadeType;
26 import org.hibernate.envers.Audited;
27 import org.hibernate.search.annotations.Field;
28 import org.hibernate.search.annotations.Index;
29 import org.hibernate.search.annotations.IndexedEmbedded;
30
31 import eu.etaxonomy.cdm.model.agent.AgentBase;
32
33 @XmlAccessorType(XmlAccessType.FIELD)
34 @XmlType(name = "EventBase", propOrder = {
35 "timeperiod",
36 "actor",
37 "description"
38 })
39 @XmlRootElement(name = "EventBase")
40 @MappedSuperclass
41 @Audited
42 public abstract class EventBase extends AnnotatableEntity implements IEvent {
43 private static final long serialVersionUID = -1859035632758446593L;
44 @SuppressWarnings("unused")
45 private static final Logger logger = Logger.getLogger(EventBase.class);
46
47 @XmlElement(name = "TimePeriod")
48 private TimePeriod timeperiod = TimePeriod.NewInstance();
49
50 @XmlElement(name = "Actor")
51 @XmlIDREF
52 @XmlSchemaType(name = "IDREF")
53 @ManyToOne(fetch = FetchType.LAZY)
54 @IndexedEmbedded
55 @Cascade(CascadeType.SAVE_UPDATE)
56 private AgentBase<?> actor;
57
58 @XmlElement(name = "Description")
59 @Field(index=Index.YES)
60 private String description;
61
62 //******************** GETTER / SETTER *******************/
63
64 @Override
65 public TimePeriod getTimeperiod() {
66 return timeperiod;
67 }
68 @Override
69 public void setTimeperiod(TimePeriod timeperiod) {
70 if (timeperiod == null){
71 timeperiod = TimePeriod.NewInstance();
72 }
73 this.timeperiod = timeperiod;
74 }
75
76 @Override
77 public AgentBase getActor() {
78 return actor;
79 }
80 @Override
81 public void setActor(AgentBase actor) {
82 this.actor = actor;
83 }
84
85 /**
86 * The description of this event. Implementing classes may use this field for different purposes.
87 * @return
88 */
89 public String getDescription() {
90 return description;
91 }
92
93 /**
94 * @see #getDescription()
95 * @param description
96 */
97 public void setDescription(String description) {
98 this.description = description;
99 }
100
101
102 //*********** CLONE **********************************/
103
104 /**
105 * Clones <i>this</i> event base. This is a shortcut that enables to
106 * create a new instance that differs only slightly from <i>this</i> event base
107 * by modifying only some of the attributes.<BR>
108 * This method overrides the clone method from {@link AnnotatableEntity AnnotatableEntity}.
109 *
110 * @see eu.etaxonomy.cdm.model.media.AnnotatableEntity#clone()
111 * @see java.lang.Object#clone()
112 */
113 @Override
114 public Object clone() throws CloneNotSupportedException{
115 EventBase result = (EventBase)super.clone();
116 //Actor //is this needed??
117 result.setActor(this.getActor());
118 //time period
119 result.setTimeperiod((TimePeriod)this.getTimeperiod().clone());
120 //no changes to: description
121 return result;
122 }
123
124
125
126 }