2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.common
;
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
;
18 import org
.apache
.log4j
.Logger
;
20 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
21 import eu
.etaxonomy
.cdm
.io
.jaxb
.JaxbImportConfigurator
;
22 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
23 import eu
.etaxonomy
.cdm
.io
.tcsxml
.in
.TcsXmlImportConfigurator
;
30 public class ImportWrapper
{
31 private static final Logger logger
= Logger
.getLogger(ImportWrapper
.class);
35 private Class
<?
extends ICdmImporter
> importClass
= CdmApplicationAwareDefaultImport
.class;
37 private IImportConfigurator configuration
;
39 public static List
<ImportWrapper
> list(){
40 logger
.debug("Create ImportWrapper list");
41 List
<ImportWrapper
> result
= new ArrayList
<ImportWrapper
>();
43 ImportWrapper wrapper
= Abcd206WrapperInstance();
45 wrapper
= TcsXml101WrapperInstance();
47 wrapper
= Jaxb10WrapperInstance();
52 public static ImportWrapper
Abcd206WrapperInstance(){
53 String label
= "ABCD 2.06";
54 Class
<?
extends ICdmImporter
> clazz
= CdmApplicationAwareDefaultImport
.class;
55 IImportConfigurator config
= Abcd206ImportConfigurator
.NewInstance(null, null);
56 ImportWrapper wrapper
= new ImportWrapper();
57 wrapper
.setLabel(label
);
58 wrapper
.setImportClass(clazz
);
59 wrapper
.setConfiguration(config
);
64 public static ImportWrapper
TcsXml101WrapperInstance(){
65 String label
= "TcsXML 1.1";
66 Class
<?
extends ICdmImporter
> clazz
= CdmApplicationAwareDefaultImport
.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
);
76 public static ImportWrapper
Jaxb10WrapperInstance(){
77 String label
= "CDM 1.0 XML";
78 Class
<?
extends ICdmImporter
> clazz
= CdmApplicationAwareDefaultImport
.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
);
94 public boolean invoke(Object source
, ICdmDataSource destination
, UUID secUUID
){
96 Method methodInvoke
= importClass
.getDeclaredMethod("invoke", IImportConfigurator
.class);
97 Method methodSetSource
= configuration
.getClass().getMethod("setSource", String
.class);
98 methodSetSource
.setAccessible(true);
100 this.configuration
.setDestination(destination
);
101 methodSetSource
.invoke(configuration
, source
);
103 if (this.importClass
== null){
106 return (Boolean
)methodInvoke
.invoke(importClass
.newInstance(), configuration
);
108 } catch (SecurityException e
) {
110 } catch (IllegalArgumentException e
) {
112 } catch (NoSuchMethodException e
) {
114 } catch (IllegalAccessException e
) {
116 } catch (InvocationTargetException e
) {
118 } catch (InstantiationException e
) {
127 // *************** GETTER / SETTER *******************************************/
130 * @return the configuration
132 public IImportConfigurator
getConfiguration() {
133 return configuration
;
137 * @param configuration the configuration to set
139 public void setConfiguration(IImportConfigurator configuration
) {
140 this.configuration
= configuration
;
146 public String
getLabel() {
151 * @param label the label to set
153 public void setLabel(String label
) {
158 * @return the ioClazz
160 public Class
<?
extends ICdmImporter
> getImportClass() {
165 * @param ioClazz the ioClazz to set
167 public void setImportClass(Class
<?
extends ICdmImporter
> importClass
) {
168 this.importClass
= importClass
;
171 //******* TEST **************************************//
175 public static void main(String
[] args
) {
176 ImportWrapper
.list().get(1).invoke("", null, UUID
.randomUUID());