reintegrate cdm-3.3 branch into trunk
[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 * @created 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 private OriginalSourceType type;
71
72 //The object's ID in the source, where the alternative string comes from
73 @XmlElement(name = "IdInSource")
74 private String idInSource;
75
76 @XmlElement(name = "IdNamespace")
77 private String idNamespace;
78
79 //***************** CONSTRUCTOR ***********************/
80
81 //for hibernate use only
82 protected OriginalSourceBase() {
83
84 }
85
86 /**
87 * Constructor
88 * @param type2
89 */
90 protected OriginalSourceBase(OriginalSourceType type){
91 if (type == null){
92 throw new IllegalArgumentException("OriginalSourceType must not be null");
93 }
94 this.type = type;
95 }
96
97 //**************** GETTER / SETTER *******************************/
98
99
100 /* (non-Javadoc)
101 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#getIdInSource()
102 */
103 public String getIdInSource(){
104 return this.idInSource;
105 }
106 /* (non-Javadoc)
107 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#setIdInSource(java.lang.String)
108 */
109 public void setIdInSource(String idInSource){
110 this.idInSource = idInSource;
111 }
112
113
114 /* (non-Javadoc)
115 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#getIdNamespace()
116 */
117 public String getIdNamespace() {
118 return idNamespace;
119 }
120
121 /* (non-Javadoc)
122 * @see eu.etaxonomy.cdm.model.common.IOriginalSource#setIdNamespace(java.lang.String)
123 */
124 public void setIdNamespace(String idNamespace) {
125 this.idNamespace = idNamespace;
126 }
127
128
129 public OriginalSourceType getType() {
130 return type;
131 }
132
133 public void setType(OriginalSourceType type) {
134 Assert.notNull(type, "OriginalSourceType must not be null");
135 this.type = type;
136 }
137
138
139 //********************** CLONE ************************************************/
140
141 /* (non-Javadoc)
142 * @see java.lang.Object#clone()
143 */
144 @Override
145 public Object clone() throws CloneNotSupportedException{
146 OriginalSourceBase<?> result = (OriginalSourceBase<?>)super.clone();
147
148 //no changes to: idInSource, sourcedObj
149 return result;
150 }
151
152
153 //************************ toString ***************************************/
154 @Override
155 public String toString(){
156 if (StringUtils.isNotBlank(idInSource) || StringUtils.isNotBlank(idNamespace) ){
157 return "OriginalSource:" + CdmUtils.concat(":", idNamespace, idInSource);
158 }else{
159 return super.toString();
160 }
161 }
162
163 }