ref #6241 replaced @created by @since in cdmlib
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / OriginalSourceBase.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
13 import javax.persistence.Column;
14 import javax.persistence.Entity;
15 import javax.persistence.Inheritance;
16 import javax.persistence.InheritanceType;
17 import javax.validation.constraints.NotNull;
18 import javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlAttribute;
21 import javax.xml.bind.annotation.XmlElement;
22 import javax.xml.bind.annotation.XmlRootElement;
23 import javax.xml.bind.annotation.XmlType;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.log4j.Logger;
27 import org.hibernate.annotations.Table;
28 import org.hibernate.annotations.Type;
29 import org.hibernate.envers.Audited;
30 import org.springframework.util.Assert;
31
32 import eu.etaxonomy.cdm.common.CdmUtils;
33
34 /**
35 * Abstract base class for classes implementing {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource}.
36 * @see eu.etaxonomy.cdm.model.common.IOriginalSource
37 *
38 * @author m.doering
39 * @version 1.0
40 * @since 08-Nov-2007 13:06:22
41 */
42
43 @XmlAccessorType(XmlAccessType.FIELD)
44 @XmlType(name = "OriginalSource", propOrder = {
45 "type",
46 "idInSource",
47 "idNamespace"
48 })
49 @XmlRootElement(name = "OriginalSource")
50 @Entity
51 @Audited
52 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
53 @Table(appliesTo="OriginalSourceBase")
54 public abstract class OriginalSourceBase<T extends ISourceable> extends ReferencedEntityBase implements IOriginalSource<T>, Cloneable {
55 private static final long serialVersionUID = -1972959999261181462L;
56 @SuppressWarnings("unused")
57 private static final Logger logger = Logger.getLogger(OriginalSourceBase.class);
58
59 /**
60 * The {@link OriginalSourceType type} of this source. According to PROV the type has to be thought as
61 * an activity that leads from the source entity to the current entity. It is not a property of the
62 * source itself.
63 */
64 @XmlAttribute(name ="type")
65 @Column(name="sourceType")
66 @NotNull
67 @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
68 parameters = {@org.hibernate.annotations.Parameter(name="enumClass", value="eu.etaxonomy.cdm.model.common.OriginalSourceType")}
69 )
70 @Audited
71 private OriginalSourceType type;
72
73 //The object's ID in the source, where the alternative string comes from
74 @XmlElement(name = "IdInSource")
75 private String idInSource;
76
77 @XmlElement(name = "IdNamespace")
78 private String idNamespace;
79
80 //***************** CONSTRUCTOR ***********************/
81
82 //for hibernate use only
83 protected OriginalSourceBase() {
84
85 }
86
87 /**
88 * Constructor
89 * @param type2
90 */
91 protected OriginalSourceBase(OriginalSourceType type){
92 if (type == null){
93 throw new IllegalArgumentException("OriginalSourceType must not be null");
94 }
95 this.type = type;
96 }
97
98 //**************** GETTER / SETTER *******************************/
99
100
101 @Override
102 public String getIdInSource(){
103 return this.idInSource;
104 }
105 @Override
106 public void setIdInSource(String idInSource){
107 this.idInSource = idInSource;
108 }
109
110
111 @Override
112 public String getIdNamespace() {
113 return idNamespace;
114 }
115 @Override
116 public void setIdNamespace(String idNamespace) {
117 this.idNamespace = idNamespace;
118 }
119
120
121 @Override
122 public OriginalSourceType getType() {
123 return type;
124 }
125 @Override
126 public void setType(OriginalSourceType type) {
127 Assert.notNull(type, "OriginalSourceType must not be null");
128 this.type = type;
129 }
130
131
132 //********************** CLONE ************************************************/
133
134 @Override
135 public Object clone() throws CloneNotSupportedException{
136 OriginalSourceBase<?> result = (OriginalSourceBase<?>)super.clone();
137
138 //no changes to: idInSource
139 return result;
140 }
141
142
143 //************************ toString ***************************************/
144 @Override
145 public String toString(){
146 if (StringUtils.isNotBlank(idInSource) || StringUtils.isNotBlank(idNamespace) ){
147 return "OriginalSource:" + CdmUtils.concat(":", idNamespace, idInSource);
148 }else{
149 return super.toString();
150 }
151 }
152
153 //*********************************** EQUALS *********************************************************/
154
155 /**
156 * {@inheritDoc}
157 */
158 @Override
159 public boolean equalsByShallowCompare(ReferencedEntityBase other) {
160
161 if(!super.equalsByShallowCompare(other)) {
162 return false;
163 }
164 OriginalSourceBase<T> theOther = (OriginalSourceBase<T>)other;
165 if(!StringUtils.equals(this.getIdInSource(), theOther.getIdInSource())
166 || !StringUtils.equals(this.getIdNamespace(), theOther.getIdNamespace())) {
167 return false;
168 }
169
170 return true;
171 }
172
173 }