Project

General

Profile

Download (4.5 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
 * @since 08-Nov-2007 13:06:47
36
 */
37
@XmlAccessorType(XmlAccessType.FIELD)
38
@XmlType(name = "ReferencedEntityBase", propOrder = {
39
    "citationMicroReference",
40
    "originalNameString",
41
    "citation"
42
})
43
@XmlRootElement(name = "ReferencedEntityBase")
44
@MappedSuperclass
45
@Audited
46
public abstract class ReferencedEntityBase extends AnnotatableEntity implements IReferencedEntity {
47
	private static final long serialVersionUID = -5614669050360359126L;
48
	@SuppressWarnings("unused")
49
	private static final Logger logger = Logger.getLogger(ReferencedEntityBase.class);
50

    
51
	@XmlElement(name = "Citation")
52
    @XmlIDREF
53
    @XmlSchemaType(name = "IDREF")
54
    @ManyToOne(fetch = FetchType.LAZY)
55
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
56
	private Reference citation;
57

    
58
	//Details of the reference. These are mostly (implicitly) pages but can also be tables or any other element of a
59
    //publication. {if the citationMicroReference exists then there must be also a reference}
60
    @XmlElement(name = "CitationMicroReference")
61
	private String citationMicroReference;
62

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

    
66
// ************ CONSTRUCTOR ********************************************/
67

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

    
73

    
74

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

    
82
//********************* GETTER / SETTER *******************************/
83

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

    
91

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

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

    
107
//****************** CLONE ************************************************/
108

    
109
	@Override
110
	public Object clone() throws CloneNotSupportedException{
111
		ReferencedEntityBase result = (ReferencedEntityBase)super.clone();
112

    
113
		//no changes to: citation, citationMicroReference, originalNameString
114
		return result;
115
	}
116

    
117
//*********************************** EQUALS *********************************************************/
118

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

    
130
	    int thisCitationId = -1;
131
	    int otherCitationId = -1;
132
	    if(this.getCitation() != null) {
133
	        thisCitationId = this.getCitation().getId();
134
	    }
135
	    if(other.getCitation() != null) {
136
	        otherCitationId = other.getCitation().getId();
137
        }
138

    
139
        if(thisCitationId != otherCitationId
140
                || !StringUtils.equals(this.getCitationMicroReference(), other.getCitationMicroReference())
141
                || !StringUtils.equals(this.getOriginalNameString(), other.getOriginalNameString())
142
                        ){
143
            return false;
144
        }
145

    
146
        return true;
147
    }
148

    
149

    
150
}
(64-64/82)