root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/ReferenceType.java

Revision 13730, 8.0 kB (checked in by n.hoffmann, 4 months ago)
Line 
1// $Id$
2/**
3* Copyright (C) 2007 EDIT
4* European Distributed Institute of Taxonomy
5* http://www.e-taxonomy.eu
6*
7* The contents of this file are subject to the Mozilla Public License Version 1.1
8* See LICENSE.TXT at the top of this package for the full license terms.
9*/
10
11package eu.etaxonomy.cdm.model.reference;
12
13import java.io.Serializable;
14import java.util.HashSet;
15import java.util.List;
16import java.util.Set;
17import java.util.UUID;
18
19import javax.persistence.Transient;
20import javax.xml.bind.annotation.XmlEnum;
21import javax.xml.bind.annotation.XmlEnumValue;
22
23import org.apache.log4j.Logger;
24
25import au.com.bytecode.opencsv.CSVWriter;
26import eu.etaxonomy.cdm.model.common.DefinedTermBase;
27import eu.etaxonomy.cdm.model.common.IDefinedTerm;
28import eu.etaxonomy.cdm.model.common.Language;
29import eu.etaxonomy.cdm.model.media.Media;
30import eu.etaxonomy.cdm.strategy.cache.reference.ArticleDefaultCacheStrategy;
31import eu.etaxonomy.cdm.strategy.cache.reference.BookDefaultCacheStrategy;
32import eu.etaxonomy.cdm.strategy.cache.reference.BookSectionDefaultCacheStrategy;
33import eu.etaxonomy.cdm.strategy.cache.reference.CdDvdDefaultCacheStrategy;
34import eu.etaxonomy.cdm.strategy.cache.reference.GenericDefaultCacheStrategy;
35import eu.etaxonomy.cdm.strategy.cache.reference.IReferenceBaseCacheStrategy;
36import eu.etaxonomy.cdm.strategy.cache.reference.JournalDefaultCacheStrategy;
37import eu.etaxonomy.cdm.strategy.cache.reference.ReferenceBaseDefaultCacheStrategy;
38import eu.etaxonomy.cdm.strategy.cache.reference.ThesisDefaultCacheStrategy;
39
40
41/**
42 * The reference type is used to define the type of a {@link Reference reference}.<BR>
43 * When changing the type of a reference one must be careful with handling attached information.
44 * E.g. changing the type of a reference from article to book section requires to either exchange
45 * the in reference or to change the type of the in reference which may have further consequences.
46 * @author a.mueller
47 * @created 20.09.2009
48 * @version 1.0
49 */
50@XmlEnum
51public enum ReferenceType implements IDefinedTerm<ReferenceType>, Serializable{
52        //0
53        @XmlEnumValue("Article")   
54        Article(UUID.fromString("fddfb343-f652-4f33-b6cb-7c94daa2f1ec"), "Article", ArticleDefaultCacheStrategy.class),
55        //1
56        @XmlEnumValue("Book")     
57        Book(UUID.fromString("9280876c-accb-4c47-873d-46bbf4296f18"), "Book", BookDefaultCacheStrategy.class),
58        //2
59        @XmlEnumValue("Book Section") 
60        BookSection(UUID.fromString("b197435d-deec-46fa-9c66-e0e6c44c57fb"), "Book Section", BookSectionDefaultCacheStrategy.class),
61        //3
62        @XmlEnumValue("CD or DVD")
63        CdDvd(UUID.fromString("7d7c9f56-d6fd-45aa-852f-b965afe08ec0"), "CD or DVD", CdDvdDefaultCacheStrategy.class),
64        //4
65        @XmlEnumValue("Database")
66        Database(UUID.fromString("a36dbaec-0536-4a20-9fbc-e1b10ba35ea6"), "Database", ReferenceBaseDefaultCacheStrategy.class),
67        //5
68        @XmlEnumValue("Generic")
69        Generic(UUID.fromString("df149dd8-f2b4-421c-b478-acc4cce63f25"), "Generic", GenericDefaultCacheStrategy.class),
70        //6
71        @XmlEnumValue("Inproceedings")
72        InProceedings(UUID.fromString("a84dae35-6708-4c3d-8bb6-41b989947fa2"), "In Proceedings", ReferenceBaseDefaultCacheStrategy.class),
73        //7
74        @XmlEnumValue("Journal")
75        Journal(UUID.fromString("d8675c58-41cd-44fb-86be-e966bd4bc747"), "Journal", JournalDefaultCacheStrategy.class),
76        //8
77        @XmlEnumValue("Map")
78        Map(UUID.fromString("f4acc990-a277-4d80-9192-bc04be4b1cab"), "Map", ReferenceBaseDefaultCacheStrategy.class),
79        //9
80        @XmlEnumValue("Patent")
81        Patent(UUID.fromString("e44e0e6b-a721-417c-9b03-01926ea0bf56"), "Patent", ReferenceBaseDefaultCacheStrategy.class),
82        //10
83        @XmlEnumValue("Personal Communication")
84        PersonalCommunication(UUID.fromString("4ba5607e-1b9d-473c-89dd-8f1c2d27ae50"), "Personal Communication", ReferenceBaseDefaultCacheStrategy.class),
85        //11
86        @XmlEnumValue("Print Series")
87        PrintSeries(UUID.fromString("d455f30d-2685-4f57-804a-3df5ba4e0888"), "Print Series", ReferenceBaseDefaultCacheStrategy.class),
88        //12
89        @XmlEnumValue("Proceedings")
90        Proceedings(UUID.fromString("cd934865-cb25-41f1-a155-f344ccb0c57f"), "Proceedings", ReferenceBaseDefaultCacheStrategy.class),
91        //13
92        @XmlEnumValue("Report")
93        Report(UUID.fromString("4d5459b8-b65b-47cb-9579-2fe7be360d04"), "Report", ReferenceBaseDefaultCacheStrategy.class),
94        //14
95        @XmlEnumValue("Thesis")
96        Thesis(UUID.fromString("cd054393-4f5e-4842-b820-b820e5732d72"), "Thesis", ThesisDefaultCacheStrategy.class),
97        //15
98        @XmlEnumValue("Web Page")
99        WebPage(UUID.fromString("1ed8b0df-0532-40ea-aef6-ee4361341165"), "Web Page", ReferenceBaseDefaultCacheStrategy.class);
100       
101        private static final Logger logger = Logger.getLogger(ReferenceType.class);
102       
103        private String readableString;
104        private Class<? extends IReferenceBaseCacheStrategy> cacheStrategy;
105        private UUID uuid;
106       
107        private ReferenceType(UUID uuid, String defaultString, Class<? extends IReferenceBaseCacheStrategy> cacheStrategy){
108                this.uuid = uuid;
109                readableString = defaultString;
110                this.cacheStrategy = cacheStrategy;
111        }
112       
113        @Transient
114        public String getMessage(){
115                return getMessage(Language.DEFAULT());
116        }
117        public String getMessage(Language language){
118                //TODO make multi-lingual
119                return readableString;
120        }
121
122        public IReferenceBaseCacheStrategy getCacheStrategy(){
123                switch(this){
124                case Article: 
125                        return ArticleDefaultCacheStrategy.NewInstance();
126                case Book:
127                        return BookDefaultCacheStrategy.NewInstance();
128                case BookSection:
129                        return BookSectionDefaultCacheStrategy.NewInstance();
130                case CdDvd:
131                        return CdDvdDefaultCacheStrategy.NewInstance();
132                case Generic:
133                        return GenericDefaultCacheStrategy.NewInstance();
134                case Journal:
135                        return JournalDefaultCacheStrategy.NewInstance();
136                case Thesis:
137                        return ThesisDefaultCacheStrategy.NewInstance();
138                }
139                return ReferenceBaseDefaultCacheStrategy.NewInstance();
140        }
141       
142        /**
143         * Returns true if references of this type have volume information.
144         */
145        public boolean isVolumeReference(){
146                return (this == Article || isPrintedUnit() || this == Generic);
147        }
148       
149        /**
150         * Returns true if references of this type are publications (inheriting from
151         * {@link IPublicationBase}) and therefore have a publisher and a publication place.
152         */
153        public boolean isPublication(){
154                return (this == CdDvd || this == Database || this == Generic
155                                || this == Journal || isPrintedUnit() ||  this == PrintSeries
156                                || this == Report  || this == Thesis
157                                || this == WebPage || this == Map);                     
158        }
159       
160        /**
161         * Returns true if references of this type are printed units (inheriting from
162         * {@link IPrintedUnitBase}) and therefore may have an editor, an in-series or an string
163         * representing the series (seriesPart).
164         */
165        public boolean isPrintedUnit(){
166                return (this == Book || this == Proceedings);
167        }
168       
169        /**
170         * Returns true if references of this type are parts of other references (inheriting from
171         * {@link ISectionBase}) and therefore may have an in-reference and pages.
172         */
173        public boolean isSection(){
174                return (this == BookSection || this == InProceedings
175                                || isPrintedUnit() || this == Article );
176        }
177
178       
179        public ReferenceType readCsvLine(Class<ReferenceType> termClass,
180                        List<String> csvLine, java.util.Map<UUID, DefinedTermBase> terms) {
181                // TODO Auto-generated method stub
182                return null;
183        }
184
185       
186        public void writeCsvLine(CSVWriter writer, ReferenceType term) {
187                logger.warn("write csvLine not yet implemented");
188        }
189
190       
191        public UUID getUuid() {
192                return this.uuid;
193        }
194
195       
196        public ReferenceType getByUuid(UUID uuid) {
197                for (ReferenceType referenceType : ReferenceType.values()){
198                        if (referenceType.getUuid().equals(uuid)){
199                                return referenceType;
200                        }
201                }
202                return null;
203        }
204
205       
206        public ReferenceType getKindOf() {
207                return null;
208        }
209
210       
211        public Set<ReferenceType> getGeneralizationOf() {
212                return new HashSet<ReferenceType>();
213        }
214
215       
216        public ReferenceType getPartOf() {
217                return null;
218        }
219
220       
221        public Set<ReferenceType> getIncludes() {
222                return new HashSet<ReferenceType>();
223        }
224
225       
226        public Set<Media> getMedia() {
227                return new HashSet<Media>();
228        }
229       
230}
Note: See TracBrowser for help on using the browser.