1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.io.common;
|
11
|
|
12
|
import java.lang.reflect.InvocationTargetException;
|
13
|
import java.lang.reflect.Method;
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.List;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
|
20
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
21
|
import eu.etaxonomy.cdm.io.abcd206.SpecimenImportConfigurator;
|
22
|
import eu.etaxonomy.cdm.io.jaxb.JaxbImportConfigurator;
|
23
|
import eu.etaxonomy.cdm.io.tcsxml.TcsXmlImportConfigurator;
|
24
|
|
25
|
/**
|
26
|
* @author a.mueller
|
27
|
* @created 12.11.2008
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class ImportWrapper {
|
31
|
private static final Logger logger = Logger.getLogger(ImportWrapper.class);
|
32
|
|
33
|
private String label;
|
34
|
|
35
|
private Class<? extends ICdmImport> importClass = CdmDefaultImport.class;
|
36
|
|
37
|
private IImportConfigurator configuration;
|
38
|
|
39
|
public static List<ImportWrapper> list(){
|
40
|
logger.debug("Create ImportWrapper list");
|
41
|
List<ImportWrapper> result = new ArrayList<ImportWrapper>();
|
42
|
//abcd
|
43
|
ImportWrapper wrapper = Abcd206WrapperInstance();
|
44
|
result.add(wrapper);
|
45
|
wrapper = TcsXml101WrapperInstance();
|
46
|
result.add(wrapper);
|
47
|
wrapper = Jaxb10WrapperInstance();
|
48
|
result.add(wrapper);
|
49
|
return result;
|
50
|
}
|
51
|
|
52
|
public static ImportWrapper Abcd206WrapperInstance(){
|
53
|
String label = "ABCD 2.06";
|
54
|
Class<? extends ICdmImport> clazz = CdmDefaultImport.class;
|
55
|
IImportConfigurator config = SpecimenImportConfigurator.NewInstance(null, null);
|
56
|
ImportWrapper wrapper = new ImportWrapper();
|
57
|
wrapper.setLabel(label);
|
58
|
wrapper.setImportClass(clazz);
|
59
|
wrapper.setConfiguration(config);
|
60
|
return wrapper;
|
61
|
}
|
62
|
|
63
|
|
64
|
public static ImportWrapper TcsXml101WrapperInstance(){
|
65
|
String label = "TcsXML 1.1";
|
66
|
Class<? extends ICdmImport> clazz = CdmDefaultImport.class;
|
67
|
IImportConfigurator config = TcsXmlImportConfigurator.NewInstance(null, null);
|
68
|
ImportWrapper wrapper = new ImportWrapper();
|
69
|
wrapper.setLabel(label);
|
70
|
wrapper.setImportClass(clazz);
|
71
|
wrapper.setConfiguration(config);
|
72
|
return wrapper;
|
73
|
}
|
74
|
|
75
|
|
76
|
public static ImportWrapper Jaxb10WrapperInstance(){
|
77
|
String label = "CDM 1.0 XML";
|
78
|
Class<? extends ICdmImport> clazz = CdmDefaultImport.class;
|
79
|
IImportConfigurator config = JaxbImportConfigurator.NewInstance(null, null);
|
80
|
ImportWrapper wrapper = new ImportWrapper();
|
81
|
wrapper.setLabel(label);
|
82
|
wrapper.setImportClass(clazz);
|
83
|
wrapper.setConfiguration(config);
|
84
|
return wrapper;
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
*
|
89
|
* @param source
|
90
|
* @param destination
|
91
|
* @param secUUID
|
92
|
* @return
|
93
|
*/
|
94
|
public boolean invoke(Object source, ICdmDataSource destination, UUID secUUID){
|
95
|
try {
|
96
|
Method methodInvoke = importClass.getDeclaredMethod("invoke", IImportConfigurator.class);
|
97
|
Method methodSetSource = configuration.getClass().getMethod("setSource", String.class);
|
98
|
methodSetSource.setAccessible(true);
|
99
|
|
100
|
this.configuration.setDestination(destination);
|
101
|
methodSetSource.invoke(configuration, source);
|
102
|
|
103
|
if (this.importClass == null){
|
104
|
return false;
|
105
|
}else{
|
106
|
return (Boolean)methodInvoke.invoke(importClass.newInstance(), configuration);
|
107
|
}
|
108
|
} catch (SecurityException e) {
|
109
|
e.printStackTrace();
|
110
|
} catch (IllegalArgumentException e) {
|
111
|
e.printStackTrace();
|
112
|
} catch (NoSuchMethodException e) {
|
113
|
e.printStackTrace();
|
114
|
} catch (IllegalAccessException e) {
|
115
|
e.printStackTrace();
|
116
|
} catch (InvocationTargetException e) {
|
117
|
e.printStackTrace();
|
118
|
} catch (InstantiationException e) {
|
119
|
e.printStackTrace();
|
120
|
}
|
121
|
return false;
|
122
|
}
|
123
|
|
124
|
|
125
|
|
126
|
|
127
|
// *************** GETTER / SETTER *******************************************/
|
128
|
|
129
|
/**
|
130
|
* @return the configuration
|
131
|
*/
|
132
|
public IImportConfigurator getConfiguration() {
|
133
|
return configuration;
|
134
|
}
|
135
|
|
136
|
/**
|
137
|
* @param configuration the configuration to set
|
138
|
*/
|
139
|
public void setConfiguration(IImportConfigurator configuration) {
|
140
|
this.configuration = configuration;
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
* @return the label
|
145
|
*/
|
146
|
public String getLabel() {
|
147
|
return label;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* @param label the label to set
|
152
|
*/
|
153
|
public void setLabel(String label) {
|
154
|
this.label = label;
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* @return the ioClazz
|
159
|
*/
|
160
|
public Class<? extends ICdmImport> getImportClass() {
|
161
|
return importClass;
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* @param ioClazz the ioClazz to set
|
166
|
*/
|
167
|
public void setImportClass(Class<? extends ICdmImport> importClass) {
|
168
|
this.importClass = importClass;
|
169
|
}
|
170
|
|
171
|
//******* TEST **************************************//
|
172
|
/**
|
173
|
* @param args
|
174
|
*/
|
175
|
public static void main(String[] args) {
|
176
|
ImportWrapper.list().get(1).invoke("", null, UUID.randomUUID());
|
177
|
}
|
178
|
|
179
|
}
|