package wenrgise.common.businessdelegate;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.ServiceLocator;
import wenrgise.common.vo.LovQueryVO;
import wenrgise.common.vo.LovVO;
import wenrgise.common.xml.vo.LOVInfo;

public class LOVBD {
  public LovVO getLOVData(LOVInfo oLOVInfo, LovQueryVO oLOVQueryVO) throws EnrgiseSystemException {
    try {
      String sFacadeName = oLOVInfo.getFacadeName();
      System.out.println(sFacadeName);
      Object obj = ServiceLocator.getLocator().getService(sFacadeName);
      Method oMethod = obj.getClass().getDeclaredMethod("create", null);
      Object oFacadeObj = oMethod.invoke(obj, null);
      Class[] oCls = { oLOVQueryVO.getClass() };
      Method oFnMethod = oFacadeObj.getClass().getDeclaredMethod(oLOVInfo.getFunctionName(), oCls);
      Object[] oParams = { oLOVQueryVO };
      LovVO oLovVO = (LovVO)oFnMethod.invoke(oFacadeObj, oParams);
      return oLovVO;
    } catch (InvocationTargetException oInv) {
      throw new EnrgiseSystemException(oInv);
    } catch (IllegalAccessException oIll) {
      throw new EnrgiseSystemException(oIll);
    } catch (NoSuchMethodException oMet) {
      throw new EnrgiseSystemException(oMet);
    } 
  }
}
