package src.fr.impl;

import java.lang.reflect.Constructor;
import java.util.logging.Level;
import java.util.logging.Logger;

import src.fr.api.Category;
import src.fr.api.PartType;

public class PartTypeImpl implements PartType {
    private String name;
    private Category category;
    private Class<? extends PartImpl> classRef;

    public PartTypeImpl(String name,Class<? extends PartImpl> classref, Category category ) {
        this.name = name;
        this.classRef= classref;
        this.category = category;
    }

    public PartImpl newInstance(){
        Constructor<? extends PartImpl> constructor;
        try{
            constructor = classRef.getConstructor();
            return constructor.newInstance();
        } catch(Exception e){
            Logger.getGlobal().log(Level.SEVERE, "constructor call failed",e);
            System.exit(-1);
        }
        return null;
    }

    public String getName(){
        return this.name;
    }

    public Category getCategory(){
        return this.category;
    }
}
