some generics
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / common / mapping / DbImportAnnotationCreationMapper.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.cdm.io.common.mapping;
12
13 import java.sql.ResultSet;
14 import java.sql.SQLException;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.io.common.DbImportStateBase;
19 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
20 import eu.etaxonomy.cdm.model.common.Annotation;
21 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
22 import eu.etaxonomy.cdm.model.common.Language;
23 import eu.etaxonomy.cdm.model.common.Marker;
24 import eu.etaxonomy.cdm.model.common.MarkerType;
25
26
27 /**
28 * Object creation mapper which creates a marker.
29 *
30 * @author a.mueller
31 * @created 11.03.2010
32 * @version 1.0
33 */
34 public class DbImportAnnotationCreationMapper extends DbImportSupplementCreationMapperBase<Annotation, AnnotatableEntity, DbImportStateBase<?, ?>> {
35 private static final Logger logger = Logger.getLogger(DbImportAnnotationCreationMapper.class);
36
37 //************************** FACTORY METHODS ***************************************************************/
38
39
40 /**
41 * @param dbAnnotatedObjectAttribute
42 * @param annotatedObjectNamespace
43 * @return
44 */
45 public static DbImportAnnotationCreationMapper NewInstance(String dbAnnotatedObjectAttribute, String annotatedObjectNamespace){
46 return new DbImportAnnotationCreationMapper(dbAnnotatedObjectAttribute, annotatedObjectNamespace, null, null, null, null);
47 }
48
49 /**
50 * Creates an annotation mapper which creates an annotation and sets the annotation text,
51 * the annotation language and annotation (added to this annotation) holding the original
52 * source id.
53 * If one of the attribute is null the according value is not set.
54
55 * @param dbAnnotatedObjectAttribute - obligatory
56 * @param annotatedObjectNamespace - obligatory
57 * @param dbAnnotationTextAttribute
58 * @param language
59 * @param dbIdAttribute
60 * @param annotationType
61 * @return
62 */
63 public static DbImportAnnotationCreationMapper NewInstance(String dbAnnotatedObjectAttribute, String annotatedObjectNamespace, String dbAnnotationTextAttribute, Language language, String dbIdAttribute, MarkerType annotationType){
64 return new DbImportAnnotationCreationMapper(dbAnnotatedObjectAttribute, annotatedObjectNamespace, dbAnnotationTextAttribute, language, dbIdAttribute, annotationType);
65 }
66
67 // ******************************* VARIABLES ****************************************/
68
69 protected Language language;
70
71 //********************************* CONSTRUCTOR ****************************************/
72
73 /**
74 * @param dbSupplementValueAttribute
75 * @param dbSupplementedObjectAttribute
76 * @param dbIdAttribute
77 * @param supplementedObjectNamespace
78 * @param supplementType
79 */
80 protected DbImportAnnotationCreationMapper(String dbSupplementedObjectAttribute, String supplementedObjectNamespace, String dbSupplementValueAttribute, Language language, String dbIdAttribute, DefinedTermBase supplementType) {
81 super(dbSupplementValueAttribute, dbSupplementedObjectAttribute, dbIdAttribute, supplementedObjectNamespace, supplementType);
82 this.language = language;
83 }
84
85 //************************************ METHODS *******************************************/
86
87 /* (non-Javadoc)
88 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportSupplementCreationMapperBase#addSupplement(eu.etaxonomy.cdm.model.common.AnnotatableEntity, java.lang.String, eu.etaxonomy.cdm.model.common.AnnotatableEntity)
89 */
90 @Override
91 protected boolean addSupplement(Annotation annotation, AnnotatableEntity annotatableEntity, String id) {
92 if (annotatableEntity != null){
93 annotatableEntity.addAnnotation(annotation);
94 return true;
95 }else{
96 String warning = "Annotatable entity (" + id + ") for annotation not found. Annotation not created.";
97 logger.warn(warning);
98 return false;
99 }
100 }
101
102 /* (non-Javadoc)
103 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportSupplementCreationMapperBase#setSupplementValue(java.lang.Object)
104 */
105 @Override
106 protected void setSupplementValue(ResultSet rs, Annotation annotation) throws SQLException {
107 String value = rs.getString(dbSupplementValueAttribute);
108 annotation.setText(value);
109
110 }
111
112 /* (non-Javadoc)
113 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
114 */
115 @Override
116 protected Annotation createObject(ResultSet rs) throws SQLException {
117 Annotation annotation = Annotation.NewInstance(null, null);
118 if (language != null){
119 annotation.setLanguage(language);
120 }
121 return annotation;
122 }
123
124
125 }