/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */
package org.objectweb.jonas.jmx;

import javax.management.MBeanServerConnection;

import org.objectweb.jonas.common.Log;
import org.objectweb.util.monolog.api.Logger;

/**
 *
 * @author Adriana Danes
 *
 * This class allows to load a suitable ManagementRepr in the JonasMaanagementRepr
 * class. This operation is necessary to initilize and then possibly change the
 * management context. A management context is characterized by data allowing
 * to manage a JOnAS app server instance:
 * <ul>
 * <li>domain name (currently cann not switch from a domain to another)
 * <li>server name
 * <li>MBeanServerConnection allowing to connect to the managed server's JMX server
 * </ul>
 */
public class ManagementReprLoader {
	/**
     * Logger
     */
    private static Logger logger = Log.getLogger("org.objectweb.jonas.jmx");

    /**
     * This method is used to switch from a managed server to another.
     * It creates a ManagementRepr for the given server, then update JonasManagementRepr.
     * @param serverName the name of the server to be managed
     * @param currentServerName the name of the server which is currently managed
     *//*
    public static void loadServerRepr(String serverName, String currentServerName) {
        ManagementRepr repr = null;
        if (serverName == null) {
            repr = ManagementReprFactory.getManagementRepr();
        } else {
            repr = ManagementReprFactory.getManagementRepr(serverName);
            if (((ManagementReprImplJSR160) repr).getMBeanServerConnection() == null) {
                // Could not create JSR 160 MnagementRepr
                // Create a ManagementReprImpl for the current server
                repr = ManagementReprFactory.getManagementRepr(currentServerName);
            }
        }
        JonasManagementRepr.setRepr(repr);
    }*/
    /**
     * Create a ManagementRepr for the given server, then update JonasManagementRepr
     * @param serverName the name of the server to be managed
     */
    public static void loadServerRepr(String serverName) {
        ManagementRepr repr = ManagementReprFactory.getManagementRepr(serverName);
        if (((ManagementReprImplJSR160) repr).getMBeanServerConnection() != null) {
            JonasManagementRepr.addServerRepr(serverName, repr);
        }
    }
    /**
     * Update the JonasManagementRepr datastructure () in order to easilly invoke
     * operations on MBeans corresponding to a managed server in domain/cluster
     * @param serverName
     * @param connection
     *//*
    public static void loadServerReprForCluster(String serverName, MBeanServerConnection connection) {
        ManagementRepr repr = ManagementReprFactory.getManagementRepr(serverName, connection);
        if (repr != null) {
            JonasManagementRepr.addServerRepr(serverName, repr);
        }
    }*/
}