Project

General

Profile

Download (8.16 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

    
13
import javax.persistence.Entity;
14
import javax.persistence.FetchType;
15
import javax.persistence.ManyToOne;
16
import javax.persistence.Transient;
17
import javax.xml.bind.annotation.XmlAccessType;
18
import javax.xml.bind.annotation.XmlAccessorType;
19
import javax.xml.bind.annotation.XmlElement;
20
import javax.xml.bind.annotation.XmlIDREF;
21
import javax.xml.bind.annotation.XmlRootElement;
22
import javax.xml.bind.annotation.XmlSchemaType;
23
import javax.xml.bind.annotation.XmlTransient;
24
import javax.xml.bind.annotation.XmlType;
25

    
26
import org.apache.log4j.Logger;
27
import org.hibernate.annotations.Cascade;
28
import org.hibernate.annotations.CascadeType;
29
import org.hibernate.envers.Audited;
30
import org.springframework.beans.factory.annotation.Configurable;
31

    
32
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
33
import eu.etaxonomy.cdm.model.common.TimePeriod;
34
import eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy;
35
import eu.etaxonomy.cdm.strategy.cache.reference.INomenclaturalReferenceCacheStrategy;
36

    
37
/**
38
 * This class represents isolated sections (parts or chapters) within a {@link Book book}.
39
 * <P>
40
 * This class corresponds, according to the TDWG ontology, to the publication type
41
 * term (from PublicationTypeTerm): "BookSection".
42
 *   
43
 * @author m.doering
44
 * @version 1.0
45
 * @created 08-Nov-2007 13:06:14
46
 */
47
@XmlAccessorType(XmlAccessType.FIELD)
48
@XmlType(name = "BookSection", propOrder = {
49
    "inBook"
50
})
51
@XmlRootElement(name = "BookSection")
52
@Entity
53
@Audited
54
@Configurable
55
public class BookSection extends SectionBase<INomenclaturalReferenceCacheStrategy<BookSection>> implements INomenclaturalReference, Cloneable {
56
	
57
	/**
58
	 * 
59
	 */
60
	private static final long serialVersionUID = -1066199749700092670L;
61

    
62
	private static final Logger logger = Logger.getLogger(BookSection.class);
63
	
64
    @XmlElement(name = "InBook")
65
    @XmlIDREF
66
    @XmlSchemaType(name = "IDREF")
67
    @ManyToOne(fetch = FetchType.LAZY)
68
    @Cascade(CascadeType.SAVE_UPDATE)
69
	private Book inBook;
70
	
71
//    @XmlTransient
72
//    @Transient
73
//	private NomenclaturalReferenceHelper nomRefBase = NomenclaturalReferenceHelper.NewInstance(this);
74

    
75
	
76
	/** 
77
	 * Class constructor: creates a new empty book section instance only containing the
78
	 * {@link eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy default cache strategy}.
79
	 * 
80
	 * @see eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy
81
	 */
82
	protected BookSection(){
83
		super();
84
		this.cacheStrategy = BookSectionDefaultCacheStrategy.NewInstance();
85
	}
86
	
87

    
88
	/** 
89
	 * Creates a new empty book section instance only containing the
90
	 * {@link eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy default cache strategy}.
91
	 * 
92
	 * @see #NewInstance(Book, TeamOrPersonBase, String, String)
93
	 * @see eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy
94
	 */
95
	public static BookSection NewInstance(){
96
		BookSection result = new BookSection();
97
		return result;
98
	}
99
	
100
	/** 
101
	 * Creates a new book section instance with its given book, title, pages and
102
	 * author (team) and its {@link eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy default cache strategy}.
103
	 * 
104
	 * @param	inBook			the book <i>this</i> book section belongs to
105
	 * @param	author			the team or person who wrote <i>this</i> book section
106
	 * @param	sectionTitle	the string representing the title of <i>this</i>
107
	 * 							book section
108
	 * @param	pages			the string representing the pages in the book
109
	 * 							where <i>this</i> book section can be found  
110
	 * @see 					#NewInstance()
111
	 * @see 					eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy
112
	 */
113
	public static BookSection NewInstance(Book inBook, TeamOrPersonBase author, String sectionTitle, String pages ){
114
		BookSection result = new BookSection();
115
		result.setInBook(inBook);
116
		result.setTitle(sectionTitle);
117
		result.setPages(pages);
118
		result.setAuthorTeam(author);
119
		return result;
120
	}
121
	
122
	
123
	/**
124
	 * Returns the {@link Book book} <i>this</i> book section belongs to.
125
	 * 
126
	 * @return  the book containing <i>this</i> book section
127
	 * @see 	Book
128
	 */
129
	public Book getInBook(){
130
		return this.inBook;
131
	}
132

    
133
	/**
134
	 * @see #getInBook()
135
	 */
136
	public void setInBook(Book inBook){
137
		this.inBook = inBook;
138
	}
139

    
140

    
141
	/**
142
	 * Returns a formatted string containing the entire reference citation,
143
	 * including authors, title, book authors, book title, pages, corresponding to <i>this</i>
144
	 * book section.<BR>
145
	 * This method overrides the generic and inherited getCitation method
146
	 * from {@link StrictReferenceBase StrictReferenceBase}.
147
	 * 
148
	 * @see  #getNomenclaturalCitation(String)
149
	 * @see  StrictReferenceBase#getCitation()
150
	 */
151
//	@Transient
152
//	@Override
153
//	public String getCitation(){
154
//		return nomRefBase.getCitation();
155
//	}
156

    
157
	/**
158
	 * Returns a formatted string containing the entire citation used for
159
	 * nomenclatural purposes based on <i>this</i> book section - including
160
	 * (abbreviated) book title, book authors, book section title but not its
161
	 * authors - and on the given details.
162
	 * 
163
	 * @param  microReference	the string with the details (generally pages)
164
	 * 							within t<i>this</i> book section
165
	 * @return					the formatted string representing the
166
	 * 							nomenclatural citation
167
	 * @see  					#getCitation()
168
	 */
169
	@Transient
170
	public String getNomenclaturalCitation(String microReference) {
171
		if (cacheStrategy == null){
172
			logger.warn("No CacheStrategy defined for "+ this.getClass() + ": " + this.getUuid());
173
			return null;
174
		}else{
175
			return cacheStrategy.getNomenclaturalCitation(this,microReference);
176
		}
177
	}
178
	
179
	 /** 
180
	  * If the publication date of a book section and it's inBook do differ this is usually 
181
	 * caused by the fact that a book has been published during a period, because originally 
182
	 * it consisted of several parts that only later where put together to one book.
183
	 * If so, the book section's publication date may be a point in time (year or month of year)
184
	 * whereas the books publication date may be a period of several years.
185
	 * Therefore a valid nomenclatural reference string should use the book sections 
186
	 * publication date rather then the book's publication date.
187
	 * 
188
	 * @see 	StrictReferenceBase#getDatePublished()
189
	 **/
190
	 @Transient
191
	 @Override
192
	 // This method overrides StrictReferenceBase.getDatePublished() only to have 
193
	 // a specific Javadoc for BookSection.getDatePublished().
194
	public TimePeriod getDatePublished(){
195
		return super.getDatePublished();
196
	}
197

    
198

    
199
	/**
200
	 * Generates, according to the {@link strategy.cache.reference.BookSectionDefaultCacheStrategy default cache strategy}
201
	 * assigned to <i>this</i> book section, a string that identifies <i>this</i>
202
	 * book section and returns it. This string may be stored in the inherited
203
	 * {@link common.IdentifiableEntity#getTitleCache() titleCache} attribute.<BR>
204
	 * This method overrides the generic and inherited generateTitle method
205
	 * from {@link ReferenceBase ReferenceBase}.
206
	 *
207
	 * @return  the string identifying <i>this</i> book section
208
	 * @see  	#getCitation()
209
	 * @see  	eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
210
	 * @see  	eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
211
	 */
212
//	@Override
213
//	public String generateTitle(){
214
//		return nomRefBase.generateTitle();
215
//	}
216
	
217
//*********** CLONE **********************************/	
218

    
219
	/** 
220
	 * Clones <i>this</i> book section. This is a shortcut that enables to
221
	 * create a new instance that differs only slightly from <i>this</i> book
222
	 * section by modifying only some of the attributes.<BR>
223
	 * This method overrides the clone method from {@link StrictReferenceBase StrictReferenceBase}.
224
	 * 
225
	 * @see StrictReferenceBase#clone()
226
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
227
	 * @see java.lang.Object#clone()
228
	 */
229
	@Override
230
	public Object clone(){
231
		BookSection result = (BookSection)super.clone();
232
		result.cacheStrategy = BookSectionDefaultCacheStrategy.NewInstance();
233
		//no changes to: inBook
234
		return result;
235
	}
236
}
(5-5/28)