package WEB-INF.classes.wenrgise.ejb.common.utility;

import java.util.ArrayList;
import wenrgise.common.xml.vo.DetailScreen;
import wenrgise.common.xml.vo.DetailScreens;
import wenrgise.common.xml.vo.HashedEnrgiseForms;
import wenrgise.common.xml.vo.SingleForm;
import wenrgise.ejb.common.utility.EnrgiseManager;

public class ParamUtil {
  public static String getDBName() {
    return (String)EnrgiseManager.getInstance().getAppMap().get("DBName");
  }
  
  public static String getModuleName() {
    return (String)EnrgiseManager.getInstance().getAppMap().get("Module");
  }
  
  public static String getQueryVO(String sFormName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    return oHashedEnrgiseForms.getSingleForm().get_EnrgiseQueryVO();
  }
  
  public static String getHeaderBD(String sFormName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    return oHashedEnrgiseForms.getSingleForm().get_HeaderBD();
  }
  
  public static String getHeaderSaveRequired(String sFormName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    return oHashedEnrgiseForms.getSingleForm().get_HeaderSave();
  }
  
  public static String getPseudoHeaderFlag(String sFormName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    return oHashedEnrgiseForms.getSingleForm().get_PseudoHeader();
  }
  
  public static String getDetailBD(String sFormName, String sScreenName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    DetailScreen oDetailScreen = (DetailScreen)oHashedEnrgiseForms.getDetailMap().get(sScreenName);
    return oDetailScreen.get_DetailBD();
  }
  
  public static String getDetailArrayName(String sFormName, String sScreenName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    DetailScreen oDetailScreen = (DetailScreen)oHashedEnrgiseForms.getDetailMap().get(sScreenName);
    return oDetailScreen.get_DetailArrayName();
  }
  
  public static String getDetailBeanName(String sFormName, String sScreenName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    DetailScreen oDetailScreen = (DetailScreen)oHashedEnrgiseForms.getDetailMap().get(sScreenName);
    return oDetailScreen.get_DetailBean();
  }
  
  public static String getSessionBeanName() {
    String s = String.valueOf(getModuleName()).concat(String.valueOf("_UserSession"));
    return String.valueOf(getModuleName()).concat(String.valueOf("_UserSession"));
  }
  
  public static String getHeaderBean(String sFormName) {
    try {
      System.out.println(String.valueOf("I am in paramUtil-->").concat(String.valueOf(sFormName)));
      HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
      return oHashedEnrgiseForms.getSingleForm().get_HeaderBean();
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    } 
  }
  
  public static int getHeaderSize(String sFormName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    return Integer.parseInt(oHashedEnrgiseForms.getSingleForm().get_HeaderSize());
  }
  
  public static int getDetailRecordPerPage(String sFormName, String sScreenName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    DetailScreen oDetailScreen = (DetailScreen)oHashedEnrgiseForms.getDetailMap().get(sScreenName);
    return Integer.parseInt(oDetailScreen.get_DetailRecordPerPage());
  }
  
  public static int getMaxDetailPages(String sFormName, String sScreenName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    DetailScreen oDetailScreen = (DetailScreen)oHashedEnrgiseForms.getDetailMap().get(sScreenName);
    return Integer.parseInt(oDetailScreen.get_DetailPagesPerSlot());
  }
  
  public static ArrayList getDetailList(String sFormName) {
    HashedEnrgiseForms oHashedEnrgiseForms = EnrgiseManager.getInstance().getCachedObject(sFormName);
    SingleForm oSingleForm = oHashedEnrgiseForms.getSingleForm();
    DetailScreens oDetailScreens = oSingleForm.get_DetailScreens();
    return oDetailScreens.get_DetailScreen();
  }
}
