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