import model.RGBColor;
import java.lang.reflect.*;
import java.util.ResourceBundle;


/**
 * Example of using reflection and resources.
 * 
 * @author Robert Duvall (rcd@cs.duke.edu)
 */
public class MainReflection
{
	static RGBColor callMethod (String classname, String methodname)
	{
		try
		{
	    	Class<?> op = Class.forName(classname);
	    	Method m = op.getMethod(methodname, RGBColor.class, RGBColor.class);
			return (RGBColor)m.invoke(null, tests.ParserTest.BLACK, tests.ParserTest.WHITE);
		}
		catch (Exception e)
		{
			// fatal error, problem with resource file
			e.printStackTrace();
			System.exit(1);
			// make compiler happy :)
			return null;
		}
	}

	public static void main (String[] args)
    {
        final RGBColor BLACK = new RGBColor(-1);
        final RGBColor WHITE = new RGBColor(1);

    	ResourceBundle resources = ResourceBundle.getBundle("ops");

		for (String key : resources.keySet())
		{
			String value = resources.getString(key);
			int index = value.lastIndexOf(".");
			RGBColor result = callMethod(value.substring(0, index), value.substring(index + 1));
			System.out.println(BLACK + " " + key + " " + WHITE + " = " + result);
		}
	}
}
