Project

General

Profile

Download (4.46 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 eu.etaxonomy.cdm.model.common.TimePeriod;
13
import eu.etaxonomy.cdm.strategy.cache.reference.StrictReferenceBaseDefaultCacheStrategy;
14

    
15
import org.apache.log4j.Logger;
16
import org.hibernate.envers.Audited;
17

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

    
88
	/**
89
	 * Returns the date (mostly only the year) of publication / creation of
90
	 * <i>this</i> reference.
91
	 */
92
	public TimePeriod getDatePublished(){
93
		return this.datePublished;
94
	}
95
	/**
96
	 * @see 	#getDatePublished()
97
	 */
98
	public void setDatePublished(TimePeriod datePublished){
99
		this.datePublished = datePublished;
100
	}
101

    
102
	/**
103
	 * Returns a formatted string containing the entire reference citation,
104
	 * including authors, corresponding to <i>this</i> reference.
105
	 * 
106
	 * @see  #getTitle()
107
	 */
108
	@Override
109
	// TODO implement 
110
	public String getCitation(){
111
		logger.warn("getCitation not yet implemented");
112
		return "";
113
	}
114

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