reverting back the cdm application configuration refatoring
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / common / ExportConfiguratorBase.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.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.ICdmDataSource;
14 import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
15 import eu.etaxonomy.cdm.model.reference.IDatabase;
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, STATE extends ExportStateBase, TRANSFORM extends IExportTransformer> extends IoConfiguratorBase implements IExportConfigurator<STATE, TRANSFORM>{
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 * The transformer class to be used for Input
35 */
36 private TRANSFORM transformer;
37
38 public ExportConfiguratorBase(TRANSFORM transformer){
39 super();
40 //setDbSchemaValidation(DbSchemaValidation.UPDATE);
41 makeIoClassList();
42 this.setTransformer(transformer);
43 }
44
45 abstract protected void makeIoClassList();
46
47
48 @Override
49 public TRANSFORM getTransformer() {
50 return transformer;
51 }
52
53 @Override
54 public void setTransformer(TRANSFORM transformer) {
55 this.transformer = transformer;
56 }
57
58
59 @Override
60 public ICdmDataSource getSource() {
61 return source;
62 }
63
64 @Override
65 public void setSource(ICdmDataSource source) {
66 this.source = source;
67 }
68
69 /**
70 * @param source the source to get
71 */
72 public DESTINATION getDestination() {
73 return destination;
74 }
75
76 /**
77 * @param source the source to set
78 */
79 public void setDestination(DESTINATION destination) {
80 this.destination = destination;
81 }
82
83
84
85 /* (non-Javadoc)
86 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
87 */
88 // @Override
89 public IDatabase getSourceReference() {
90 //TODO //needed
91 if (this.sourceReference == null){
92 sourceReference = ReferenceFactory.newDatabase();
93 if (getSource() != null){
94 sourceReference.setTitleCache(getSource().getDatabase(), true);
95 }
96 }
97 return sourceReference;
98 }
99
100 @Override
101 public Class<ICdmIO>[] getIoClassList(){
102 return ioClassList;
103 }
104
105 /* (non-Javadoc)
106 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#getCheck()
107 */
108 @Override
109 public CHECK getCheck() {
110 return this.check;
111 }
112
113 /* (non-Javadoc)
114 * @see eu.etaxonomy.cdm.io.tcsrdf.IImportConfigurator#setCheck(eu.etaxonomy.cdm.io.tcsrdf.TcsRdfImportConfigurator.CHECK)
115 */
116 public void setCheck(CHECK check) {
117 this.check = check;
118 }
119
120 /* (non-Javadoc)
121 * @see eu.etaxonomy.cdm.io.tcsrdf.IExportConfigurator#getDbSchemaValidation()
122 */
123 // public DbSchemaValidation getDbSchemaValidation() {
124 // return dbSchemaValidation;
125 // }
126
127 // /**
128 // * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
129 // * If a controller was already created before the last created controller is returned.
130 // * @return
131 // */
132 // public CdmApplicationController getCdmAppController(){
133 // return getCdmAppController(false);
134 // }
135
136 /**
137 * Returns a new instance of <code>CdmApplicationController</code> created by the values of this configuration.
138 * @return
139 */
140 public ICdmApplicationConfiguration getNewCdmAppController(){
141 return getCdmAppController(true, false);
142 }
143
144 /**
145 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
146 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
147 * been created before a new controller is returned.
148 * @return
149 */
150 public ICdmApplicationConfiguration getCdmAppController(boolean createNew){
151 return getCdmAppController(createNew, false);
152 }
153
154
155 /**
156 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
157 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
158 * been created before a new controller is returned.
159 * @return
160 */
161 public ICdmApplicationConfiguration getCdmAppController(boolean createNew, boolean omitTermLoading){
162 if (cdmApp == null || createNew == true){
163 cdmApp = CdmApplicationController.NewInstance(this.getSource(), this.getDbSchemaValidation(), omitTermLoading);
164 }
165 return cdmApp;
166 }
167
168
169 /**
170 * @return
171 */
172 @Override
173 public boolean isValid(){
174 boolean result = true;
175 // if (source == null && this.getCdmAppController() == null ){
176 // logger.warn("Connection to CDM could not be established");
177 // result = false;
178 // }
179 if (destination == null){
180 logger.warn("Invalid export destination");
181 result = false;
182 }
183
184 return result;
185 }
186
187 @Override
188 public String getSourceNameString() {
189 if (this.getSource() == null) {
190 return null;
191 } else {
192 return this.getSource().getName();
193 }
194 }
195
196 }