Project

General

Profile

Download (3.73 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
	//#9908
68
    @XmlElement(name = "TimePeriod", type= String.class)
69
    private TimePeriod timePeriod = TimePeriod.NewInstance();
70

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

    
74
// ********************** CONSTRUCTOR **********************************************/
75

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

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

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

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

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

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

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

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

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

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

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

    
122
// ************************ STRING ****************************/
123

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

    
135
}
(8-8/56)