Project

General

Profile

Download (4.35 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.FetchType;
14
import javax.persistence.ManyToOne;
15
import javax.persistence.MappedSuperclass;
16
import javax.xml.bind.annotation.XmlAccessType;
17
import javax.xml.bind.annotation.XmlAccessorType;
18
import javax.xml.bind.annotation.XmlElement;
19
import javax.xml.bind.annotation.XmlIDREF;
20
import javax.xml.bind.annotation.XmlRootElement;
21
import javax.xml.bind.annotation.XmlSchemaType;
22
import javax.xml.bind.annotation.XmlType;
23

    
24
import org.apache.commons.lang.StringUtils;
25
import org.apache.log4j.Logger;
26
import org.hibernate.annotations.Cascade;
27
import org.hibernate.annotations.CascadeType;
28
import org.hibernate.envers.Audited;
29

    
30
import eu.etaxonomy.cdm.model.reference.Reference;
31

    
32
/**
33
 * abstract class for all objects that may have a reference
34
 * @author m.doering
35
 * @version 1.0
36
 * @created 08-Nov-2007 13:06:47
37
 */
38
@XmlAccessorType(XmlAccessType.FIELD)
39
@XmlType(name = "ReferencedEntityBase", propOrder = {
40
    "citationMicroReference",
41
    "originalNameString",
42
    "citation"
43
})
44
@XmlRootElement(name = "ReferencedEntityBase")
45
@MappedSuperclass
46
@Audited
47
public abstract class ReferencedEntityBase extends AnnotatableEntity implements IReferencedEntity {
48
	private static final long serialVersionUID = -5614669050360359126L;
49
	@SuppressWarnings("unused")
50
	private static final Logger logger = Logger.getLogger(ReferencedEntityBase.class);
51

    
52
	//Details of the reference. These are mostly (implicitly) pages but can also be tables or any other element of a
53
	//publication. {if the citationMicroReference exists then there must be also a reference}
54
    @XmlElement(name = "Citation")
55
    @XmlIDREF
56
    @XmlSchemaType(name = "IDREF")
57
    @ManyToOne(fetch = FetchType.LAZY)
58
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
59
	private Reference citation;
60

    
61
    @XmlElement(name = "CitationMicroReference")
62
	private String citationMicroReference;
63

    
64
    @XmlElement(name = "OriginalNameString")
65
	private String originalNameString;
66

    
67
// ************ CONSTRUCTOR ********************************************/
68

    
69
	//for hibernate use only
70
    protected ReferencedEntityBase() {
71
		super();
72
	}
73

    
74

    
75

    
76
	public ReferencedEntityBase(Reference citation, String citationMicroReference,
77
			String originalNameString) {
78
		super();
79
		this.citationMicroReference = citationMicroReference;
80
		this.originalNameString = originalNameString;
81
		this.citation = citation;
82
	}
83

    
84
//********************* GETTER / SETTER *******************************/
85

    
86
	public String getCitationMicroReference(){
87
		return this.citationMicroReference;
88
	}
89
	public void setCitationMicroReference(String citationMicroReference){
90
		this.citationMicroReference = citationMicroReference;
91
	}
92

    
93

    
94
	public String getOriginalNameString(){
95
		return this.originalNameString;
96
	}
97
	public void setOriginalNameString(String originalNameString){
98
		this.originalNameString = originalNameString;
99
	}
100

    
101
	@Override
102
    public Reference getCitation(){
103
		return this.citation;
104
	}
105
	public void setCitation(Reference citation) {
106
		this.citation = citation;
107
	}
108

    
109
//****************** CLONE ************************************************/
110

    
111
	/* (non-Javadoc)
112
	 * @see java.lang.Object#clone()
113
	 */
114
	@Override
115
	public Object clone() throws CloneNotSupportedException{
116
		ReferencedEntityBase result = (ReferencedEntityBase)super.clone();
117

    
118
		//no changes to: citation, citationMicroReference, originalNameString
119
		return result;
120
	}
121

    
122
//*********************************** EQUALS *********************************************************/
123

    
124
	/**
125
	 * Indicates whether some other object is "equal to" this one.
126
	 *
127
	 * Uses a content based compare strategy which avoids bean initialization. This is achieved by
128
	 * comparing the cdm entity ids.
129
	 *
130
	 * @param other
131
	 * @return
132
	 */
133
	public boolean equalsByShallowCompare(ReferencedEntityBase other) {
134

    
135
        if(this.getCitation().getId() != other.getCitation().getId()
136
                || !StringUtils.equals(this.getCitationMicroReference(), other.getCitationMicroReference())
137
                || !StringUtils.equals(this.getOriginalNameString(), other.getOriginalNameString())
138
                        ){
139
            return false;
140
        }
141

    
142
        return true;
143
    }
144

    
145

    
146
}
(58-58/73)