/*
 * 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
 *
 * Initial developer(s):Adriana Danes
 * Contributor(s): ______________________________________.
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.jmx.vjadmin.servlet;

// standard imports
import java.util.HashMap;

import javax.servlet.http.HttpSession;

import org.apache.velocity.VelocityContext;

public class InitVeloContext {

    static int nbServices = 9;

    // The services names as used in the Velocity templates
    static String services[] = {"EJBSERVER", "CONTAINER", "DATABASE", "RESOURCE", "TRANSACTION", "LOG", "JMS", "SECURITY", "ALLMBEANS"};

    // These names are contained in the URL pattern allowing to call the servlet corresponding to the service 
    static String linkNames[] = {"EJBServer", "ContainerService", "DatabaseService", "ResourceService", "TransactionService", "LogService", "JMSService", "SecurityService", "AllMbeans"};

    // These names give the label in the banner for the selected service
    static String labelNames[] = {"Server Monitoring", "Container Service", "Database Service", "Resource Service", "Transaction Service", "Log Service", "JMS Service", "Security Service", "All Mbeans"};

    static protected VelocityContext doIt(HttpSession session) {
	VelocityContext context = new VelocityContext();
	
	HashMap linkNamesTable = new HashMap(nbServices);
	HashMap labelNamesTable = new HashMap(nbServices);
	
	for (int i = 0 ; i < nbServices ; i++) {
	    linkNamesTable.put(services[i], linkNames[i]);
	    labelNamesTable.put(services[i], labelNames[i]);
	}
	
	String[] theServices = new String[nbServices];
	for (int i = 0 ; i < nbServices ; i++)
	    theServices[i] = services[i];

	context.put("linkNames", linkNamesTable);
	context.put("labelNames", labelNamesTable);
	context.put("services", theServices);
	context.put("nbServices", new Integer(nbServices));

	session.setAttribute("initialContext", context);
	    
	return context;
    }
}
