3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.io
.common
.mapping
;
13 import java
.sql
.ResultSet
;
14 import java
.sql
.SQLException
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
19 import eu
.etaxonomy
.cdm
.io
.common
.DbImportStateBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
21 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
22 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TextFormat
;
26 * This Mapper creates a text data element and adds it to a taxon.
31 public class DbImportTextDataCreationMapper
<STATE
extends DbImportStateBase
<?
,?
>> extends DbImportDescriptionElementCreationMapperBase
<TextData
, DbImportStateBase
<?
,?
>> {
32 @SuppressWarnings("unused")
33 private static final Logger logger
= Logger
.getLogger(DbImportTextDataCreationMapper
.class);
35 //******************************** FACTORY METHOD ***************************************************/
39 * Creates a Distribution and adds it to the description of a taxon.
40 * @param dbIdAttribute
41 * @param objectToCreateNamespace
42 * @param dbTaxonFkAttribute
43 * @param taxonNamespace
46 public static DbImportTextDataCreationMapper
<?
> NewInstance(String dbIdAttribute
, String objectToCreateNamespace
, String dbTaxonFkAttribute
, String taxonNamespace
){
47 Feature feature
= null;
48 Language language
= null;
49 TextFormat format
= null;
50 String dbTextAttribute
= null;
51 return new DbImportTextDataCreationMapper(dbIdAttribute
, objectToCreateNamespace
, dbTaxonFkAttribute
, taxonNamespace
, dbTextAttribute
, language
, feature
, format
);
56 * Creates a TextData, adds the the in the language and the format defined and then adds it to the description of a taxon.
57 * If language is <code>null</code> the default language is taken instead.
58 * @param dbIdAttribute
59 * @param objectToCreateNamespace
60 * @param dbTaxonFkAttribute
61 * @param taxonNamespace
65 public static DbImportTextDataCreationMapper
<?
> NewInstance(String dbIdAttribute
, String objectToCreateNamespace
, String dbTaxonFkAttribute
, String taxonNamespace
, String dbTextAttribute
, Language language
, Feature feature
, TextFormat format
){
66 return new DbImportTextDataCreationMapper(dbIdAttribute
, objectToCreateNamespace
, dbTaxonFkAttribute
, taxonNamespace
, dbTextAttribute
, language
, feature
, format
);
69 //******************************* ATTRIBUTES ***************************************/
71 protected Feature defaultFeature
;
72 protected Language defaultLanguage
;
73 protected TextFormat defaultFormat
;
74 protected String dbTextAttribute
;
76 //********************************* CONSTRUCTOR ****************************************/
78 * @param dbIdAttribute
79 * @param objectToCreateNamespace
80 * @param dbTaxonFkAttribute
81 * @param taxonNamespace
83 protected DbImportTextDataCreationMapper(String dbIdAttribute
, String objectToCreateNamespace
, String dbTaxonFkAttribute
, String dbTextAttribute
, String taxonNamespace
, Language language
, Feature feature
, TextFormat format
) {
84 super(dbIdAttribute
, objectToCreateNamespace
, dbTaxonFkAttribute
, taxonNamespace
);
85 this.defaultFeature
= feature
;
86 this.defaultLanguage
= language
;
87 this.defaultFormat
= format
;
90 //************************************ METHODS *******************************************/
93 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
96 protected TextData
createObject(ResultSet rs
) throws SQLException
{
97 TextData textData
= TextData
.NewInstance();
99 if (CdmUtils
.isNotEmpty(dbTextAttribute
)){
100 text
= rs
.getString(dbTextAttribute
);
103 Language language
= this.defaultLanguage
;
104 if (language
== null){
105 language
= Language
.DEFAULT();
107 textData
.putText(text
, language
);
109 TextFormat format
= this.defaultFormat
;
110 textData
.setFormat(format
);
112 Feature feature
= this.defaultFeature
;
113 textData
.setFeature(feature
);