Commit 7f67e0ef authored by R.W.Majeed's avatar R.W.Majeed

Fixed incorrect loading of configuration

parent 2331262d
package de.sekmi.histream.conf;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
......@@ -23,9 +21,9 @@ public class Configuration {
@XmlElementWrapper(name="plugins", required=true)
protected PluginConfig[] plugins;
@XmlElement(required = true)
protected List<PluginRef> source;
protected PluginRef[] source;
@XmlElement(required = true)
protected List<PluginRef> destination;
protected PluginRef[] destination;
public PluginConfig[] getPlugins(){return plugins;}
......
package de.sekmi.histream.conf;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
......@@ -10,6 +14,8 @@ import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import de.sekmi.histream.Plugin;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "plugin")
......@@ -23,4 +29,24 @@ public class PluginConfig {
@XmlElement
protected PluginProperty[] property;
public Class<?> resolveClass() throws ClassNotFoundException{
return Class.forName(clazz);
}
public String getClazz(){ return clazz; }
@SuppressWarnings("unchecked")
public Plugin newInstance() throws Exception{
Constructor<? extends Plugin> c;
try {
c = (Constructor<? extends Plugin>) resolveClass().getConstructor(Map.class);
} catch (NoSuchMethodException | SecurityException| ClassNotFoundException e) {
throw new Exception("Unable to find constructor",e);
}
HashMap<String, String> props = new HashMap<>();
for( PluginProperty prop : property ){
props.put(prop.name, prop.value);
}
return c.newInstance(props);
}
}
......@@ -10,10 +10,13 @@ import java.util.Properties;
import javax.xml.bind.JAXB;
import de.sekmi.histream.Plugin;
import de.sekmi.histream.conf.Configuration;
import de.sekmi.histream.conf.PluginConfig;
public class HIStream {
......@@ -42,7 +45,14 @@ public class HIStream {
// load configuration
Configuration config = JAXB.unmarshal(new File("src/test/resources/histream.xml"), Configuration.class);
System.out.println("Configuration with "+config.getPlugins().length+" plugins");
for( PluginConfig p : config.getPlugins() ){
try {
Class<?> c = p.resolveClass();
System.out.println("Plugin class loaded: "+c);
} catch (ClassNotFoundException e) {
System.err.println("Plugin class not found: "+p.getClazz());
}
}
// load plugins
hs.shutdown();
......
<histream>
<plugins>
<!-- plugins are loaded in order of occurance -->
<plugin class="de.sekmi.histream.i2b2.I2b2PatientStore">
<plugin class="de.sekmi.histream.i2b2.PostgresPatientStore">
<property name="user">i2b2demodata</property>
</plugin>
<plugin class="de.sekmi.histream.i2b2.I2b2VisitStore">
<plugin class="de.sekmi.histream.i2b2.PostgresVisitStore">
<property name="user">i2b2demodata</property>
</plugin>
<plugin class="de.sekmi.histream.i2b2.services.HiveServer">
<property name="user">i2b2demodata</property>
</plugin>
<plugin class="de.sekmi.histream.impl.SAXObservationProvider">
</plugin>
<plugin class="de.sekmi.histream.i2b2.I2b2Inserter">
<property name="user">i2b2demodata</property>
</plugin>
......@@ -20,10 +22,10 @@
<!-- Wie kann die Konfiguration benutzt werden, wenn z.B. Dateien von der Kommandozeile
gelesen werden sollen und dann das Programm beendet werden soll?
-->
<source plugin-ref="de.sekmi.histream.hl7.MLLPListener" />
<source plugin-ref="de.sekmi.histream.impl.SAXObservationProvider" />
<source plugin="de.sekmi.histream.hl7.MLLPListener" />
<source plugin="de.sekmi.histream.impl.SAXObservationProvider" />
<destination plugin-ref="de.sekmi.histream.i2b2.I2b2Inserter" />
<destination plugin="de.sekmi.histream.i2b2.I2b2Inserter" />
<!-- kann dateien von Kommandozeile lesen -->
<filehandler type="text/xml" plugin-ref="de.sekmi.histream.hl7.MLLPListener">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment