6d141bebecfe1409aeef50fe11758e6852c47fba
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / entitycreator / ReferenceCreator.java
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
11 package eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.model.reference.Reference;
19 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
20 import eu.etaxonomy.cdm.model.reference.ReferenceType;
21 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
22 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
23
24 /**
25 * <p>ReferenceCreator class.</p>
26 *
27 * @author p.ciardelli
28 * @created 07.07.2009
29 * @version 1.0
30 */
31 public class ReferenceCreator implements IEntityCreator<Reference> {
32
33 /* (non-Javadoc)
34 * @see eu.etaxonomy.taxeditor.bulkeditor.IEntityCreator#createEntity(java.lang.String)
35 */
36 /** {@inheritDoc} */
37 public Reference createEntity(String text) {
38 return createEntity(Reference.class, text);
39 }
40
41 /* (non-Javadoc)
42 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.Class, java.lang.String)
43 */
44 /** {@inheritDoc} */
45 public Reference createEntity(Object key, String text) {
46 Reference reference = null;
47
48 // TODO replace w more generic method when cdmlib matures accordingly
49 if (ReferenceType.Article.getMessage().equals(key)) {
50 reference = ReferenceFactory.newArticle();
51 }
52 if (ReferenceType.Book.getMessage().equals(key)) {
53 reference = ReferenceFactory.newBook();
54 }
55 if (ReferenceType.BookSection.getMessage().equals(key)) {
56 reference = ReferenceFactory.newBookSection();
57 }
58 if (ReferenceType.CdDvd.getMessage().equals(key)) {
59 reference = ReferenceFactory.newCdDvd();
60 }
61 if (ReferenceType.Database.getMessage().equals(key)) {
62 reference = ReferenceFactory.newDatabase();
63 }
64 if (ReferenceType.Generic.getMessage().equals(key)) {
65 reference = ReferenceFactory.newGeneric();
66 }
67 if (ReferenceType.InProceedings.getMessage().equals(key)) {
68 reference = ReferenceFactory.newInProceedings();
69 }
70 if (ReferenceType.Journal.getMessage().equals(key)) {
71 reference = ReferenceFactory.newJournal();
72 }
73 if (ReferenceType.Map.getMessage().equals(key)) {
74 reference = ReferenceFactory.newMap();
75 }
76 if (ReferenceType.Patent.getMessage().equals(key)) {
77 reference = ReferenceFactory.newPatent();
78 }
79 if (ReferenceType.PersonalCommunication.getMessage().equals(key)) {
80 reference = ReferenceFactory.newPersonalCommunication();
81 }
82 if (ReferenceType.PrintSeries.getMessage().equals(key)) {
83 reference = ReferenceFactory.newPrintSeries();
84 }
85 if (ReferenceType.Proceedings.getMessage().equals(key)) {
86 reference = ReferenceFactory.newProceedings();
87 }
88 if (ReferenceType.Report.getMessage().equals(key)) {
89 reference = ReferenceFactory.newReport();
90 }
91 if (ReferenceType.Thesis.getMessage().equals(key)) {
92 reference = ReferenceFactory.newThesis();
93 }
94 if (ReferenceType.WebPage.getMessage().equals(key)) {
95 reference = ReferenceFactory.newWebPage();
96 }
97 if (reference == null) {
98 BulkEditorUtil.warn(getClass(), "Reference type " + key + " not found. Creating reference with default type.");
99 reference = ReferenceFactory.newGeneric();
100 }
101 reference.setTitleCache(text);
102 return reference;
103 }
104
105 /* (non-Javadoc)
106 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#getClassLabelPairs()
107 */
108 /**
109 * <p>getKeyLabelPairs</p>
110 *
111 * @return a {@link java.util.Map} object.
112 */
113 public Map<Object, String> getKeyLabelPairs() {
114 Map<Object, String> result = new HashMap<Object, String>();
115 for (ReferenceType type : ReferenceType.values()) {
116 result.put(type.getMessage(), type.getMessage());
117 }
118 return result;
119 }
120 }