java/parameter-lister/src/info/glogalcode/parameterLister/modules/AbstractModuleFactory.java
changeset 21 7d86d90e6e0e
child 28 bfef9f34e438
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/parameter-lister/src/info/glogalcode/parameterLister/modules/AbstractModuleFactory.java	Sat Sep 10 23:03:43 2016 +0200
     1.3 @@ -0,0 +1,35 @@
     1.4 +package info.glogalcode.parameterLister.modules;
     1.5 +
     1.6 +import info.glogalcode.parameterLister.OutputModule;
     1.7 +import info.glogalcode.parameterLister.OutputModuleFactory;
     1.8 +import info.glogalcode.parameterLister.OutputModuleFactoryException;
     1.9 +
    1.10 +/**
    1.11 + *
    1.12 + * @author Ing. František Kučera (frantovo.cz)
    1.13 + */
    1.14 +public abstract class AbstractModuleFactory implements OutputModuleFactory {
    1.15 +
    1.16 +	private final Class<? extends OutputModule> clazz;
    1.17 +	private final String name;
    1.18 +
    1.19 +	public AbstractModuleFactory(String name, Class<? extends OutputModule> clazz) {
    1.20 +		this.clazz = clazz;
    1.21 +		this.name = name;
    1.22 +	}
    1.23 +
    1.24 +	@Override
    1.25 +	public String getName() {
    1.26 +		return name;
    1.27 +	}
    1.28 +
    1.29 +	@Override
    1.30 +	public OutputModule createModule() throws OutputModuleFactoryException {
    1.31 +		try {
    1.32 +			return clazz.newInstance();
    1.33 +		} catch (IllegalAccessException | InstantiationException e) {
    1.34 +			throw new OutputModuleFactoryException("Error while creating instance of class " + clazz + " for module " + name, e);
    1.35 +		}
    1.36 +	}
    1.37 +
    1.38 +}