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
.lang
.reflect
.InvocationTargetException
;
14 import java
.lang
.reflect
.Method
;
15 import java
.sql
.ResultSet
;
16 import java
.sql
.SQLException
;
17 import java
.util
.HashMap
;
20 import org
.apache
.log4j
.Logger
;
22 import eu
.etaxonomy
.cdm
.io
.common
.DbImportStateBase
;
23 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
24 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
26 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
33 public class DbImportMultiLanguageTextMapper
<CDMBASE
extends CdmBase
> extends DbImportMultiAttributeMapperBase
<CDMBASE
, DbImportStateBase
<?
,?
>> {
34 @SuppressWarnings("unused")
35 private static final Logger logger
= Logger
.getLogger(DbImportMultiLanguageTextMapper
.class);
37 //****************************** FACTORY METHOD ********************************************/
39 public static DbImportMultiLanguageTextMapper
NewInstance(String dbTextAttribute
, String dbLanguageAttribute
, String languageNamespace
, String cdmMultiLanguageTextAttribute
){
40 return new DbImportMultiLanguageTextMapper(dbTextAttribute
, dbLanguageAttribute
, languageNamespace
, cdmMultiLanguageTextAttribute
);
44 //***************************** VARIABLES *************************************************/
46 private String dbTextAttribute
;
47 private String dbLanguageAttribute
;
48 private String languageNamespace
;
49 private String cdmMultiLanguageTextAttribute
;
50 private Method destinationMethod
;
52 //***************************** CONSTRUCTOR *************************************************/
54 protected DbImportMultiLanguageTextMapper(String dbTextAttribute
, String dbLanguageAttribute
, String languageNamespace
, String cdmMultiLanguageTextAttribute
){
56 this.dbTextAttribute
= dbTextAttribute
;
57 this.dbLanguageAttribute
= dbLanguageAttribute
;
58 this.languageNamespace
= languageNamespace
;
59 this.cdmMultiLanguageTextAttribute
= cdmMultiLanguageTextAttribute
;
63 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportMultiAttributeMapperBase#initialize(eu.etaxonomy.cdm.io.common.DbImportStateBase, java.lang.Class)
66 public void initialize(DbImportStateBase
<?
,?
> state
, Class
<?
extends CdmBase
> destinationClass
) {
67 super.initialize(state
, destinationClass
);
69 Class targetClass
= getTargetClass(destinationClass
);
70 Class
<?
> parameterType
= getTypeClass();
71 String methodName
= ImportHelper
.getSetterMethodName(targetClass
, cdmMultiLanguageTextAttribute
);
72 destinationMethod
= targetClass
.getMethod(methodName
, parameterType
);
73 } catch (SecurityException e
) {
74 throw new RuntimeException(e
);
75 } catch (NoSuchMethodException e
) {
76 throw new RuntimeException(e
);
81 * This method is used to be compliant with DbSingleAttributeImport
84 protected Class
<?
> getTypeClass() {
89 * This method is used to be compliant with DbSingleAttributeImport
90 * @param destinationClass
92 * @throws SecurityException
93 * @throws NoSuchMethodException
95 protected Class
getTargetClass(Class
<?
> destinationClass
) throws SecurityException
, NoSuchMethodException
{
96 return destinationClass
;
100 * @see eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper#invoke(java.sql.ResultSet, eu.etaxonomy.cdm.model.common.CdmBase)
102 public CDMBASE
invoke(ResultSet rs
, CDMBASE cdmBase
) throws SQLException
{
103 //TODO make this a definedTermMapper
104 Language language
= (Language
)getRelatedObject(rs
, languageNamespace
, dbLanguageAttribute
);
105 String text
= getStringDbValue(rs
, dbTextAttribute
);
107 Map
<Language
, LanguageString
> multilanguageText
= new HashMap
<Language
, LanguageString
>();
108 LanguageString languageString
= LanguageString
.NewInstance(text
, language
);
109 multilanguageText
.put(language
, languageString
);
111 destinationMethod
.invoke(cdmBase
, multilanguageText
);
112 } catch (IllegalArgumentException e
) {
114 } catch (IllegalAccessException e
) {
115 throw new RuntimeException(e
);
116 } catch (InvocationTargetException e
) {
117 throw new RuntimeException (e
);