/*
 *  hbIRCS
 *  
 *  Copyright 2005 Boris HUISGEN <bhuisgen@hbis.fr>
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package fr.hbis.ircs.commands;

import java.util.logging.Level;
import java.util.logging.Logger;

import fr.hbis.ircs.Command;
import fr.hbis.ircs.IRC;
import fr.hbis.ircs.Manager;
import fr.hbis.ircs.Message;
import fr.hbis.ircs.Source;

/**
 * The class <code>Error</code> implements the ERROR command.
 * 
 * @author bhuisgen
 */
public class Error implements Command
{
	/**
	 * Constructs a new <code>Error</code> object.
	 * 
	 * @param manager
	 *            the manager.
	 */
	public Error(Manager manager)
	{
		m_manager = manager;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see fr.hbis.ircs.Command#execute(fr.hbis.ircs.Source,
	 * java.lang.String[])
	 */
	public void execute(Source src, String[] params)
	{
		// ERROR <message>

		if ((params == null) || (params.length < 1))
		{
			Message message = Message.create(IRC.ERR_NEEDMOREPARAMS, src);
			message.addParameter("ERROR");
			message.addLastParameter(IRC.ERRMSG_NEEDMOREPARAMS);
			src.send(message);

			return;
		}

		doCommand(src, params);
	}

	/**
	 * Processes the ERROR command.
	 * 
	 * @param src
	 *            the source.
	 * @param params
	 *            the parameters of the command.
	 */
	private void doCommand(Source src, String[] params)
	{
		m_logger.log(Level.WARNING, params[0]);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see fr.hbis.ircs.Command#getName()
	 */
	public String getName()
	{
		return ("ERROR");
	}

	private Manager m_manager;
	private static final Logger m_logger = Logger
			.getLogger("fr.hbis.ircs.commands.Error");
}
