bugfix for Coordinate Parser with whitespaces, Dateparsing, etc.
[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 javax.persistence.Column;
13 import javax.persistence.Entity;
14 import javax.persistence.FetchType;
15 import javax.persistence.JoinColumn;
16 import javax.persistence.ManyToOne;
17 import javax.persistence.Transient;
18 import javax.validation.constraints.NotNull;
19 import javax.xml.bind.annotation.XmlAccessType;
20 import javax.xml.bind.annotation.XmlAccessorType;
21 import javax.xml.bind.annotation.XmlElement;
22 import javax.xml.bind.annotation.XmlIDREF;
23 import javax.xml.bind.annotation.XmlSchemaType;
24 import javax.xml.bind.annotation.XmlType;
25
26 import org.apache.log4j.Logger;
27 import org.hibernate.annotations.Any;
28 import org.hibernate.envers.Audited;
29 import org.hibernate.envers.NotAudited;
30
31 /**
32 * This class aims to make available some "flags" for identifiable entities in a
33 * flexible way. Application developers (and even users) can define their own
34 * "flags" as a MarkerType.
35 * @author m.doering
36 * @version 1.0
37 * @created 08-Nov-2007 13:06:33
38 */
39
40 @XmlAccessorType(XmlAccessType.FIELD)
41 @XmlType(name = "Marker")
42 @Entity
43 @Audited
44 public class Marker extends VersionableEntity implements Cloneable{
45 private static final long serialVersionUID = -7474489691871404610L;
46 @SuppressWarnings("unused")
47 private static final Logger logger = Logger.getLogger(Marker.class);
48
49 @XmlElement(name = "Flag")
50 private boolean flag;
51
52 @XmlElement(name = "MarkerType")
53 @XmlIDREF
54 @XmlSchemaType(name = "IDREF")
55 @ManyToOne(fetch = FetchType.LAZY)
56 @NotNull
57 private MarkerType markerType;
58
59 @XmlElement(name = "MarkedObject")
60 @XmlIDREF
61 @XmlSchemaType(name = "IDREF")
62 @Any(metaDef = "CdmBase",
63 fetch=FetchType.LAZY,
64 metaColumn = @Column(name="markedObj_type"),
65 optional = false)
66 @JoinColumn(name = "markedObj_id")
67 @NotAudited
68 private AnnotatableEntity markedObj;
69
70 /**
71 * Factory method
72 * @return
73 */
74 public static Marker NewInstance(){
75 return new Marker();
76 }
77
78 /**
79 * Factory method
80 * @param markerType The type of the marker
81 * @param flag The value of the marker
82 * @return
83 */
84 public static Marker NewInstance(MarkerType markerType, boolean flag){
85 return new Marker(markerType, flag);
86 }
87
88 public static Marker NewInstance(AnnotatableEntity annotatedObject, boolean flag, MarkerType markerType){
89 Marker marker = new Marker();
90 marker.setFlag(flag);
91 marker.setMarkerType(markerType);
92 annotatedObject.addMarker(marker);
93 return marker;
94 }
95
96 /**
97 * Default Constructor
98 */
99 private Marker() {
100 }
101
102 /**
103 * Constructor
104 * @param flag
105 */
106 protected Marker(MarkerType markerType, boolean flag){
107 this.markerType = markerType;
108 this.flag = flag;
109 }
110
111 /**
112 * @return
113 */
114 public AnnotatableEntity getMarkedObj() {
115 return markedObj;
116 }
117 public void setMarkedObj(AnnotatableEntity newMarkedObject) {
118 this.markedObj = newMarkedObject;
119 }
120
121 /**
122 * @return
123 */
124 public MarkerType getMarkerType(){
125 return this.markerType;
126 }
127 public void setMarkerType(MarkerType type){
128 this.markerType = type;
129 }
130
131 /**
132 * The flag value.
133 * @return
134 */
135 public boolean getFlag(){
136 return this.flag;
137 }
138 public void setFlag(boolean flag){
139 this.flag = flag;
140 }
141
142 /**
143 * @see getFlag()
144 * @return
145 */
146 @Transient
147 public boolean getValue(){
148 return getFlag();
149 }
150
151
152 //****************** CLONE ************************************************/
153
154
155 /* (non-Javadoc)
156 * @see java.lang.Object#clone()
157 */
158 @Override
159 public Object clone() throws CloneNotSupportedException{
160 Marker result = (Marker)super.clone();
161 result.setFlag(this.flag);
162 result.setMarkerType(this.markerType);
163 return result;
164 }
165
166 /**
167 * Clones this marker and sets the clones marked object to 'markedObject'
168 * @see java.lang.Object#clone()
169 */
170 public Marker clone(AnnotatableEntity markedObject) throws CloneNotSupportedException{
171 Marker result = (Marker)clone();
172 result.setMarkedObj(markedObject);
173 return result;
174 }
175
176 }