java/parameter-lister/src/info/glogalcode/parameterLister/modules/AbstractModuleFactory.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 10 Sep 2016 23:08:58 +0200
changeset 22 91e52083f255
parent 21 7d86d90e6e0e
child 28 bfef9f34e438
permissions -rw-r--r--
java: XML module skeleton
     1 package info.glogalcode.parameterLister.modules;
     2 
     3 import info.glogalcode.parameterLister.OutputModule;
     4 import info.glogalcode.parameterLister.OutputModuleFactory;
     5 import info.glogalcode.parameterLister.OutputModuleFactoryException;
     6 
     7 /**
     8  *
     9  * @author Ing. František Kučera (frantovo.cz)
    10  */
    11 public abstract class AbstractModuleFactory implements OutputModuleFactory {
    12 
    13 	private final Class<? extends OutputModule> clazz;
    14 	private final String name;
    15 
    16 	public AbstractModuleFactory(String name, Class<? extends OutputModule> clazz) {
    17 		this.clazz = clazz;
    18 		this.name = name;
    19 	}
    20 
    21 	@Override
    22 	public String getName() {
    23 		return name;
    24 	}
    25 
    26 	@Override
    27 	public OutputModule createModule() throws OutputModuleFactoryException {
    28 		try {
    29 			return clazz.newInstance();
    30 		} catch (IllegalAccessException | InstantiationException e) {
    31 			throw new OutputModuleFactoryException("Error while creating instance of class " + clazz + " for module " + name, e);
    32 		}
    33 	}
    34 
    35 }