1 /**
2 * Copyright (C) 2008 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 */
6
7 package eu.etaxonomy.cdm.io.common;
8
9 import org.apache.log4j.Logger;
10
11 import eu.etaxonomy.cdm.database.DbSchemaValidation;
12 import eu.etaxonomy.cdm.database.ICdmDataSource;
13 import eu.etaxonomy.cdm.io.common.IExportConfigurator.CHECK;
14 import eu.etaxonomy.cdm.model.reference.IDatabase;
15 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
16 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
17
18 /**
19 * @author a.babadshanjan
20 * @created 16.11.2008
21 */
22 public abstract class ExportConfiguratorBase<DESTINATION extends Object> extends IoConfiguratorBase {
23
24 private static final Logger logger = Logger.getLogger(ExportConfiguratorBase.class);
25
26 private CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
27
28 private ICdmDataSource source;
29 private DESTINATION destination;
30 protected IDatabase sourceReference;
31 protected Class<ICdmIO>[] ioClassList;
32
33
34 public ExportConfiguratorBase(){
35 super();
36 //setDbSchemaValidation(DbSchemaValidation.UPDATE);
37 makeIoClassList();
38 }
39
40 abstract protected void makeIoClassList();
41
42 public ICdmDataSource getSource() {
43 return source;
44 }
45
46 public void setSource(ICdmDataSource source) {
47 this.source = source;
48 }
49
50 /**
51 * @param source the source to get
52 */
53 public DESTINATION getDestination() {
54 return destination;
55 }
56
57 /**
58 * @param source the source to set
59 */
60 public void setDestination(DESTINATION destination) {
61 this.destination = destination;
62 }
63
64
65
66 /* (non-Javadoc)
67 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
68 */
69 // @Override
70 public IDatabase getSourceReference() {
71 //TODO //needed
72 ReferenceFactory refFactory = ReferenceFactory.newInstance();
73 if (this.sourceReference == null){
74 sourceReference = refFactory.newDatabase();
75 if (getSource() != null){
76 sourceReference.setTitleCache(getSource().getDatabase(), true);
77 }
78 }
79 return sourceReference;
80 }
81
82 public Class<ICdmIO>[] getIoClassList(){
83 return ioClassList;
84 }
85
86 /* (non-Javadoc)
87 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCheck()
88 */
89 public CHECK getCheck() {
90 return this.check;
91 }
92
93 /* (non-Javadoc)
94 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.tcsrdf.TcsRdfImportConfigurator.CHECK)
95 */
96 public void setCheck(CHECK check) {
97 this.check = check;
98 }
99
100 /* (non-Javadoc)
101 * @see eu.etaxonomy.cdm.io.tcsrdf.IExportConfigurator#getDbSchemaValidation()
102 */
103 // public DbSchemaValidation getDbSchemaValidation() {
104 // return dbSchemaValidation;
105 // }
106
107 // /**
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.
110 // * @return
111 // */
112 // public CdmApplicationController getCdmAppController(){
113 // return getCdmAppController(false);
114 // }
115 //
116 // /**
117 // * Returns a new instance of <code>CdmApplicationController</code> created by the values of this configuration.
118 // * @return
119 // */
120 // public CdmApplicationController getNewCdmAppController(){
121 // return getCdmAppController(true, false);
122 // }
123 //
124 // /**
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.
128 // * @return
129 // */
130 // public CdmApplicationController getCdmAppController(boolean createNew){
131 // return getCdmAppController(createNew, false);
132 // }
133 //
134 //
135 // /**
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.
139 // * @return
140 // */
141 // public CdmApplicationController getCdmAppController(boolean createNew, boolean omitTermLoading){
142 // if (cdmApp == null || createNew == true){
143 // try {
144 // cdmApp = CdmApplicationController.NewInstance(this.getSource(), this.getDbSchemaValidation(), omitTermLoading);
145 // } catch (DataSourceNotFoundException e) {
146 // logger.error("could not connect to destination database");
147 // return null;
148 // }catch (TermNotFoundException e) {
149 // logger.error("could not find needed term in destination datasource");
150 // return null;
151 // }
152 // }
153 // return cdmApp;
154 // }
155
156
157 /**
158 * @return
159 */
160 public boolean isValid(){
161 boolean result = true;
162 // if (source == null && this.getCdmAppController() == null ){
163 // logger.warn("Connection to CDM could not be established");
164 // result = false;
165 // }
166 if (destination == null){
167 logger.warn("Invalid export destination");
168 result = false;
169 }
170
171 return result;
172 }
173
174 public String getSourceNameString() {
175 if (this.getSource() == null) {
176 return null;
177 } else {
178 return (String)this.getSource().getName();
179 }
180 }
181
182 }