package wenrgise.common.utility;

import com.tcs.wenrgise.util.common.FWXMLUtility;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import wenrgise.common.xml.vo.EnrgiseApp;
import wenrgise.common.xml.vo.EnrgiseForms;
import wenrgise.common.xml.vo.INFOClass;
import wenrgise.common.xml.vo.LOVClass;
import wenrgise.workflow.utility.WflDocParamsManager;
import wenrgise.workflow.xml.vo.WflDocParams;

public class EnrgisePlugIn implements PlugIn {
  static final Logger log = Logger.getLogger("wenrgise.common.utility.EnrgisePlugIn");
  
  private String formPathName = "/WEB-INF/EnrgiseConfig.xml";
  
  private String pathName = "/WEB-INF/EnrgiseLOV.xml";
  
  private String appPath = "/WEB-INF/EnrgiseApp.xml";
  
  private String reportPathName = "/WEB-INF/EnrgiseReport.xml";
  
  private String wflImplPathName = "/WEB-INF/WflDocParameters.xml";
  
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
    try {
      EnrgiseForms oEnrgiseForms = (EnrgiseForms)FWXMLUtility.xmlToObject("wenrgise.common.xml.vo.EnrgiseForms", calculatePath(servlet, this.formPathName));
      EnrgiseManager.getInstance().init(oEnrgiseForms);
      LOVClass oLOVClass = (LOVClass)FWXMLUtility.xmlToObject("wenrgise.common.xml.vo.LOVClass", calculatePath(servlet, this.pathName));
      LOVManager.getInstance().init(oLOVClass);
      EnrgiseApp oEnrgiseApp = (EnrgiseApp)FWXMLUtility.xmlToObject("wenrgise.common.xml.vo.EnrgiseApp", calculatePath(servlet, this.appPath));
      EnrgiseManager.getInstance().setEnrApp(oEnrgiseApp);
      WflDocParams oWflDocParams = (WflDocParams)FWXMLUtility.xmlToObject("wenrgise.workflow.xml.vo.WflDocParams", calculatePath(servlet, this.wflImplPathName));
      WflDocParamsManager.getInstance().init(oWflDocParams);
      INFOClass oINFOClass = (INFOClass)FWXMLUtility.xmlToObject("wenrgise.common.xml.vo.INFOClass", calculatePath(servlet, this.reportPathName));
      StringBuffer woStringBuffer = new StringBuffer();
      woStringBuffer.append(" rwserver server=peerless");
    } catch (Exception oEx) {
      log.severe(oEx.getMessage());
    } 
  }
  
  public void destroy() {}
  
  private String calculatePath(ActionServlet servlet, String sPath) {
    return servlet.getServletContext().getRealPath(sPath);
  }
  
  public String getFormPathName() {
    return this.formPathName;
  }
  
  public void setFormPathName(String newFormPathName) {
    this.formPathName = newFormPathName;
  }
}
