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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import wenrgise.common.xml.vo.LOV;
import wenrgise.common.xml.vo.LOVClass;
import wenrgise.common.xml.vo.LOVInfo;
import wenrgise.common.xml.vo.Screen;
import wenrgise.common.xml.vo.ScreenMode;
import wenrgise.common.xml.vo.ScreenModes;
import wenrgise.common.xml.vo.Screens;

public class LOVManager {
  private static wenrgise.ejb.common.utility.LOVManager me;
  
  private HashMap oMap = new HashMap();
  
  public static wenrgise.ejb.common.utility.LOVManager getInstance() {
    if (me == null)
      me = new wenrgise.ejb.common.utility.LOVManager(); 
    return me;
  }
  
  public LOVInfo getCachedObject(String name_) {
    if (name_ == null || name_.trim().length() <= 0)
      return null; 
    return (LOVInfo)this.oMap.get(name_);
  }
  
  public void init(LOVClass oLOVClass) {
    if (oLOVClass == null)
      return; 
    ArrayList oList = oLOVClass.get_LOV();
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      LOV oLOV = oIt.next();
      String sLOVName = oLOV.get_LovKey();
      Screens oScreens = oLOV.get_Screens();
      Iterator oScreenIt = oScreens.get_Screen().iterator();
      while (oScreenIt.hasNext()) {
        Screen oScreen = oScreenIt.next();
        String sScreenName = oScreen.get_ScreenName();
        ScreenModes oScreenModes = oScreen.get_ScreenModes();
        Iterator oScreenModeIt = oScreenModes.get_ScreenMode().iterator();
        while (oScreenModeIt.hasNext()) {
          ScreenMode oScreenMode = oScreenModeIt.next();
          String sMode = oScreenMode.get_ModeName();
          LOVInfo oLOVInfo = new LOVInfo();
          oLOVInfo.setFacadeName(oScreenMode.get_FacadeName());
          oLOVInfo.setFunctionName(oScreenMode.get_FunctionName());
          oLOVInfo.setInsertFlag(oScreenMode.get_InsertFlag());
          oLOVInfo.setRecursiveFlag(oScreenMode.get_RecursiveFlag());
          String sCombinedKey = String.valueOf(String.valueOf(sLOVName).concat(String.valueOf(sScreenName))).concat(String.valueOf(sMode));
          if (!this.oMap.containsKey(sCombinedKey))
            this.oMap.put(sCombinedKey, oLOVInfo); 
        } 
      } 
    } 
  }
  
  public static void main(String[] argv) {
    wenrgise.ejb.common.utility.LOVManager oLov = new wenrgise.ejb.common.utility.LOVManager();
  }
}
