package ws.prova.parser;

/*
 * Copyright (C) 2002-2007 <a href="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</a>
 *
 * 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 of the License, or (at your option) 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
 */

import org.mandarax.kernel.ClauseSetException;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Prototypical parsing exception
 * <p>Title: Prova </p>
 * <p>Description: Prototypical parsing exception</p>
 * <p>Copyright: Copyright (C) 2002-2007</p>
 * <p>Company: City University, London, United Kingdom</p>
 *
 * @author <A HREF="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</A>
 * @version 2.0 <25 March 2007>
 */
public class ParsingException extends ClauseSetException {
	private String src;
	private String desc;
	private Map errors = new HashMap();

	public ParsingException() {
	}

	public ParsingException(final String message) {
		super(message);
	}

	public String toString() {
		return desc + " in " + src;
	}

	public Map errors() {
		return errors;
	}

	public String errorsToString() {
		StringBuffer sb = new StringBuffer();
		for (Iterator kit = errors.keySet().iterator(); kit.hasNext();) {
			final Object key = kit.next();
			sb.append("Line ");
			sb.append(key);
			sb.append(" > ");
			sb.append(errors.get(key));
			sb.append("\n");
		}
		return sb.toString();
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getSource() {
		return src;
	}

	public void setSource(final String src) {
		this.src = src;
	}

	public void addError(final int line, final String desc) {
		errors.put(new Integer(line), desc);
	}
}
