Project

General

Profile

Download (4.77 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.reference;
11

    
12
import javax.persistence.Column;
13
import javax.persistence.Embedded;
14
import javax.persistence.Entity;
15
import javax.persistence.Inheritance;
16
import javax.persistence.InheritanceType;
17
import javax.persistence.Lob;
18
import javax.persistence.Transient;
19
import javax.xml.bind.annotation.XmlAccessType;
20
import javax.xml.bind.annotation.XmlAccessorType;
21
import javax.xml.bind.annotation.XmlElement;
22
import javax.xml.bind.annotation.XmlRootElement;
23
import javax.xml.bind.annotation.XmlType;
24

    
25
import org.apache.log4j.Logger;
26
import org.hibernate.envers.Audited;
27

    
28
import eu.etaxonomy.cdm.model.common.TimePeriod;
29
import eu.etaxonomy.cdm.strategy.cache.reference.IReferenceBaseCacheStrategy;
30
import eu.etaxonomy.cdm.strategy.cache.reference.StrictReferenceBaseDefaultCacheStrategy;
31

    
32
/**
33
 * This (abstract) class represents all different kind of references regardless
34
 * of their peculiarities. In order to take in account their peculiar
35
 * relationships and their use for different purposes each kind of reference is
36
 * represented by a subclass and not by an attribute (the values of which would
37
 * have been defined terms of a particular vocabulary).
38
 * <P>
39
 * This class corresponds to: <ul>
40
 * <li> PublicationCitation according to the TDWG ontology
41
 * <li> Publication according to the TCS
42
 * <li> Reference according to the ABCD schema
43
 * </ul>
44
 * 
45
 * @author m.doering
46
 * @version 1.0
47
 * @created 08-Nov-2007 13:06:54
48
 */
49
@XmlAccessorType(XmlAccessType.FIELD)
50
@XmlType(name = "StrictReferenceBase", propOrder = {
51
	"title",
52
    "datePublished"
53
})
54
@XmlRootElement(name = "StrictReferenceBase")
55
@Entity
56
@Audited
57
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
58
public abstract class StrictReferenceBase<S extends IReferenceBaseCacheStrategy> extends ReferenceBase<S> {
59
	
60
	private static final Logger logger = Logger.getLogger(StrictReferenceBase.class);
61
	
62
	//Title of the reference
63
	@XmlElement(name ="Title" )
64
	@Column(length=4096, name="title")
65
	@Lob
66
	private String title;
67
	
68
	//The date range assigned to the reference. ISO Date range like. Flexible, year can be left out, etc
69
	@XmlElement(name ="DatePublished" )
70
	@Embedded
71
	private TimePeriod datePublished;
72
	
73
	protected StrictReferenceBase(){
74
		super();
75
	}
76
	
77
	
78
	/**
79
	 * Returns a string representing the title of <i>this</i> reference. If a
80
	 * reference has different titles (for instance abbreviated and not
81
	 * abbreviated) then for each title a new instance must be created.
82
	 * 
83
	 * @return  the title string of <i>this</i> reference
84
	 * @see 	#getCitation()
85
	 */
86
	public String getTitle(){
87
		return this.title;
88
	}
89
	/**
90
	 * @see 	#getTitle()
91
	 */
92
	public void setTitle(String title){
93
		this.title = title;
94
	}
95

    
96
	/**
97
	 * Returns the date (mostly only the year) of publication / creation of
98
	 * <i>this</i> reference.
99
	 */
100
	public TimePeriod getDatePublished(){
101
		return this.datePublished;
102
	}
103
	/**
104
	 * @see 	#getDatePublished()
105
	 */
106
	public void setDatePublished(TimePeriod datePublished){
107
		this.datePublished = datePublished;
108
	}
109

    
110
	/**
111
	 * Returns a formatted string containing the entire reference citation,
112
	 * including authors, corresponding to <i>this</i> reference.
113
	 * 
114
	 * @see  #getTitle()
115
	 */
116
	@Override
117
	@Transient
118
	// TODO implement 
119
	public String getCitation(){
120
		logger.warn("getCitation not yet implemented");
121
		return "";
122
	}
123

    
124
	/**
125
	 * Returns a string representation for the year of publication / creation
126
	 * of <i>this</i> reference. The string is obtained by transformation of
127
	 * the {@link #getDatePublished() datePublished} attribute.
128
	 */
129
	@Transient
130
	@Override
131
	public String getYear(){
132
		if (this.getDatePublished() == null){
133
			return null;
134
		}else{
135
			return getDatePublished().getYear();
136
		}
137
	}
138
	
139
//******************** CLONE *****************************************/
140
	
141
	/* (non-Javadoc)
142
	 * @see eu.etaxonomy.cdm.model.reference.ReferenceBase#clone()
143
	 */
144
	/** 
145
	 * Clones <i>this</i> reference. This is a shortcut that enables to create
146
	 * a new instance that differs only slightly from <i>this</i> reference by
147
	 * modifying only some of the attributes.
148
	 * 
149
	 * @see ReferenceBase#clone()
150
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
151
	 * @see java.lang.Object#clone()
152
	 */
153
	@Override
154
	public Object clone() {
155
		try {
156
			StrictReferenceBase result = (StrictReferenceBase)super.clone();
157
			result.setDatePublished(datePublished != null? (TimePeriod)datePublished.clone(): null);
158
			//no change to: title
159
			return result;
160
		} catch (CloneNotSupportedException e) {
161
			logger.warn("Object does not implement cloneable");
162
			e.printStackTrace();
163
			return null;
164
		}
165
	}
166
}
(24-24/28)