Project

General

Profile

Download (3.25 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.agent;
10

    
11
import javax.persistence.Entity;
12
import javax.persistence.Transient;
13
import javax.xml.bind.annotation.XmlAccessType;
14
import javax.xml.bind.annotation.XmlAccessorType;
15
import javax.xml.bind.annotation.XmlElement;
16
import javax.xml.bind.annotation.XmlTransient;
17
import javax.xml.bind.annotation.XmlType;
18

    
19
import org.apache.log4j.Logger;
20
import org.hibernate.envers.Audited;
21
import org.hibernate.search.annotations.Field;
22
import org.hibernate.search.annotations.Index;
23
import org.hibernate.search.annotations.Indexed;
24

    
25
import eu.etaxonomy.cdm.common.CdmUtils;
26
import eu.etaxonomy.cdm.strategy.cache.agent.INomenclaturalAuthorCacheStrategy;
27
import eu.etaxonomy.cdm.strategy.match.IMatchable;
28

    
29

    
30
/**
31
 * The abstract class for such {@link AgentBase agents} ({@link Person persons} or {@link Team teams}) who might also be used
32
 * for authorship of {@link eu.etaxonomy.cdm.model.reference.ReferenceBase references} or of {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon names}.
33
 * 
34
 * @author a.mueller
35
 * @version 1.0
36
 * @created 17-APR-2008
37
 */
38
@XmlAccessorType(XmlAccessType.FIELD)
39
@XmlType(name = "TeamOrPersonBase", propOrder = {
40
	"nomenclaturalTitle"
41
})
42
@Entity
43
@Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase")
44
@Audited
45
public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<?>> extends AgentBase<INomenclaturalAuthorCacheStrategy<T>> implements INomenclaturalAuthor {
46
	private static final long serialVersionUID = 5216821307314001961L;
47
	public static final Logger logger = Logger.getLogger(TeamOrPersonBase.class);
48

    
49
	@XmlElement(name="NomenclaturalTitle")
50
	@Field(index=Index.TOKENIZED)
51
	protected String nomenclaturalTitle;
52

    
53
	@Transient
54
	@XmlTransient
55
	protected boolean isGeneratingTitleCache = false;
56
	
57
	/**
58
	 * Returns the identification string (nomenclatural abbreviation) used in
59
	 * nomenclature for this {@link Person person} or this {@link Team team}.
60
	 * 
61
	 * @see  INomenclaturalAuthor#getNomenclaturalTitle()
62
	 */
63
	public String getNomenclaturalTitle() {
64
		String result = nomenclaturalTitle;
65
		if (CdmUtils.isEmpty(nomenclaturalTitle) && (isGeneratingTitleCache == false)){
66
			result = getTitleCache();
67
		}
68
		return result;
69
	}
70

    
71
	/** 
72
	 * @see     #getNomenclaturalTitle()
73
	 */
74
	public void setNomenclaturalTitle(String nomenclaturalTitle) {
75
		this.nomenclaturalTitle = nomenclaturalTitle;
76
	}
77

    
78
	/* (non-Javadoc)
79
	 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
80
	 */
81
	@Override
82
	public String getTitleCache() {
83
		isGeneratingTitleCache = true;
84
		String result = super.getTitleCache();
85
		result = replaceEmptyTitleByNomTitle(result);
86
		isGeneratingTitleCache = false;
87
		return result;
88
	}
89

    
90
	/**
91
	 * @param result
92
	 * @return
93
	 */
94
	protected String replaceEmptyTitleByNomTitle(String result) {
95
		if (CdmUtils.isEmpty(result)){
96
			result = nomenclaturalTitle;
97
		}
98
		if (CdmUtils.isEmpty(result)){
99
			result = super.getTitleCache();
100
		}
101
		return result;
102
	}
103
	
104
	
105
}
(10-10/12)