package com.eactive.eai.rms.client.util;

import java.util.Properties;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

import com.eactive.eai.rms.client.context.RmsProperties;
//import com.ibm.websphere.management.AdminClient;


/**
 * The Class MBeanServerFactoryBeanUtil.
 * <ul>
 * <li>1. Function :WebLogic의 MBeanServer를 생성 합니다. </li>
 * <li>2. Summary :</li>
 * <li>3. Notification :</li>
 * </ul>
 * 
 * @author  : $Author: amjang $
 * @version : $Revision: 1.3 $
 */
public class AdminClinetPropertiesFactoryBeanUtil implements FactoryBean, InitializingBean {

    /** F/W logger. */
    private static com.eactive.eai.common.util.Logger logger = com.eactive.eai.common.util.Logger.getLogger(com.eactive.eai.common.util.Logger.LOGGER_CLIENT);


    /** The monitoring properties. */
    private RmsProperties rmsProperties;

    /** The properties. */
    private  Properties properties = null;

    /**
     * Sets the monitoring properties.
     * 
     * @param rmsProperties the new monitoring properties
     */
    public void setRmsProperties(RmsProperties rmsProperties) {
        this.rmsProperties = rmsProperties;
    }

    public void afterPropertiesSet() {
        init();
    }

    /**
     * Inits the.
     */

    private void init() {
        try {
	        String serverIp     = rmsProperties.getStringProperty(RmsProperties.LOCAL_MBEAN_SERVER_IP);
	        String port         = rmsProperties.getStringProperty(RmsProperties.LOCAL_MBEAN_SERVER_PORT);
	        String loginId      = rmsProperties.getStringProperty(RmsProperties.LOCAL_MBEAN_SERVER_ID);
	        String password     = rmsProperties.getStringProperty(RmsProperties.LOCAL_MBEAN_SERVER_PASSWORD);
	        String subjectLogin = rmsProperties.getStringProperty(RmsProperties.SUBJECT_LOGIN);
	        
			Properties props = new Properties();
			if (ContainerUtil.get() == ContainerUtil.WEBSPHERE ){
//				props.put(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_RMI);
//				props.put(AdminClient.CONNECTOR_SECURITY_ENABLED, ""+false);
//				props.put(AdminClient.CONNECTOR_HOST, serverIp);
//				props.put(AdminClient.CONNECTOR_PORT, port);
//				props.put(AdminClient.USERNAME, loginId);
//				props.put(AdminClient.PASSWORD, password);
				props.put("isSubjectLogin", subjectLogin);
				
			}else if (ContainerUtil.get() == ContainerUtil.WEBLOGIC ){
				props.put(RmsProperties.LOCAL_MBEAN_SERVER_IP, serverIp);
				props.put(RmsProperties.LOCAL_MBEAN_SERVER_PORT, port);
				props.put(RmsProperties.LOCAL_MBEAN_SERVER_ID, loginId);
				props.put(RmsProperties.LOCAL_MBEAN_SERVER_PASSWORD, password);
			}
			
			this.properties = props;
			
        } catch (Exception e) {
            logger.error("Could not make AdminClient Properties : "  + e.getMessage(),e);
        }
    }


    public Object getObject() {
        return this.properties;
    }

    public Class<Properties> getObjectType() {
        return Properties.class;
    }

    public boolean isSingleton() {
        return true;
    }

}
