Commit 0a4e02e7 authored by R.W.M.'s avatar R.W.M.
Browse files

documentation

parent d806960d
......@@ -20,29 +20,28 @@ package de.sekmi.histream;
* #L%
*/
import java.io.Closeable;
import java.io.IOException;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Properties;
/**
*
* <p>
* A Plugin should implement a constructor accepting a single
* {@link Properties} object for configuration. The {@link Closeable#close()}
* method is called when the plugin is unloaded or during normal termination.
*
* @author Raphael
*
*/
public interface Plugin extends Closeable{
@Override
import java.util.Map;
/**
*
* <p>
* A Plugin should implement a constructor accepting a single
* {@link Map} object for configuration. The {@link Closeable#close()}
* method is called when the plugin is unloaded or during normal termination.
*
* @author Raphael
*
*/
public interface Plugin extends Closeable{
@Override
default void close()throws IOException{}
@SuppressWarnings("unchecked")
......@@ -53,5 +52,5 @@ public interface Plugin extends Closeable{
return c.newInstance(configuration);
}
}
}
}
......@@ -20,88 +20,94 @@ package de.sekmi.histream.conf;
* #L%
*/
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.logging.Logger;
import javax.xml.bind.JAXB;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import de.sekmi.histream.Plugin;
/**
* Configuration for HIStream processing. Uses javax.xml.bind for loading XML files
* via
* @author Raphael
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "http://some/namespace",
name = "histream", propOrder = {
"plugins",
"source",
"destination"
})
public class Configuration {
private static final Logger log = Logger.getLogger(Configuration.class.getName());
@XmlElement(name="plugin")
@XmlElementWrapper(name="plugins", required=true)
protected PluginConfig[] plugins;
@XmlElement(required = true)
protected PluginRef[] source;
@XmlElement(required = true)
protected PluginRef[] destination;
public PluginConfig[] getPlugins(){return plugins;}
public PluginRef[] getDestinations(){return destination;}
public PluginRef[] getSources(){return source;}
public static final Configuration fromFile(File file){
return JAXB.unmarshal(file, Configuration.class);
}
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.logging.Logger;
import javax.xml.bind.JAXB;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import de.sekmi.histream.Plugin;
/**
* Configuration for HIStream processing. Uses javax.xml.bind for loading XML files.
*
* @author Raphael
*
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "http://some/namespace",
name = "histream", propOrder = {
"plugins",
"source",
"destination"
})
public class Configuration {
private static final Logger log = Logger.getLogger(Configuration.class.getName());
@XmlElement(name="plugin")
@XmlElementWrapper(name="plugins", required=true)
protected PluginConfig[] plugins;
@XmlElement(required = true)
protected PluginRef[] source;
@XmlElement(required = true)
protected PluginRef[] destination;
public PluginConfig[] getPlugins(){return plugins;}
public PluginRef[] getDestinations(){return destination;}
public PluginRef[] getSources(){return source;}
/**
* Instantiates each plugin listed order (as specified in configuration).
* Instantiation is performed by looking up a constructor which accepts a single
* argument of type {@link Map} and calling that constructor with the properties
* specified for the plugin.
* <p>
* If an exception is thrown by the constructor if any plugin, the previously instantiated
* plugins are closed in reverse order. Any exceptions thrown by the close methods are suppressed
* by the constructor exception (via {@link Exception#addSuppressed(Throwable)}).
* @return plugin instances
* @throws Exception exception thrown by any plugin during construction
*/
public Plugin[] createPluginInstances() throws Exception{
Plugin[] insts = new Plugin[plugins.length];
for( int i=0; i<plugins.length; i++ ){
try{
insts[i] = plugins[i].newInstance();
log.info("Plugin instance created: "+insts[i]);
}catch( Exception e ){
// close previously instantiated plugins in reverse order
for( int j=i-1; j>=0; j-- ){
try{
insts[j].close();
}catch( IOException f ){
e.addSuppressed(f);
}
}
throw e;
}
}
return insts;
}
}
* Load configuration from XML file.
*
* @param file XML file containing the configuration
* @return configuration contained in the specified file
*/
public static final Configuration fromFile(File file){
return JAXB.unmarshal(file, Configuration.class);
}
/**
* Instantiates each plugin listed order (as specified in configuration).
* Instantiation is performed by looking up a constructor which accepts a single
* argument of type {@link Map} and calling that constructor with the properties
* specified for the plugin.
* <p>
* If an exception is thrown by the constructor if any plugin, the previously instantiated
* plugins are closed in reverse order. Any exceptions thrown by the close methods are suppressed
* by the constructor exception (via {@link Exception#addSuppressed(Throwable)}).
* @return plugin instances
* @throws Exception exception thrown by any plugin during construction
*/
public Plugin[] createPluginInstances() throws Exception{
Plugin[] insts = new Plugin[plugins.length];
for( int i=0; i<plugins.length; i++ ){
try{
insts[i] = plugins[i].newInstance();
log.info("Plugin instance created: "+insts[i]);
}catch( Exception e ){
// close previously instantiated plugins in reverse order
for( int j=i-1; j>=0; j-- ){
try{
insts[j].close();
}catch( IOException f ){
e.addSuppressed(f);
}
}
throw e;
}
}
return insts;
}
}
package de.sekmi.histream.ontology;
public class OntologyException extends Exception{
/**
*
*/
private static final long serialVersionUID = 1L;
public OntologyException(Throwable cause){
super(cause);
}
public OntologyException(String message){
super(message);
}
}
package de.sekmi.histream.ontology;
/**
* Ontology exception
*
* @author Raphael
*
*/
public class OntologyException extends Exception{
/**
*
*/
private static final long serialVersionUID = 1L;
public OntologyException(Throwable cause){
super(cause);
}
public OntologyException(String message){
super(message);
}
}
Supports Markdown
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