Project

General

Profile

Download (4.75 KB) Statistics
| Branch: | Tag: | Revision:
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
 * @since 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>
54
        extends ReferencedEntityBase
55
        implements IOriginalSource<T>, IIntextReferenceTarget,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
	@Override
103
	public String getIdInSource(){
104
		return this.idInSource;
105
	}
106
	@Override
107
	public void setIdInSource(String idInSource){
108
		this.idInSource = idInSource;
109
	}
110

    
111

    
112
	@Override
113
	public String getIdNamespace() {
114
		return idNamespace;
115
	}
116
	@Override
117
	public void setIdNamespace(String idNamespace) {
118
		this.idNamespace = idNamespace;
119
	}
120

    
121

    
122
	@Override
123
	public OriginalSourceType getType() {
124
		return type;
125
	}
126
	@Override
127
	public void setType(OriginalSourceType type) {
128
		Assert.notNull(type, "OriginalSourceType must not be null");
129
		this.type = type;
130
	}
131

    
132

    
133
//********************** CLONE ************************************************/
134

    
135
	@Override
136
	public Object clone() throws CloneNotSupportedException{
137
		OriginalSourceBase<?> result = (OriginalSourceBase<?>)super.clone();
138

    
139
		//no changes to: idInSource
140
		return result;
141
	}
142

    
143

    
144
//************************ toString ***************************************/
145
	@Override
146
	public String toString(){
147
		if (StringUtils.isNotBlank(idInSource) || StringUtils.isNotBlank(idNamespace) ){
148
			return "OriginalSource:" + CdmUtils.concat(":", idNamespace, idInSource);
149
		}else{
150
			return super.toString();
151
		}
152
	}
153

    
154
//*********************************** EQUALS *********************************************************/
155

    
156
	/**
157
     * {@inheritDoc}
158
     */
159
    @Override
160
    public boolean equalsByShallowCompare(ReferencedEntityBase other) {
161

    
162
        if(!super.equalsByShallowCompare(other)) {
163
            return false;
164
        }
165
        OriginalSourceBase<T> theOther = (OriginalSourceBase<T>)other;
166
        if(!StringUtils.equals(this.getIdInSource(), theOther.getIdInSource())
167
                || !StringUtils.equals(this.getIdNamespace(), theOther.getIdNamespace())) {
168
            return false;
169
        }
170

    
171
        return true;
172
    }
173

    
174
}
(58-58/79)