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