java/parameter-lister/src/info/glogalcode/parameterLister/modules/AbstractModuleFactory.java
author František Kučera <franta-hg@frantovo.cz>
Sun, 11 Sep 2016 19:52:26 +0200
changeset 28 bfef9f34e438
parent 21 7d86d90e6e0e
permissions -rw-r--r--
license: GNU GPL v3
franta-hg@28
     1
/**
franta-hg@28
     2
 * parameter-lister
franta-hg@28
     3
 * Copyright © 2015 František Kučera (frantovo.cz)
franta-hg@28
     4
 *
franta-hg@28
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@28
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@28
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@28
     8
 * (at your option) any later version.
franta-hg@28
     9
 *
franta-hg@28
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@28
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@28
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@28
    13
 * GNU General Public License for more details.
franta-hg@28
    14
 *
franta-hg@28
    15
 * You should have received a copy of the GNU General Public License
franta-hg@28
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@28
    17
 */
franta-hg@21
    18
package info.glogalcode.parameterLister.modules;
franta-hg@21
    19
franta-hg@21
    20
import info.glogalcode.parameterLister.OutputModule;
franta-hg@21
    21
import info.glogalcode.parameterLister.OutputModuleFactory;
franta-hg@21
    22
import info.glogalcode.parameterLister.OutputModuleFactoryException;
franta-hg@21
    23
franta-hg@21
    24
/**
franta-hg@21
    25
 *
franta-hg@21
    26
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@21
    27
 */
franta-hg@21
    28
public abstract class AbstractModuleFactory implements OutputModuleFactory {
franta-hg@21
    29
franta-hg@21
    30
	private final Class<? extends OutputModule> clazz;
franta-hg@21
    31
	private final String name;
franta-hg@21
    32
franta-hg@21
    33
	public AbstractModuleFactory(String name, Class<? extends OutputModule> clazz) {
franta-hg@21
    34
		this.clazz = clazz;
franta-hg@21
    35
		this.name = name;
franta-hg@21
    36
	}
franta-hg@21
    37
franta-hg@21
    38
	@Override
franta-hg@21
    39
	public String getName() {
franta-hg@21
    40
		return name;
franta-hg@21
    41
	}
franta-hg@21
    42
franta-hg@21
    43
	@Override
franta-hg@21
    44
	public OutputModule createModule() throws OutputModuleFactoryException {
franta-hg@21
    45
		try {
franta-hg@21
    46
			return clazz.newInstance();
franta-hg@21
    47
		} catch (IllegalAccessException | InstantiationException e) {
franta-hg@21
    48
			throw new OutputModuleFactoryException("Error while creating instance of class " + clazz + " for module " + name, e);
franta-hg@21
    49
		}
franta-hg@21
    50
	}
franta-hg@21
    51
franta-hg@21
    52
}