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.Transient;
|
15
|
import javax.xml.bind.annotation.XmlAccessType;
|
16
|
import javax.xml.bind.annotation.XmlAccessorType;
|
17
|
import javax.xml.bind.annotation.XmlRootElement;
|
18
|
import javax.xml.bind.annotation.XmlType;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.hibernate.envers.Audited;
|
22
|
import org.hibernate.search.annotations.Indexed;
|
23
|
import org.springframework.beans.factory.annotation.Configurable;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
28
|
import eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy;
|
29
|
import eu.etaxonomy.cdm.strategy.cache.reference.INomenclaturalReferenceCacheStrategy;
|
30
|
|
31
|
/**
|
32
|
* This class represents isolated sections (parts or chapters) within a {@link Book book}.
|
33
|
* <P>
|
34
|
* This class corresponds, according to the TDWG ontology, to the publication type
|
35
|
* term (from PublicationTypeTerm): "BookSection".
|
36
|
*
|
37
|
* @author m.doering
|
38
|
* @version 1.0
|
39
|
* @created 08-Nov-2007 13:06:14
|
40
|
*/
|
41
|
@XmlAccessorType(XmlAccessType.FIELD)
|
42
|
@XmlType(name = "BookSection", propOrder = {
|
43
|
// "inBook"
|
44
|
})
|
45
|
@XmlRootElement(name = "BookSection")
|
46
|
@Entity
|
47
|
@Indexed(index = "eu.etaxonomy.cdm.model.reference.ReferenceBase")
|
48
|
@Audited
|
49
|
@Configurable
|
50
|
public class BookSection extends SectionBase<INomenclaturalReferenceCacheStrategy<BookSection>> implements INomenclaturalReference, Cloneable {
|
51
|
private static final long serialVersionUID = -1066199749700092670L;
|
52
|
private static final Logger logger = Logger.getLogger(BookSection.class);
|
53
|
|
54
|
// @XmlElement(name = "InBook")
|
55
|
// @XmlIDREF
|
56
|
// @XmlSchemaType(name = "IDREF")
|
57
|
// @ManyToOne(fetch = FetchType.LAZY)
|
58
|
// @IndexedEmbedded
|
59
|
// @Cascade(CascadeType.SAVE_UPDATE)
|
60
|
// private Book inBook;
|
61
|
|
62
|
// @XmlTransient
|
63
|
// @Transient
|
64
|
// private NomenclaturalReferenceHelper nomRefBase = NomenclaturalReferenceHelper.NewInstance(this);
|
65
|
|
66
|
|
67
|
/**
|
68
|
* Class constructor: creates a new empty book section instance only containing the
|
69
|
* {@link eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy default cache strategy}.
|
70
|
*
|
71
|
* @see eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy
|
72
|
*/
|
73
|
protected BookSection(){
|
74
|
super();
|
75
|
this.type = ReferenceType.BookSection;
|
76
|
this.cacheStrategy = BookSectionDefaultCacheStrategy.NewInstance();
|
77
|
}
|
78
|
|
79
|
|
80
|
/**
|
81
|
* Creates a new empty book section instance only containing the
|
82
|
* {@link eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy default cache strategy}.
|
83
|
*
|
84
|
* @see #NewInstance(Book, TeamOrPersonBase, String, String)
|
85
|
* @see eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy
|
86
|
*/
|
87
|
public static BookSection NewInstance(){
|
88
|
BookSection result = new BookSection();
|
89
|
return result;
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Creates a new book section instance with its given book, title, pages and
|
94
|
* author (team) and its {@link eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy default cache strategy}.
|
95
|
*
|
96
|
* @param inBook the book <i>this</i> book section belongs to
|
97
|
* @param author the team or person who wrote <i>this</i> book section
|
98
|
* @param sectionTitle the string representing the title of <i>this</i>
|
99
|
* book section
|
100
|
* @param pages the string representing the pages in the book
|
101
|
* where <i>this</i> book section can be found
|
102
|
* @see #NewInstance()
|
103
|
* @see eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy
|
104
|
*/
|
105
|
public static BookSection NewInstance(Book inBook, TeamOrPersonBase author, String sectionTitle, String pages ){
|
106
|
BookSection result = new BookSection();
|
107
|
result.setInBook(inBook);
|
108
|
result.setTitle(sectionTitle);
|
109
|
result.setPages(pages);
|
110
|
result.setAuthorTeam(author);
|
111
|
return result;
|
112
|
}
|
113
|
|
114
|
|
115
|
/**
|
116
|
* Returns the {@link Book book} <i>this</i> book section belongs to.
|
117
|
*
|
118
|
* @return the book containing <i>this</i> book section
|
119
|
* @see Book
|
120
|
*/
|
121
|
@Transient
|
122
|
public Book getInBook(){
|
123
|
if (inReference == null){
|
124
|
return null;
|
125
|
}
|
126
|
if (! this.inReference.isInstanceOf(Book.class)){
|
127
|
throw new IllegalStateException("The in-reference of a BookSection may only be of type Book");
|
128
|
}
|
129
|
return CdmBase.deproxy(this.inReference,Book.class);
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* @see #getInBook()
|
134
|
*/
|
135
|
public void setInBook(Book inBook){
|
136
|
this.inReference = inBook;
|
137
|
}
|
138
|
|
139
|
|
140
|
/**
|
141
|
* Returns a formatted string containing the entire reference citation,
|
142
|
* including authors, title, book authors, book title, pages, corresponding to <i>this</i>
|
143
|
* book section.<BR>
|
144
|
* This method overrides the generic and inherited getCitation method
|
145
|
* from {@link StrictReferenceBase StrictReferenceBase}.
|
146
|
*
|
147
|
* @see #getNomenclaturalCitation(String)
|
148
|
* @see StrictReferenceBase#getCitation()
|
149
|
*/
|
150
|
// @Transient
|
151
|
// @Override
|
152
|
// public String getCitation(){
|
153
|
// return nomRefBase.getCitation();
|
154
|
// }
|
155
|
|
156
|
/**
|
157
|
* Returns a formatted string containing the entire citation used for
|
158
|
* nomenclatural purposes based on <i>this</i> book section - including
|
159
|
* (abbreviated) book title, book authors, book section title but not its
|
160
|
* authors - and on the given details.
|
161
|
*
|
162
|
* @param microReference the string with the details (generally pages)
|
163
|
* within t<i>this</i> book section
|
164
|
* @return the formatted string representing the
|
165
|
* nomenclatural citation
|
166
|
* @see #getCitation()
|
167
|
*/
|
168
|
@Transient
|
169
|
public String getNomenclaturalCitation(String microReference) {
|
170
|
if (cacheStrategy == null){
|
171
|
logger.warn("No CacheStrategy defined for "+ this.getClass() + ": " + this.getUuid());
|
172
|
return null;
|
173
|
}else{
|
174
|
return cacheStrategy.getNomenclaturalCitation(this,microReference);
|
175
|
}
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* If the publication date of a book section and it's inBook do differ this is usually
|
180
|
* caused by the fact that a book has been published during a period, because originally
|
181
|
* it consisted of several parts that only later where put together to one book.
|
182
|
* If so, the book section's publication date may be a point in time (year or month of year)
|
183
|
* whereas the books publication date may be a period of several years.
|
184
|
* Therefore a valid nomenclatural reference string should use the book sections
|
185
|
* publication date rather then the book's publication date.
|
186
|
*
|
187
|
* @see StrictReferenceBase#getDatePublished()
|
188
|
**/
|
189
|
@Transient
|
190
|
@Override
|
191
|
// This method overrides StrictReferenceBase.getDatePublished() only to have
|
192
|
// a specific Javadoc for BookSection.getDatePublished().
|
193
|
public TimePeriod getDatePublished(){
|
194
|
return super.getDatePublished();
|
195
|
}
|
196
|
|
197
|
|
198
|
/**
|
199
|
* Generates, according to the {@link strategy.cache.reference.BookSectionDefaultCacheStrategy default cache strategy}
|
200
|
* assigned to <i>this</i> book section, a string that identifies <i>this</i>
|
201
|
* book section and returns it. This string may be stored in the inherited
|
202
|
* {@link common.IdentifiableEntity#getTitleCache() titleCache} attribute.<BR>
|
203
|
* This method overrides the generic and inherited generateTitle method
|
204
|
* from {@link ReferenceBase ReferenceBase}.
|
205
|
*
|
206
|
* @return the string identifying <i>this</i> book section
|
207
|
* @see #getCitation()
|
208
|
* @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
|
209
|
* @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
|
210
|
*/
|
211
|
// @Override
|
212
|
// public String generateTitle(){
|
213
|
// return nomRefBase.generateTitle();
|
214
|
// }
|
215
|
|
216
|
|
217
|
|
218
|
/**
|
219
|
* Clones <i>this</i> book section. This is a shortcut that enables to
|
220
|
* create a new instance that differs only slightly from <i>this</i> book
|
221
|
* section by modifying only some of the attributes.<BR>
|
222
|
* This method overrides the clone method from {@link StrictReferenceBase StrictReferenceBase}.
|
223
|
*
|
224
|
* @see StrictReferenceBase#clone()
|
225
|
* @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
|
226
|
* @see java.lang.Object#clone()
|
227
|
*/
|
228
|
@Override
|
229
|
public Object clone(){
|
230
|
BookSection result = (BookSection)super.clone();
|
231
|
result.cacheStrategy = BookSectionDefaultCacheStrategy.NewInstance();
|
232
|
//no changes to: inBook
|
233
|
return result;
|
234
|
}
|
235
|
}
|