| 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.Person; |
|---|
| 15 | import eu.etaxonomy.cdm.model.common.TimePeriod; |
|---|
| 16 | import eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy; |
|---|
| 17 | import eu.etaxonomy.cdm.strategy.cache.reference.BookDefaultCacheStrategy; |
|---|
| 18 | import eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy; |
|---|
| 19 | import eu.etaxonomy.cdm.strategy.cache.reference.CdDvdDefaultCacheStrategy; |
|---|
| 20 | import eu.etaxonomy.cdm.strategy.cache.reference.GenericDefaultCacheStrategy; |
|---|
| 21 | import eu.etaxonomy.cdm.strategy.cache.reference.JournalDefaultCacheStrategy; |
|---|
| 22 | import eu.etaxonomy.cdm.strategy.cache.reference.ReferenceBaseDefaultCacheStrategy; |
|---|
| 23 | import eu.etaxonomy.cdm.strategy.cache.reference.ThesisDefaultCacheStrategy; |
|---|
| 24 | |
|---|
| 25 | public class ReferenceFactory { |
|---|
| 26 | private static final Logger logger = Logger.getLogger(ReferenceFactory.class); |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * @return |
|---|
| 31 | * @deprecated //use static methods instead |
|---|
| 32 | */ |
|---|
| 33 | public static ReferenceFactory newInstance(){ |
|---|
| 34 | return new ReferenceFactory(); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | public static Reference newArticle(){ |
|---|
| 38 | Reference<ArticleDefaultCacheStrategy> article = new Reference(ReferenceType.Article); |
|---|
| 39 | article.setCacheStrategy(ReferenceType.Article.getCacheStrategy()); |
|---|
| 40 | return article; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | public static Reference newJournal(){ |
|---|
| 44 | Reference<JournalDefaultCacheStrategy<Reference>> journal = new Reference(ReferenceType.Journal); |
|---|
| 45 | journal.setCacheStrategy(ReferenceType.Journal.getCacheStrategy()); |
|---|
| 46 | return journal; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public static Reference newBook(){ |
|---|
| 50 | Reference<BookDefaultCacheStrategy<Reference>> book = new Reference<BookDefaultCacheStrategy<Reference>>(ReferenceType.Book); |
|---|
| 51 | book.setCacheStrategy(ReferenceType.Book.getCacheStrategy()); |
|---|
| 52 | return book; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | public static Reference newThesis(){ |
|---|
| 56 | Reference<ThesisDefaultCacheStrategy<Reference>> thesis = new Reference<ThesisDefaultCacheStrategy<Reference>>(ReferenceType.Thesis); |
|---|
| 57 | thesis.setCacheStrategy(ReferenceType.Thesis.getCacheStrategy()); |
|---|
| 58 | return thesis; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public static Reference newInProceedings(){ |
|---|
| 62 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> inProceedings = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.InProceedings); |
|---|
| 63 | inProceedings.setCacheStrategy(ReferenceType.InProceedings.getCacheStrategy()); |
|---|
| 64 | return inProceedings; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | public static Reference newProceedings(){ |
|---|
| 68 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> proceedings = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.Proceedings); |
|---|
| 69 | proceedings.setCacheStrategy(ReferenceType.Proceedings.getCacheStrategy()); |
|---|
| 70 | return proceedings; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | public static Reference newBookSection(){ |
|---|
| 74 | Reference<BookSectionDefaultCacheStrategy<Reference>> bookSection = new Reference<BookSectionDefaultCacheStrategy<Reference>>(ReferenceType.BookSection); |
|---|
| 75 | bookSection.setCacheStrategy(ReferenceType.BookSection.getCacheStrategy()); |
|---|
| 76 | return bookSection; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | public static Reference newCdDvd(){ |
|---|
| 80 | Reference<CdDvdDefaultCacheStrategy<Reference>> cdDvd= new Reference<CdDvdDefaultCacheStrategy<Reference>>(ReferenceType.CdDvd); |
|---|
| 81 | cdDvd.setCacheStrategy(ReferenceType.CdDvd.getCacheStrategy()); |
|---|
| 82 | return cdDvd; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | public static Reference newGeneric(){ |
|---|
| 86 | Reference generic = new Reference<GenericDefaultCacheStrategy>(ReferenceType.Generic); |
|---|
| 87 | generic.setCacheStrategy(ReferenceType.Generic.getCacheStrategy()); |
|---|
| 88 | return generic; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | public static Reference newMap(){ |
|---|
| 92 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> map = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.Map); |
|---|
| 93 | map.setCacheStrategy(ReferenceType.Map.getCacheStrategy()); |
|---|
| 94 | return map; |
|---|
| 95 | |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | public static Reference newReport(){ |
|---|
| 99 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> report = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.Report); |
|---|
| 100 | report.setCacheStrategy(ReferenceType.Report.getCacheStrategy()); |
|---|
| 101 | return report; |
|---|
| 102 | |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | public static Reference newWebPage(){ |
|---|
| 106 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> webPage = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.WebPage); |
|---|
| 107 | webPage.setCacheStrategy(ReferenceType.WebPage.getCacheStrategy()); |
|---|
| 108 | return webPage; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | public static Reference newDatabase(){ |
|---|
| 112 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> db = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.Database); |
|---|
| 113 | db.setCacheStrategy(ReferenceType.Database.getCacheStrategy()); |
|---|
| 114 | return db; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | /** |
|---|
| 119 | * Creates a new empty print series instance. |
|---|
| 120 | */ |
|---|
| 121 | public static Reference newPrintSeries() { |
|---|
| 122 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> refBase = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.PrintSeries); |
|---|
| 123 | refBase.setCacheStrategy(ReferenceType.PrintSeries.getCacheStrategy()); |
|---|
| 124 | return refBase; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * Creates a new print series instance with a given title string. |
|---|
| 129 | */ |
|---|
| 130 | public static Reference newPrintSeries(String series) { |
|---|
| 131 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> refBase = newPrintSeries(); |
|---|
| 132 | refBase.setCacheStrategy(ReferenceType.PrintSeries.getCacheStrategy()); |
|---|
| 133 | return refBase; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | public Reference newBookSection(Reference book, Person partAuthor, |
|---|
| 137 | String sectionTitle, String pages) { |
|---|
| 138 | Reference bookSection = newBookSection(); |
|---|
| 139 | bookSection.setAuthorTeam(partAuthor); |
|---|
| 140 | bookSection.setTitle(sectionTitle); |
|---|
| 141 | bookSection.setPages(pages); |
|---|
| 142 | return bookSection; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | public static Reference newArticle(Reference inJournal, Person partAuthor, |
|---|
| 146 | String title, String pages, String series, String volume, TimePeriod datePublished) { |
|---|
| 147 | Reference article = newArticle(); |
|---|
| 148 | article.setInReference(inJournal); |
|---|
| 149 | article.setAuthorTeam(partAuthor); |
|---|
| 150 | article.setTitle(title); |
|---|
| 151 | article.setPages(pages); |
|---|
| 152 | article.setVolume(volume); |
|---|
| 153 | article.setDatePublished(datePublished); |
|---|
| 154 | return article; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | /** |
|---|
| 158 | * Returns a new reference for the according reference type. If reference type is <code>null</code>, |
|---|
| 159 | * <code>null</code> is returned. |
|---|
| 160 | * @param referenceType |
|---|
| 161 | * @return |
|---|
| 162 | */ |
|---|
| 163 | public static Reference newReference(ReferenceType referenceType) { |
|---|
| 164 | if (referenceType == null){ |
|---|
| 165 | return null; |
|---|
| 166 | } |
|---|
| 167 | switch(referenceType){ |
|---|
| 168 | case Article: |
|---|
| 169 | return newArticle(); |
|---|
| 170 | case Journal: |
|---|
| 171 | return newJournal(); |
|---|
| 172 | case BookSection: |
|---|
| 173 | return newBookSection(); |
|---|
| 174 | case CdDvd: |
|---|
| 175 | return newCdDvd(); |
|---|
| 176 | case Database: |
|---|
| 177 | return newDatabase(); |
|---|
| 178 | case InProceedings: |
|---|
| 179 | return newInProceedings(); |
|---|
| 180 | case Map: |
|---|
| 181 | return newMap(); |
|---|
| 182 | case Patent: |
|---|
| 183 | return newPatent(); |
|---|
| 184 | case PersonalCommunication: |
|---|
| 185 | return newPersonalCommunication(); |
|---|
| 186 | case PrintSeries: |
|---|
| 187 | return newPrintSeries(); |
|---|
| 188 | case Proceedings: |
|---|
| 189 | return newProceedings(); |
|---|
| 190 | case Report: |
|---|
| 191 | return newReport(); |
|---|
| 192 | case Thesis: |
|---|
| 193 | return newThesis(); |
|---|
| 194 | case WebPage: |
|---|
| 195 | return newWebPage(); |
|---|
| 196 | case Book: |
|---|
| 197 | return newBook(); |
|---|
| 198 | case Generic: |
|---|
| 199 | return newGeneric(); |
|---|
| 200 | default: |
|---|
| 201 | logger.warn("Unknown reference type " + referenceType.getMessage() + ". Created generic reference instead."); |
|---|
| 202 | return newGeneric(); |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | public static Reference newPersonalCommunication() { |
|---|
| 207 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> personalCommunication = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.PersonalCommunication); |
|---|
| 208 | personalCommunication.setCacheStrategy(ReferenceType.PersonalCommunication.getCacheStrategy()); |
|---|
| 209 | return personalCommunication; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | public static Reference newPatent() { |
|---|
| 213 | Reference<ReferenceBaseDefaultCacheStrategy<Reference>> patent = new Reference<ReferenceBaseDefaultCacheStrategy<Reference>>(ReferenceType.Patent); |
|---|
| 214 | patent.setCacheStrategy(ReferenceType.Patent.getCacheStrategy()); |
|---|
| 215 | return patent; |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | } |
|---|