Performed project cleanup.
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / Marker.java
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 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.XmlType;
21
22 /**
23 * This class aims to make available some "flags" for identifiable entities in a
24 * flexible way. Application developers (and even users) can define their own
25 * "flags" as a MarkerType.
26 * @author m.doering
27 * @version 1.0
28 * @created 08-Nov-2007 13:06:33
29 */
30 @XmlAccessorType(XmlAccessType.FIELD)
31 @XmlType(name = "Marker")
32 @Entity
33 public class Marker extends VersionableEntity implements Cloneable{
34 private static final Logger logger = Logger.getLogger(Marker.class);
35
36 @XmlElement(name = "Flag")
37 private boolean flag;
38
39 @XmlElement(name = "MarkerType")
40 private MarkerType markerType;
41
42 @XmlElement(name = "MarkedObject")
43 private AnnotatableEntity markedObj;
44
45 /**
46 * Factory method
47 * @return
48 */
49 public static Marker NewInstance(){
50 return new Marker();
51 }
52
53 /**
54 * Factory method
55 * @param markerType The type of the marker
56 * @param flag The value of the marker
57 * @return
58 */
59 public static Marker NewInstance(MarkerType markerType, boolean flag){
60 return new Marker(markerType, flag);
61 }
62
63 /**
64 * Default Constructor
65 */
66 private Marker() {
67 }
68
69 /**
70 * Constructor
71 * @param flag
72 */
73 protected Marker(MarkerType markerType, boolean flag){
74 this.markerType = markerType;
75 this.flag = flag;
76 }
77
78 /**
79 * @return
80 */
81 @Transient
82 public AnnotatableEntity getMarkedObj() {
83 return markedObj;
84 }
85 protected void setMarkedObj(AnnotatableEntity newMarkedObject) {
86 this.markedObj = newMarkedObject;
87 }
88
89 /**
90 * @return
91 */
92 @ManyToOne
93 @Cascade({CascadeType.SAVE_UPDATE})
94 public MarkerType getMarkerType(){
95 return this.markerType;
96 }
97 public void setMarkerType(MarkerType type){
98 this.markerType = type;
99 }
100
101 /**
102 * The flag value.
103 * @return
104 */
105 public boolean getFlag(){
106 return this.flag;
107 }
108 public void setFlag(boolean flag){
109 this.flag = flag;
110 }
111
112
113 //****************** CLONE ************************************************/
114
115 /* (non-Javadoc)
116 * @see java.lang.Object#clone()
117 */
118 @Override
119 public Object clone() throws CloneNotSupportedException{
120 Marker result = (Marker)super.clone();
121 //no changes to: type, flag
122 return result;
123 }
124
125 /**
126 * Clones this marker and sets the clones marked object to 'markedObject'
127 * @see java.lang.Object#clone()
128 */
129 public Marker clone(AnnotatableEntity markedObject) throws CloneNotSupportedException{
130 Marker result = (Marker)clone();
131 result.setMarkedObj(markedObject);
132 return result;
133 }
134
135 }