Project

General

Profile

Download (2.17 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.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
	private static final Logger logger = Logger.getLogger(Marker.class);
29
	
30
	private boolean flag;
31
	private MarkerType markerType;
32
	private AnnotatableEntity markedObj;
33
	
34
	/**
35
	 * Factory method
36
	 * @param markerType The type of the marker
37
	 * @param flag The value of the marker
38
	 * @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
	@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
	/**
75
	 * @return
76
	 */
77
	@ManyToOne
78
	@Cascade({CascadeType.SAVE_UPDATE})
79
	public MarkerType getMarkerType(){
80
		return this.markerType;
81
	}
82
	public void setMarkerType(MarkerType type){
83
		this.markerType = type;
84
	}
85

    
86
	/**
87
	 * The flag value.
88
	 * @return
89
	 */
90
	public boolean getFlag(){
91
		return this.flag;
92
	}
93
	public void setFlag(boolean flag){
94
		this.flag = flag;
95
	}
96

    
97
}
(21-21/39)