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
.io
.common
.DbImportStateBase
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.DescriptionElementSource
;
21 import eu
.etaxonomy
.cdm
.model
.common
.IOriginalSource
;
22 import eu
.etaxonomy
.cdm
.model
.common
.ISourceable
;
23 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
24 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
25 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
26 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
34 //TODO remove ANNOTATABLE by ISourcable (but this is not CDMBase yet therefore not trivial
35 public abstract class DbImportObjectCreationMapperBase
<CREATE
extends VersionableEntity
, STATE
extends DbImportStateBase
<?
,?
>> extends DbImportMultiAttributeMapperBase
<CREATE
, STATE
> {
36 private static final Logger logger
= Logger
.getLogger(DbImportObjectCreationMapperBase
.class);
39 //******************************* ATTRIBUTES ***************************************/
40 protected String dbIdAttribute
;
41 //TODO get standard namespace from mappingImport
42 protected String objectToCreateNamespace
;
45 //********************************* CONSTRUCTOR ****************************************/
47 * @param mappingImport
49 protected DbImportObjectCreationMapperBase(String dbIdAttribute
, String objectToCreateNamespace
) {
51 //TODO make it a single attribute mapper
52 this.dbIdAttribute
= dbIdAttribute
;
53 this.objectToCreateNamespace
= objectToCreateNamespace
;
56 //************************************ METHODS *******************************************/
59 * @see eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper#initialize(eu.etaxonomy.cdm.io.common.DbImportStateBase, java.lang.Class)
61 public void initialize(STATE state
, Class
<?
extends CdmBase
> destinationClass
) {
62 super.initialize(state
, destinationClass
);
63 //Todo remove initialize when this logging is not needed anymore
64 logger
.warn("DbImportObjectCreationMapperBase still needs 'citation' implemented for OriginalSource"); //see addOriginalSource()
69 * @see eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper#invoke(java.sql.ResultSet, eu.etaxonomy.cdm.model.common.CdmBase)
71 public CREATE
invoke(ResultSet rs
, CREATE noObject
) throws SQLException
{
72 CREATE result
= createObject(rs
);
73 result
= doInvoke(rs
, result
);
74 addOriginalSource(rs
, result
);
81 * @throws SQLException
83 protected abstract CREATE
doInvoke(ResultSet rs
, CREATE createdObject
) throws SQLException
;
86 * This method creates the object to be created. It needs to be implemented by the concrete classes.
87 * E.g. if you have a TaxonNameCreation class which inherits from this class you need to implement
88 * createObject by creating an empty taxon name.
89 * @param rs The result set
90 * @return The object to be created
91 * @throws SQLException
93 protected abstract CREATE
createObject(ResultSet rs
) throws SQLException
;
96 * TODO also implemented in CdmImportBase (reduce redundance)
97 * @throws SQLException
99 public void addOriginalSource(ResultSet rs
, CREATE cdmBase
) throws SQLException
{
100 if (cdmBase
instanceof ISourceable
){
101 IOriginalSource source
;
102 ISourceable sourceable
= (ISourceable
)cdmBase
;
103 Object id
= rs
.getObject(dbIdAttribute
);
104 String strId
= String
.valueOf(id
);
105 String idNamespace
= this.objectToCreateNamespace
;
107 ReferenceBase citation
= null;
108 //importMapperHelper.getState().getConfig()xxx;
109 String microCitation
= null;
110 if (cdmBase
instanceof IdentifiableEntity
){
111 source
= IdentifiableSource
.NewInstance(strId
, idNamespace
, citation
, microCitation
);
112 }else if (cdmBase
instanceof DescriptionElementBase
){
113 source
= DescriptionElementSource
.NewInstance(strId
, idNamespace
, citation
, microCitation
);
115 logger
.warn("ISourceable not beeing identifiable entities or description element base are not yet supported. CdmBase is of type " + cdmBase
.getClass().getSimpleName() + ". Original source not added.");
118 sourceable
.addSource(source
);
126 * Returns the transformer from the configuration
129 protected IInputTransformer
getTransformer(){
130 return getState().getConfig().getTransformer();