Project

General

Profile

Download (4.15 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

    
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
	@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, sourcedObj
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
}
(54-54/72)