001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.projection.proj;
003
004import org.openstreetmap.josm.tools.JosmRuntimeException;
005
006/**
007 * Proj Factory that creates instances from a given class.
008 */
009public class ClassProjFactory implements ProjFactory {
010
011    private final Class<? extends Proj> projClass;
012
013    /**
014     * Constructs a new {@code ClassProjFactory}.
015     * @param projClass projection class
016     */
017    public ClassProjFactory(Class<? extends Proj> projClass) {
018        this.projClass = projClass;
019    }
020
021    @Override
022    public Proj createInstance() {
023        Proj proj = null;
024        try {
025            proj = projClass.getConstructor().newInstance();
026        } catch (ReflectiveOperationException e) {
027            throw new JosmRuntimeException(e);
028        }
029        return proj;
030    }
031}