/*
* @CalculatorAction.java 1.2 May 19, 2006
*
* Copyright (c) 2006 FirstPartner
* All rights reserved.
*
*/
package net.fp.rp.drools.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.fp.rp.drools.Constants;
import net.fp.rp.drools.ContextListener;
import net.fp.rp.drools.SpringDecisionTableLoader;
import net.fp.rp.drools.form.CalculatorFormBean;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.drools.RuleBase;
import org.drools.StatelessSession;
/**
* Setting Default Value for the CalculatorBean
* @version 1.3 May 19, 2006
* Copyright @link www.firstpartners.net/red
*/
public class CalculatorAction extends Action {
private RuleBase rb = null;
private StatelessSession wm = null;
// set the drools from static variable
public void setRuleBase() {
try {
if (ContextListener.excelRules != null) {
rb = ContextListener.excelRules;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
*
* initWorkingMemory
*
*/
public void initWorkingMemory() {
try {
if (wm == null) {
wm = rb.newStatelessSession();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
*
*/
public ActionForward execute(ActionMapping mapping,
ActionForm calcForm,
HttpServletRequest request,
HttpServletResponse response) {
try {
// setRuleBase();
// initWorkingMemory();
CalculatorFormBean cfb = (CalculatorFormBean) calcForm;
// set default value
cfb.setRateType(Constants.STANDARDVARIABLEVAL);
cfb.setRateTypeValue(3.95);
// init Drools Load Configuration
//todo - this will fail for the momemnt , probably with a null pointer error
SpringDecisionTableLoader dtLoader = new SpringDecisionTableLoader();
//DroolsLoadConf.workingMemory = wm;
///DroolsLoadConf.excelRules = rb;
return mapping.findForward("success");
}
catch (Exception e) {
e.printStackTrace();
return mapping.findForward("error");
}
}
}