package JSSPF;

/**
 * Encapsulates a dynamic class we have available in the extensions directory,
 * and provides a method to get an instance of the class.
 */
public class PluginClassDef
{
    /**
     * The name that the dynamic class represented by this class identifies itself with.
     */
    public String className;

    /**
     * The name of the category that the dynamic class represented by this class belongs to.
     */
    public String classType;

    /**
     * This is the class definition that this placeholder actually represents.
     */
    private Class classClass;

    /**
     * Constructs a placeholder for a dynamic class. This should only be used
     * in the dynamic class manager.
     * @param name The name of the class we have found.
     * @param type The type of the class we have found.
     * @param clasS The class object representing the class we have found.
     */
    protected PluginClassDef(String name, String type, Class clasS)
    {
        className = name;
        classType = type;
        classClass = clasS;
    }

    /**
     * Creates an instance of a dynamic class we have in the catalogue. This
     * can be called by anyone.
     * @return A PluginClassBase representation of the PluginClassBase subclass
     * represented by this placeholder.
     */
    public PluginClassBase getInstance()
    {
        try
        {
            return (PluginClassBase) classClass.newInstance();
        }
        catch (Exception e) {}

        return null;
    }
}
