Project

General

Profile

Download (6.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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 org.apache.log4j.Logger;
13

    
14
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
15
import eu.etaxonomy.cdm.model.common.TimePeriod;
16

    
17
public class ReferenceFactory {
18
	private static final Logger logger = Logger.getLogger(ReferenceFactory.class);
19

    
20
	public static Reference newArticle(){
21
		Reference article = new Reference(ReferenceType.Article);
22
		article.setCacheStrategy(ReferenceType.Article.getCacheStrategy());
23
		return article;
24
	}
25

    
26
	public static Reference newJournal(){
27
		Reference journal = new Reference(ReferenceType.Journal);
28
		journal.setCacheStrategy(ReferenceType.Journal.getCacheStrategy());
29
		return journal;
30
	}
31

    
32
	public static Reference newBook(){
33
		Reference book = new Reference(ReferenceType.Book);
34
		book.setCacheStrategy(ReferenceType.Book.getCacheStrategy());
35
		return book;
36
	}
37

    
38
	public static Reference newThesis(){
39
		Reference thesis = new Reference(ReferenceType.Thesis);
40
		thesis.setCacheStrategy(ReferenceType.Thesis.getCacheStrategy());
41
		return thesis;
42
	}
43

    
44
	public static Reference newInProceedings(){
45
		Reference inProceedings = new Reference(ReferenceType.InProceedings);
46
		inProceedings.setCacheStrategy(ReferenceType.InProceedings.getCacheStrategy());
47
		return inProceedings;
48
	}
49

    
50
	public static Reference newProceedings(){
51
		Reference proceedings = new Reference(ReferenceType.Proceedings);
52
		proceedings.setCacheStrategy(ReferenceType.Proceedings.getCacheStrategy());
53
		return proceedings;
54
	}
55

    
56
	public static Reference newBookSection(){
57
		Reference bookSection = new Reference(ReferenceType.BookSection);
58
		bookSection.setCacheStrategy(ReferenceType.BookSection.getCacheStrategy());
59
		return bookSection;
60
	}
61

    
62

    
63
	public static Reference newSection(){
64
		Reference section = new Reference(ReferenceType.Section);
65
		section.setCacheStrategy(ReferenceType.Section.getCacheStrategy());
66
		return section;
67
	}
68

    
69
	public static Reference newCdDvd(){
70
		Reference cdDvd= new Reference(ReferenceType.CdDvd);
71
		cdDvd.setCacheStrategy(ReferenceType.CdDvd.getCacheStrategy());
72
		return cdDvd;
73
	}
74

    
75
	public static Reference newGeneric(){
76
		Reference generic = new Reference(ReferenceType.Generic);
77
		generic.setCacheStrategy(ReferenceType.Generic.getCacheStrategy());
78
		return generic;
79
	}
80

    
81
	public static Reference newMap(){
82
		Reference map = new Reference(ReferenceType.Map);
83
		map.setCacheStrategy(ReferenceType.Map.getCacheStrategy());
84
		return map;
85

    
86
	}
87

    
88
	public static Reference newReport(){
89
		Reference report = new Reference(ReferenceType.Report);
90
		report.setCacheStrategy(ReferenceType.Report.getCacheStrategy());
91
		return report;
92

    
93
	}
94

    
95
	public static Reference newWebPage(){
96
		Reference webPage = new Reference(ReferenceType.WebPage);
97
		webPage.setCacheStrategy(ReferenceType.WebPage.getCacheStrategy());
98
		return webPage;
99
	}
100

    
101
	public static Reference newDatabase(){
102
		Reference db = new Reference(ReferenceType.Database);
103
		db.setCacheStrategy(ReferenceType.Database.getCacheStrategy());
104
		return db;
105
	}
106

    
107

    
108
	/**
109
	 * Creates a new empty print series instance.
110
	 */
111
	public static Reference newPrintSeries() {
112
		Reference refBase = new Reference(ReferenceType.PrintSeries);
113
		refBase.setCacheStrategy(ReferenceType.PrintSeries.getCacheStrategy());
114
		return refBase;
115
	}
116

    
117

    
118
    public static Reference newPersonalCommunication() {
119
        Reference personalCommunication = new Reference(ReferenceType.PersonalCommunication);
120
        personalCommunication.setCacheStrategy(ReferenceType.PersonalCommunication.getCacheStrategy());
121
        return personalCommunication;
122
    }
123

    
124
    public static Reference newPatent() {
125
        Reference patent = new Reference(ReferenceType.Patent);
126
        patent.setCacheStrategy(ReferenceType.Patent.getCacheStrategy());
127
        return patent;
128
    }
129

    
130
// ******************** Short cuts **********************************************/
131

    
132
	/**
133
	 * Creates a new print series instance with a given title string.
134
	 */
135
	public static Reference newPrintSeries(String series) {
136
		Reference refBase = newPrintSeries();
137
		refBase.setTitle(series);
138
		refBase.setCacheStrategy(ReferenceType.PrintSeries.getCacheStrategy());
139
		return refBase;
140
	}
141

    
142
	public static Reference newBookSection(Reference book, TeamOrPersonBase partAuthor,
143
			String sectionTitle, String pages) {
144
		Reference bookSection = newBookSection();
145
		bookSection.setInBook(book);
146
		bookSection.setAuthorship(partAuthor);
147
		bookSection.setTitle(sectionTitle);
148
		bookSection.setPages(pages);
149
		return bookSection;
150
	}
151

    
152
	public static Reference newArticle(Reference inJournal, TeamOrPersonBase partAuthor,
153
			String title, String pages, String seriesPart, String volume, TimePeriod datePublished) {
154
		IArticle article = newArticle();
155
		article.setInReference(inJournal);
156
		article.setAuthorship(partAuthor);
157
		article.setTitle(title);
158
		article.setPages(pages);
159
		article.setVolume(volume);
160
		article.setSeriesPart(seriesPart);
161
		article.setDatePublished(datePublished);
162
		return (Reference)article;
163
	}
164

    
165
//****************************** by Type **************************************/
166

    
167
	/**
168
	 * Returns a new reference for the according reference type. If reference type is <code>null</code>,
169
	 * <code>null</code> is returned.
170
	 * @param referenceType
171
	 * @return
172
	 */
173
	public static Reference newReference(ReferenceType referenceType) {
174
		if (referenceType == null){
175
			return null;
176
		}
177
		switch(referenceType){
178
			case Article:
179
				return newArticle();
180
			case Journal:
181
				return newJournal();
182
			case BookSection:
183
				return newBookSection();
184
			case CdDvd:
185
				return newCdDvd();
186
			case Database:
187
				return newDatabase();
188
			case InProceedings:
189
				return newInProceedings();
190
			case Map:
191
				return newMap();
192
			case Patent:
193
				return newPatent();
194
			case PersonalCommunication:
195
				return newPersonalCommunication();
196
			case PrintSeries:
197
				return newPrintSeries();
198
			case Proceedings:
199
				return newProceedings();
200
			case Report:
201
				return newReport();
202
			case Thesis:
203
				return newThesis();
204
			case WebPage:
205
				return newWebPage();
206
			case Book:
207
				return newBook();
208
			case Generic:
209
				return newGeneric();
210
			case Section:
211
				return newSection();
212
			default:
213
				logger.warn("Unknown reference type " + referenceType.getMessage() + ". Created generic reference instead.");
214
				return newGeneric();
215
		}
216
	}
217

    
218
}
(24-24/27)