Project

General

Profile

Download (3.72 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
package eu.etaxonomy.cdm.model.common;
10

    
11
import javax.persistence.Entity;
12
import javax.persistence.FetchType;
13
import javax.persistence.ManyToOne;
14
import javax.xml.bind.annotation.XmlAccessType;
15
import javax.xml.bind.annotation.XmlAccessorType;
16
import javax.xml.bind.annotation.XmlElement;
17
import javax.xml.bind.annotation.XmlIDREF;
18
import javax.xml.bind.annotation.XmlSchemaType;
19
import javax.xml.bind.annotation.XmlType;
20

    
21
import org.apache.logging.log4j.LogManager;
22
import org.apache.logging.log4j.Logger;
23
import org.hibernate.annotations.Cascade;
24
import org.hibernate.annotations.CascadeType;
25
import org.hibernate.envers.Audited;
26

    
27
import eu.etaxonomy.cdm.model.agent.AgentBase;
28

    
29
/**
30
 * @author a.mueller
31
 * @since 23.03.2009
32
 */
33
@XmlAccessorType(XmlAccessType.FIELD)
34
@XmlType(name = "Credit")
35
@Entity
36
@Audited
37
public class Credit extends LanguageStringBase {
38

    
39
	private static final long serialVersionUID = 5763391127298427701L;
40
	@SuppressWarnings("unused")
41
	private static final Logger logger = LogManager.getLogger(Credit.class);
42

    
43
// ********************** FACTORY **********************************************/
44

    
45
    public static Credit NewInstance(AgentBase agent, TimePeriod timePeriod, String text){
46
        return NewInstance(agent, timePeriod, text, null, Language.DEFAULT());
47
    }
48

    
49
    public static Credit NewInstance(AgentBase agent, TimePeriod timePeriod, String text, String abbreviatedText, Language language){
50
        Credit result = new Credit(text, language);
51
        result.setAgent(agent);
52
        result.setAbbreviatedText(abbreviatedText);
53
        result.setTimePeriod(timePeriod);
54
        return result;
55
    }
56

    
57
// ********************** FACTORY **********************************************/
58

    
59
	// owner etc as defined by the rightstype
60
	@XmlElement(name = "Agent")
61
	@XmlIDREF
62
	@XmlSchemaType(name = "IDREF")
63
	@ManyToOne(fetch = FetchType.LAZY)
64
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
65
	private AgentBase<?> agent;
66

    
67
    @XmlElement(name = "TimePeriod", type= String.class)
68
    private TimePeriod timePeriod = TimePeriod.NewInstance();
69

    
70
	@XmlElement(name = "AbbreviatedText")
71
	private String abbreviatedText;
72

    
73
// ********************** CONSTRUCTOR **********************************************/
74

    
75
	protected Credit(){
76
		super();
77
	}
78

    
79
	protected Credit(String text, Language language){
80
		super(text, language);
81
	}
82

    
83
//*********************** GETTER /SETTER *****************************/
84

    
85
	public AgentBase getAgent() {
86
		return agent;
87
	}
88
	public void setAgent(AgentBase agent) {
89
		this.agent = agent;
90
	}
91

    
92
    public TimePeriod getTimePeriod() {
93
        return timePeriod;
94
    }
95
    public void setTimePeriod(TimePeriod timePeriod) {
96
        this.timePeriod = timePeriod;
97
    }
98

    
99
    public String getAbbreviatedText() {
100
		return abbreviatedText;
101
	}
102
	public void setAbbreviatedText(String abbreviatedText) {
103
		this.abbreviatedText = abbreviatedText;
104
	}
105

    
106
//************************* CLONE **************************/
107

    
108
	@Override
109
	public Credit clone() throws CloneNotSupportedException{
110

    
111
	    Credit result = (Credit)super.clone();
112

    
113
	    if (this.timePeriod != null) {
114
	        result.timePeriod = this.timePeriod.clone();
115
	    }
116

    
117
		//no changes to: agent
118
		return result;
119
	}
120

    
121
// ************************ STRING ****************************/
122

    
123
    @Override
124
    public String toString() {
125
        if (isNotBlank(this.abbreviatedText)){
126
            return this.abbreviatedText;
127
        }else if (isNotBlank(this.text)){
128
            return this.text;
129
        }else{
130
            return super.toString();
131
        }
132
    }
133

    
134
}
(8-8/56)