2 * Copyright (C) 2008 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
7 package eu
.etaxonomy
.cdm
.io
.common
;
9 import org
.apache
.log4j
.Logger
;
11 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
12 import eu
.etaxonomy
.cdm
.database
.DataSourceNotFoundException
;
13 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
14 import eu
.etaxonomy
.cdm
.io
.common
.IExportConfigurator
.CHECK
;
15 import eu
.etaxonomy
.cdm
.model
.common
.init
.TermNotFoundException
;
16 import eu
.etaxonomy
.cdm
.model
.reference
.Database
;
17 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
20 * @author a.babadshanjan
23 public abstract class ExportConfiguratorBase
<DESTINATION
extends Object
> extends IoConfiguratorBase
{
25 private static final Logger logger
= Logger
.getLogger(ExportConfiguratorBase
.class);
27 private CHECK check
= CHECK
.EXPORT_WITHOUT_CHECK
;
29 private ICdmDataSource source
;
30 private DESTINATION destination
;
31 //private DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
32 private CdmApplicationController cdmApp
= null;
33 protected ReferenceBase sourceReference
;
34 protected Class
<ICdmIO
>[] ioClassList
;
37 public ExportConfiguratorBase(){
39 //setDbSchemaValidation(DbSchemaValidation.UPDATE);
43 abstract protected void makeIoClassList();
45 public ICdmDataSource
getSource() {
49 public void setSource(ICdmDataSource source
) {
54 * @param source the source to get
56 public DESTINATION
getDestination() {
61 * @param source the source to set
63 public void setDestination(DESTINATION destination
) {
64 this.destination
= destination
;
68 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
71 public ReferenceBase
getSourceReference() {
73 if (this.sourceReference
== null){
74 sourceReference
= Database
.NewInstance();
75 if (getSource() != null){
76 sourceReference
.setTitleCache(getSource().getDatabase());
79 return sourceReference
;
82 public Class
<ICdmIO
>[] getIoClassList(){
87 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCheck()
89 public CHECK
getCheck() {
94 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.tcsrdf.TcsRdfImportConfigurator.CHECK)
96 public void setCheck(CHECK check
) {
101 * @see eu.etaxonomy.cdm.io.tcsrdf.IExportConfigurator#getDbSchemaValidation()
103 // public DbSchemaValidation getDbSchemaValidation() {
104 // return dbSchemaValidation;
108 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
109 * If a controller was already created before the last created controller is returned.
112 public CdmApplicationController
getCdmAppController(){
113 return getCdmAppController(false);
117 * Returns a new instance of <code>CdmApplicationController</code> created by the values of this configuration.
120 public CdmApplicationController
getNewCdmAppController(){
121 return getCdmAppController(true, false);
125 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
126 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
127 * been created before a new controller is returned.
130 public CdmApplicationController
getCdmAppController(boolean createNew
){
131 return getCdmAppController(createNew
, false);
136 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
137 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
138 * been created before a new controller is returned.
141 public CdmApplicationController
getCdmAppController(boolean createNew
, boolean omitTermLoading
){
142 if (cdmApp
== null || createNew
== true){
144 cdmApp
= CdmApplicationController
.NewInstance(this.getSource(), this.getDbSchemaValidation(), omitTermLoading
);
145 } catch (DataSourceNotFoundException e
) {
146 logger
.error("could not connect to destination database");
148 }catch (TermNotFoundException e
) {
149 logger
.error("could not find needed term in destination datasource");
158 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#isValid()
160 public boolean isValid(){
161 boolean result
= true;
163 logger
.warn("Connection to CDM could not be established");
166 if (destination
== null){
167 logger
.warn("Invalid export destination");
174 public String
getSourceNameString() {
175 if (this.getSource() == null) {
178 return (String
)this.getSource().getName();