1 |
9479da48
|
Andreas Müller
|
/**
|
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 org.apache.log4j.Logger;
|
13 |
|
|
import org.hibernate.annotations.Cascade;
|
14 |
|
|
import org.hibernate.annotations.CascadeType;
|
15 |
|
|
|
16 |
|
|
import javax.persistence.*;
|
17 |
|
|
|
18 |
|
|
/**
|
19 |
|
|
* This class aims to make available some "flags" for identifiable entities in a
|
20 |
|
|
* flexible way. Application developers (and even users) can define their own
|
21 |
|
|
* "flags" as a MarkerType.
|
22 |
|
|
* @author m.doering
|
23 |
|
|
* @version 1.0
|
24 |
|
|
* @created 08-Nov-2007 13:06:33
|
25 |
|
|
*/
|
26 |
|
|
@Entity
|
27 |
|
|
public class Marker extends VersionableEntity {
|
28 |
572ce758
|
Andreas Müller
|
private static final Logger logger = Logger.getLogger(Marker.class);
|
29 |
|
|
|
30 |
9479da48
|
Andreas Müller
|
private boolean flag;
|
31 |
572ce758
|
Andreas Müller
|
private MarkerType markerType;
|
32 |
9479da48
|
Andreas Müller
|
private AnnotatableEntity markedObj;
|
33 |
|
|
|
34 |
572ce758
|
Andreas Müller
|
/**
|
35 |
|
|
* Factory method
|
36 |
ab44ad21
|
Andreas Müller
|
* @param markerType The type of the marker
|
37 |
|
|
* @param flag The value of the marker
|
38 |
572ce758
|
Andreas Müller
|
* @return
|
39 |
|
|
*/
|
40 |
|
|
public static Marker NewInstance(MarkerType markerType, boolean flag){
|
41 |
|
|
return new Marker(markerType, flag);
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
/**
|
45 |
|
|
* Constructor
|
46 |
|
|
* @param flage
|
47 |
|
|
*/
|
48 |
|
|
protected Marker(MarkerType markerType, boolean flag){
|
49 |
|
|
this.markerType = markerType;
|
50 |
|
|
this.flag = flag;
|
51 |
|
|
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
/**
|
55 |
|
|
* @return
|
56 |
|
|
*/
|
57 |
9479da48
|
Andreas Müller
|
@Transient
|
58 |
|
|
public AnnotatableEntity getMarkedObj() {
|
59 |
|
|
return markedObj;
|
60 |
|
|
}
|
61 |
|
|
protected void setMarkedObj(AnnotatableEntity newMarkedObject) {
|
62 |
|
|
// Hibernate bidirectional cascade hack:
|
63 |
|
|
// http://opensource.atlassian.com/projects/hibernate/browse/HHH-1054
|
64 |
|
|
if(this.markedObj == newMarkedObject) return;
|
65 |
|
|
if (markedObj != null) {
|
66 |
|
|
markedObj.markers.remove(this);
|
67 |
|
|
}
|
68 |
|
|
if (newMarkedObject!= null) {
|
69 |
|
|
newMarkedObject.markers.add(this);
|
70 |
|
|
}
|
71 |
|
|
this.markedObj = newMarkedObject;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
572ce758
|
Andreas Müller
|
/**
|
75 |
|
|
* @return
|
76 |
|
|
*/
|
77 |
9479da48
|
Andreas Müller
|
@ManyToOne
|
78 |
|
|
@Cascade({CascadeType.SAVE_UPDATE})
|
79 |
572ce758
|
Andreas Müller
|
public MarkerType getMarkerType(){
|
80 |
|
|
return this.markerType;
|
81 |
9479da48
|
Andreas Müller
|
}
|
82 |
572ce758
|
Andreas Müller
|
public void setMarkerType(MarkerType type){
|
83 |
|
|
this.markerType = type;
|
84 |
9479da48
|
Andreas Müller
|
}
|
85 |
|
|
|
86 |
572ce758
|
Andreas Müller
|
/**
|
87 |
|
|
* The flag value.
|
88 |
|
|
* @return
|
89 |
|
|
*/
|
90 |
9479da48
|
Andreas Müller
|
public boolean getFlag(){
|
91 |
|
|
return this.flag;
|
92 |
|
|
}
|
93 |
|
|
public void setFlag(boolean flag){
|
94 |
|
|
this.flag = flag;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
}
|