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