Project

General

Profile

Download (2.45 KB) Statistics
| Branch: | Tag: | Revision:
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.api.application.CdmApplicationController;
12
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
13
import eu.etaxonomy.cdm.database.DbSchemaValidation;
14
import eu.etaxonomy.cdm.database.ICdmDataSource;
15

    
16
/**
17
 * This is an exporter that invokes the application aware defaultExport when
18
 * invoked itself
19
 * 
20
 * @author a.babadshanjan
21
 * @created 17.11.2008
22
 */
23
public class CdmDefaultIOBase<T extends IIoConfigurator> {
24
	@SuppressWarnings("unused")
25
	private static final Logger logger = Logger
26
			.getLogger(CdmDefaultIOBase.class);
27

    
28
	protected ICdmApplicationConfiguration cdmApp = null;
29

    
30
	/**
31
	 * Creates a new {@link CdmApplicationController} if it does not exist yet
32
	 * or if createNew is <ocde>true</code>
33
	 * 
34
	 * @param config
35
	 * @param destination
36
	 * @param omitTermLoading
37
	 * @param createNew
38
	 * @return
39
	 */
40
	protected boolean startApplicationController(IIoConfigurator config,
41
			ICdmDataSource cdmSource, boolean omitTermLoading, boolean createNew) {
42
		if (config.getCdmAppController() != null) {
43
			this.cdmApp = config.getCdmAppController();
44
		}
45
		DbSchemaValidation schemaValidation = config.getDbSchemaValidation();
46
		if (this instanceof CdmDefaultExport) {
47
			if (schemaValidation.equals(DbSchemaValidation.CREATE)
48
					|| schemaValidation.equals(DbSchemaValidation.CREATE_DROP)) {
49
				throw new IllegalArgumentException(
50
						"The export may not run with DbSchemaValidation.CREATE or DbSchemaValidation.CREATE_DROP as this value deletes the source database");
51
			}
52
		}
53

    
54
		if (createNew == true || cdmApp == null) {
55
			cdmApp = CdmApplicationController.NewInstance(cdmSource,
56
					schemaValidation, omitTermLoading);
57
			if (cdmApp != null) {
58
				return true;
59
			} else {
60
				return false;
61
			}
62
		}
63
		return true;
64

    
65
	}
66

    
67
	/**
68
	 * Returns the {@link CdmApplicationController}. This is null if invoke()
69
	 * has not been called yet and if the controller has not been set manually
70
	 * by setCdmApp() yet.
71
	 * 
72
	 * @return the cdmApp
73
	 */
74
	public ICdmApplicationConfiguration getCdmAppController() {
75
		return this.cdmApp;
76
	}
77

    
78
	/**
79
	 * @param cdmApp
80
	 *            the cdmApp to set
81
	 */
82
	public void setCdmAppController(ICdmApplicationConfiguration cdmApp) {
83
		this.cdmApp = cdmApp;
84
	}
85

    
86
}
(6-6/48)