<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="com.eactive.eai.adapter.AdapterGroupVO"%>
<%@ page import="com.eactive.eai.adapter.AdapterVO"%>
<%@ page import="java.util.*"%>
<%
    try
    {
        //파라미터
        String adapterType      = request.getParameter("adapterType");
        String adapterGroupNm   = request.getParameter("adapterGroupNm");
        String adapterNm        = request.getParameter("adapterNm");
        String adapterStartStop = request.getParameter("adapterStartStop");

        //파라미터에 대한 null 처리
        if (adapterType == null)        adapterType = "";
        if (adapterGroupNm == null)     adapterGroupNm = "";
        if (adapterNm == null)          adapterNm = "";
        if (adapterStartStop == null)   adapterStartStop = "";
        
        //성공 실패여부 변수
        boolean success = false;

        com.eactive.eai.adapter.AdapterManager manager
            = com.eactive.eai.adapter.AdapterManager.getInstance();
        java.util.HashMap voMap = manager.getAllAdapterGroupVO();

        //out.println(voMap.size());
        Iterator it = voMap.keySet().iterator();
        String[] groupNames = new String[voMap.size()];
        for (int i = 0; it.hasNext(); i++)
        {
            groupNames[i] = (String) it.next();
        }
        Arrays.sort(groupNames);
        
        for (int i = 0; i < groupNames.length; i++)
        {
            AdapterGroupVO gvo = manager
                    .getAdapterGroupVO(groupNames[i]);

            if (gvo == null)
                continue;

            //해당 어댑터 타입이고 어댑터 그룹명일 경우
            if (adapterType.equals(gvo.getType())
                    && adapterGroupNm.equals(gvo.getName()))
            {
                Iterator it2 = gvo.getAdapters();

                for (int j = 0; it2.hasNext(); j++)
                {
                    AdapterVO vo = (AdapterVO) it2.next();

                    if (vo == null)
                        continue;

                    //해당 어댑터의 AdapterVO 일경우
                    if (vo.getName().equals(adapterNm))
                    {
                        if (adapterStartStop.equals("START"))
                        {
                            vo.start();
                            out.print("The adapter has been activated.");
                            success = true ;

                        }
                        else if (adapterStartStop.equals("STOP"))
                        {
                            vo.stop();
                            out.print("The adapter has been shut down.");
                            success = true ;
                        }
                    }
                }
            }
        }
        
        if( success == false ) {
            out.print("No such adapter found.");
        }
    }
    catch (Exception e)
    {
        // YUN_DEBUG
        //e.printStackTrace();
        out.print("An error occurred during processing.");
    }
%>