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.common;
|
11
|
|
12
|
import javax.persistence.Entity;
|
13
|
import javax.persistence.FetchType;
|
14
|
import javax.persistence.ManyToOne;
|
15
|
import javax.persistence.Transient;
|
16
|
import javax.validation.constraints.NotNull;
|
17
|
import javax.xml.bind.annotation.XmlAccessType;
|
18
|
import javax.xml.bind.annotation.XmlAccessorType;
|
19
|
import javax.xml.bind.annotation.XmlElement;
|
20
|
import javax.xml.bind.annotation.XmlIDREF;
|
21
|
import javax.xml.bind.annotation.XmlSchemaType;
|
22
|
import javax.xml.bind.annotation.XmlType;
|
23
|
|
24
|
import org.apache.log4j.Logger;
|
25
|
import org.hibernate.envers.Audited;
|
26
|
|
27
|
import eu.etaxonomy.cdm.validation.Level2;
|
28
|
|
29
|
/**
|
30
|
* This class aims to make available some "flags" for identifiable entities in a
|
31
|
* flexible way. Application developers (and even users) can define their own
|
32
|
* "flags" as a MarkerType.
|
33
|
* @author m.doering
|
34
|
* @since 08-Nov-2007 13:06:33
|
35
|
*/
|
36
|
|
37
|
@XmlAccessorType(XmlAccessType.FIELD)
|
38
|
@XmlType(name = "Marker")
|
39
|
@Entity
|
40
|
@Audited
|
41
|
public class Marker extends VersionableEntity implements Cloneable{
|
42
|
private static final long serialVersionUID = -7474489691871404610L;
|
43
|
@SuppressWarnings("unused")
|
44
|
private static final Logger logger = Logger.getLogger(Marker.class);
|
45
|
|
46
|
@XmlElement(name = "Flag")
|
47
|
private boolean flag;
|
48
|
|
49
|
@XmlElement(name = "MarkerType")
|
50
|
@XmlIDREF
|
51
|
@XmlSchemaType(name = "IDREF")
|
52
|
@ManyToOne(fetch = FetchType.LAZY)
|
53
|
@NotNull(groups=Level2.class) //removed from Level1 for now, see #4588
|
54
|
private MarkerType markerType;
|
55
|
|
56
|
// *********************** FACTORY *****************************/
|
57
|
|
58
|
/**
|
59
|
* Factory method
|
60
|
* @return
|
61
|
*/
|
62
|
public static Marker NewInstance(){
|
63
|
return new Marker();
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Factory method
|
68
|
* @param markerType The type of the marker
|
69
|
* @param flag The value of the marker
|
70
|
* @return
|
71
|
*/
|
72
|
public static Marker NewInstance(MarkerType markerType, boolean flag){
|
73
|
return new Marker(markerType, flag);
|
74
|
}
|
75
|
|
76
|
public static Marker NewInstance(AnnotatableEntity markedObject, boolean flag, MarkerType markerType){
|
77
|
Marker marker = new Marker();
|
78
|
marker.setFlag(flag);
|
79
|
marker.setMarkerType(markerType);
|
80
|
markedObject.addMarker(marker);
|
81
|
return marker;
|
82
|
}
|
83
|
|
84
|
//************************** CONSTRUCTOR **********************************/
|
85
|
|
86
|
/**
|
87
|
* Default Constructor
|
88
|
*/
|
89
|
private Marker() {
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Constructor
|
94
|
* @param flag
|
95
|
*/
|
96
|
protected Marker(MarkerType markerType, boolean flag){
|
97
|
this.markerType = markerType;
|
98
|
this.flag = flag;
|
99
|
}
|
100
|
|
101
|
// ****************************** GETTER / SETTER ***************************/
|
102
|
|
103
|
/**
|
104
|
* @return
|
105
|
*/
|
106
|
public MarkerType getMarkerType(){
|
107
|
return this.markerType;
|
108
|
}
|
109
|
public void setMarkerType(MarkerType type){
|
110
|
this.markerType = type;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* The flag value.
|
115
|
* @return
|
116
|
*/
|
117
|
public boolean getFlag(){
|
118
|
return this.flag;
|
119
|
}
|
120
|
public void setFlag(boolean flag){
|
121
|
this.flag = flag;
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* @see getFlag()
|
126
|
* @return
|
127
|
*/
|
128
|
@Transient
|
129
|
public boolean getValue(){
|
130
|
return getFlag();
|
131
|
}
|
132
|
|
133
|
//****************** CLONE ************************************************/
|
134
|
|
135
|
@Override
|
136
|
public Marker clone() throws CloneNotSupportedException{
|
137
|
Marker result = (Marker)super.clone();
|
138
|
result.setFlag(this.flag);
|
139
|
result.setMarkerType(this.markerType);
|
140
|
return result;
|
141
|
}
|
142
|
}
|