Provided high-level classes for Export. Adapted Jaxb Export/Import to generic IO...
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / jaxb / JaxbExportConfigurator.java
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.jaxb;
8
9 import org.apache.log4j.Logger;
10
11 import eu.etaxonomy.cdm.database.ICdmDataSource;
12 import eu.etaxonomy.cdm.io.common.ExportConfiguratorBase;
13 import eu.etaxonomy.cdm.io.common.IExportConfigurator;
14 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
15 import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
16 import eu.etaxonomy.cdm.model.reference.Database;
17 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
18
19 /**
20 * @author a.babadshanjan
21 * @created 03.09.2008
22 */
23 public class JaxbExportConfigurator extends ExportConfiguratorBase implements IExportConfigurator {
24
25 private static final Logger logger = Logger.getLogger(JaxbExportConfigurator.class);
26
27 private int maxRows = 0;
28
29 // private boolean doAgents = true;
30 private boolean doAgentData = true;
31 private boolean doLanguageData = true;
32 private boolean doFeatureData = true;
33 private boolean doDescriptions = true;
34 private boolean doMedia = true;
35 // private boolean doOccurrences = true;
36 // private boolean doReferences = true;
37 private boolean doReferencedEntities = true;
38 // private boolean doRelationships = true;
39 private boolean doSynonyms = true;
40 // private boolean doTaxonNames = true;
41 // private boolean doTaxa = true;
42 private boolean doTerms = true;
43 private boolean doTermVocabularies = true;
44 private boolean doHomotypicalGroups = true;
45
46 // private Object source;
47 // private ICdmDataSource cdmDb;
48 // private ICdmDataSource cdmSource;
49 // private ICdmDataSource cdmDestination;
50 // private DbSchemaValidation cdmSourceSchemaValidation = DbSchemaValidation.VALIDATE;
51 // private DbSchemaValidation cdmDestSchemaValidation = DbSchemaValidation.CREATE;
52 // private CdmApplicationController cdmApp = null;
53
54
55 /**
56 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
57 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
58 * been created before a new controller is returned.
59 * @return
60 */
61 // public CdmApplicationController getSourceAppController(ICdmDataSource cdmDb, boolean createNew){
62 // if (cdmApp == null || createNew == true){
63 // try {
64 // cdmApp = CdmApplicationController.NewInstance(this.getCdmSource(), this.getCdmSourceSchemaValidation(), true);
65 // } catch (DataSourceNotFoundException e) {
66 // logger.error("Could not connect to source database");
67 // return null;
68 // }catch (TermNotFoundException e) {
69 // logger.error("Terms not found in source database. " +
70 // "This error should not happen since preloaded terms are not expected for this application.");
71 // return null;
72 // }
73 // }
74 // return cdmApp;
75 // }
76
77 /**
78 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
79 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
80 * been created before a new controller is returned.
81 * @return
82 */
83 // public CdmApplicationController getDestinationAppController(ICdmDataSource cdmDb, boolean createNew){
84 // if (cdmApp == null || createNew == true){
85 // try {
86 // cdmApp = CdmApplicationController.NewInstance(this.getCdmDestination(), this.getCdmDestSchemaValidation(), true);
87 // } catch (DataSourceNotFoundException e) {
88 // logger.error("Could not connect to destination database");
89 // return null;
90 // }catch (TermNotFoundException e) {
91 // logger.error("Terms not found in destination database. " +
92 // "This error should not happen since preloaded terms are not expected for this application.");
93 // return null;
94 // }
95 // }
96 // return cdmApp;
97 // }
98
99 public int getMaxRows() {
100 return maxRows;
101 }
102
103 public void setMaxRows(int maxRows) {
104 this.maxRows = maxRows;
105 }
106
107 // public ICdmDataSource getCdmSource() {
108 // return cdmSource;
109 // }
110 //
111 // public void setCdmSource(ICdmDataSource cdmSource) {
112 // this.cdmSource = cdmSource;
113 // }
114
115 // public ICdmDataSource getCdmDestination() {
116 // return cdmDestination;
117 // }
118 //
119 // public void setCdmDestination(ICdmDataSource cdmDestination) {
120 // this.cdmDestination = cdmDestination;
121 // }
122
123 // public DbSchemaValidation getCdmSourceSchemaValidation() {
124 // return cdmSourceSchemaValidation;
125 // }
126 //
127 // public void setCdmSourceSchemaValidation(DbSchemaValidation cdmSchemaValidation) {
128 // this.cdmSourceSchemaValidation = cdmSchemaValidation;
129 // }
130
131 // public DbSchemaValidation getCdmDestSchemaValidation() {
132 // return cdmDestSchemaValidation;
133 // }
134 //
135 // public void setCdmDestSchemaValidation(DbSchemaValidation cdmSchemaValidation) {
136 // this.cdmDestSchemaValidation = cdmSchemaValidation;
137 // }
138
139 // public boolean isDoAgents() {
140 // return doAgents;
141 // }
142 //
143 // public void setDoAgents(boolean doAgents) {
144 // this.doAgents = doAgents;
145 // }
146
147 public boolean isDoAgentData() {
148 return doAgentData;
149 }
150
151 public void setDoAgentData(boolean doAgentData) {
152 this.doAgentData = doAgentData;
153 }
154
155 public boolean isDoLanguageData() {
156 return doLanguageData;
157 }
158
159 public void setDoLanguageData(boolean doLanguageData) {
160 this.doLanguageData = doLanguageData;
161 }
162
163 public boolean isDoFeatureData() {
164 return doFeatureData;
165 }
166
167 public void setDoFeatureData(boolean doFeatureData) {
168 this.doFeatureData = doFeatureData;
169 }
170
171 public boolean isDoDescriptions() {
172 return doDescriptions;
173 }
174
175 public void setDoDescriptions(boolean doDescriptions) {
176 this.doDescriptions = doDescriptions;
177 }
178
179 public boolean isDoMedia() {
180 return doMedia;
181 }
182
183 public void setDoMedia(boolean doMedia) {
184 this.doMedia = doMedia;
185 }
186
187 // public boolean isDoOccurrences() {
188 // return doOccurrences;
189 // }
190 //
191 // public void setDoOccurrences(boolean doOccurrences) {
192 // this.doOccurrences = doOccurrences;
193 // }
194
195 // public boolean isDoReferences() {
196 // return doReferences;
197 // }
198 //
199 // public void setDoReferences(boolean doReferences) {
200 // this.doReferences = doReferences;
201 // }
202
203 public boolean isDoReferencedEntities() {
204 return doReferencedEntities;
205 }
206
207 public void setDoReferencedEntities(boolean doReferencedEntities) {
208 this.doReferencedEntities = doReferencedEntities;
209 }
210
211 // public boolean isDoRelationships() {
212 // return doRelationships;
213 // }
214 //
215 // public void setDoRelationships(boolean doRelationships) {
216 // this.doRelationships = doRelationships;
217 // }
218
219 public boolean isDoSynonyms() {
220 return doSynonyms;
221 }
222
223 public void setDoSynonyms(boolean doSynonyms) {
224 this.doSynonyms = doSynonyms;
225 }
226
227 // public boolean isDoTaxonNames() {
228 // return doTaxonNames;
229 // }
230 //
231 // public void setDoTaxonNames(boolean doTaxonNames) {
232 // this.doTaxonNames = doTaxonNames;
233 // }
234
235 // public boolean isDoTaxa() {
236 // return doTaxa;
237 // }
238 //
239 // public void setDoTaxa(boolean doTaxa) {
240 // this.doTaxa = doTaxa;
241 // }
242
243 public boolean isDoTerms() {
244 return doTerms;
245 }
246
247 public void setDoTerms(boolean doTerms) {
248 this.doTerms = doTerms;
249 }
250
251 public boolean isDoTermVocabularies() {
252 return doTermVocabularies;
253 }
254
255 public void setDoTermVocabularies(boolean doTermVocabularies) {
256 this.doTermVocabularies = doTermVocabularies;
257 }
258
259 public boolean isDoHomotypicalGroups() {
260 return doHomotypicalGroups;
261 }
262
263 public void setDoHomotypicalGroups(boolean doHomotypicalGroups) {
264 this.doHomotypicalGroups = doHomotypicalGroups;
265 }
266
267
268 // @SuppressWarnings("unchecked")
269 protected void makeIoClassList() {
270 exportClassList = new Class[] {
271 CdmExporter.class,
272 };
273 };
274
275
276 public static JaxbExportConfigurator NewInstance(ICdmDataSource source, String url) {
277 return new JaxbExportConfigurator(source, url);
278 }
279
280
281 /**
282 * @param url
283 * @param destination
284 */
285 private JaxbExportConfigurator(ICdmDataSource source, String url) {
286 super();
287 setDestination(url);
288 setSource(source);
289 }
290
291
292 /* (non-Javadoc)
293 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
294 */
295 public String getDestination() {
296 return (String)super.getDestination();
297 }
298
299
300 /**
301 * @param file
302 */
303 public void setDestination(String fileName) {
304 super.setDestination(fileName);
305 }
306
307
308 /* (non-Javadoc)
309 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getDestinationReference()
310 */
311 // @Override
312 // public ReferenceBase getDestinationReference() {
313 // //TODO
314 // if (this.destinationReference == null){
315 // logger.warn("getDestinationReference() not yet fully implemented");
316 // destinationReference = Database.NewInstance();
317 // destinationReference.setTitleCache("Jaxb export");
318 // }
319 // return destinationReference;
320 // }
321
322
323 /* (non-Javadoc)
324 * @see eu.etaxonomy.cdm.io.common.IExportConfigurator#getDestinationNameString()
325 */
326 public String getDestinationNameString() {
327 if (this.getDestination() == null) {
328 return null;
329 } else {
330 return this.getDestination();
331 }
332 }
333
334 }