//  Phil Hoke
//
//
/************************************************************************
 * Rule Engine
 *
 *
 * @author   Phil Hoke (C)2001
 ************************************************************************/

package AcademicScheduling.bin;
import java.beans.*;
import jess.*;


public class RuleEngine {

	  static Rete rete = new Rete();
	  public RuleEngine() {
		    System.out.println("Engine Created");
  	  }


  public void parseRules(String ruleFile) throws JessException
  {
    try
        {
          System.out.println("Parse Rulese");

			 rete.executeCommand("(batch " + ruleFile + ")");
			 rete.executeCommand("(reset)");

			}
    catch (JessException re)
        {
         re.printStackTrace();
         System.out.println("Jess Exception ");
        }
  }


  public  void addObject(String ruleObjectString, Object ruleObject) throws JessException
  {
    try
        {

			 Funcall f = new Funcall("definstance", rete);
			 f.add(new Value(ruleObjectString, RU.ATOM));
			 f.add(new Value(ruleObject));
			 f.execute(rete.getGlobalContext());
			}
    catch (JessException re)
        {
         re.printStackTrace();
         System.out.println("Jess Exception ");
        }
  }

  public Rete getRete() {
		return rete;
  }


  public void fireRules() {
    try
        {
         System.out.println("Firing Rules ");
         rete.executeCommand("(reset)");
         rete.executeCommand("(run)");

        }
    catch (JessException re)
        {
         re.printStackTrace();
         System.out.println("Jess Exception ");
        }
  }
}

