package turgen.plugin;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;


/** Container that manages available plugins*/
public class PluginManager {


    private HashMap classPluginMap;

    /** Create new PluginManager using Vector of plugins
     *
     * @param v Vector of plugins to be managed
     */
    public PluginManager(Vector v) {
        createClassPluginMap(v);

    }

    private void createClassPluginMap(Vector v) {

        classPluginMap = new HashMap();
        Iterator it = v.iterator();

        while(it.hasNext()==true) {
            Plugin pgn = (Plugin)it.next();
            classPluginMap.put(pgn.getClass().getName(), pgn);
        }
    }

    public Plugin getPlugin(String className) {

        Plugin pgn = (Plugin)classPluginMap.get(className);
        return pgn;
    }

    public String getPluginClassName(Plugin pgn) {
        return pgn.getClass().getName();
    }

    public Plugin[] getPlugins() {

        Set s = classPluginMap.keySet();
        int l = classPluginMap.size();

        Iterator it = s.iterator();

        Plugin[] plugins = new Plugin[l];

        int i=0;
        while(it.hasNext()) {
            plugins[i]=(Plugin)classPluginMap.get(it.next());
            i++;
        }

        return plugins;


    }


}
