// $Id: ArgumentException.java,v 1.6 2004/02/27 16:30:00 m31 Exp $
//
// This file is part of the program suite "Principia Mathematica II"
// which is a working prototype for the main project:
// "Hilbert II" - http://www.qedeq.org
//
// Copyright 2001-2004  Michael Meyling <mime@qedeq.org>.
//
// "Principia Mathematica II" 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 General Public License for more details.

package com.meyling.principia.argument;


/**
 * This is a construction (and checking) exception for arguments.
 *
 * @version $Revision: 1.6 $
 * @author  Michael Meyling
 */
public class ArgumentException extends Exception {

    /** exception code */
    private final int code;

    /** description of reason for exception */
    private final String description;

    /** problem with this argument */
    private Argument argument = null;

    /** problem is illustrated with this secondary argument */
    private final Argument secundaryArgument;

    /** occured problem at beginning of argument? */
    private boolean begin = true;;


    /**
     * Constructs an argument exception.
     *
     * @param  code         exception cathegory
     * @param  description  what is the problem
     */
    public ArgumentException(final int code, final String description) {
        super(description);
        this.code = code;
        this.description = description;
        this.argument = null;
        this.secundaryArgument = null;
    }


    /**
     * Constructs an argument exception.
     *
     * @param  code         exception cathegory
     * @param  description  what is the problem
     * @param  argument     this lead to problems
     */
    public ArgumentException(final int code, final String description,
            final Argument argument) {
        super(description);
        this.code = code;
        this.description = description;
        this.argument = argument;
        this.secundaryArgument = null;
    }


    /**
     * Constructs an argument exception.
     *
     * @param  code         exception cathegory
     * @param  description  what is the problem
     * @param  argument     this lead to problems
     * @param  secundaryArgument this argument illustrates the problem
     */
    public ArgumentException(final int code, final String description,
            final Argument argument, final Argument secundaryArgument) {
        super(description);
        this.code = code;
        this.description = description;
        this.argument = argument;
        this.secundaryArgument = secundaryArgument;
    }


    /**
     * Constructs an argument exception.
     *
     * @param  code         exception cathegory
     * @param  description  what is the problem
     * @param  argument     this lead to problems (or after it)
     * @param  begin        was the problem at the begining
     *                      of <code>argument</code>?
     */
    public ArgumentException(final int code, final String description,
            final Argument argument, final boolean begin) {
        super(description);
        this.code = code;
        this.description = description;
        this.argument = argument;
        this.secundaryArgument = null;
        this.begin = begin;
    }


    /**
     * Get exception code.
     *
     * @return  exception code
     */
    public final int getCode() {
        return this.code;
    }


    /**
     * Get exception description.
     *
     * @return  exception description
     */
    public final String getDescription() {
        return this.description;
    }


    /**
     * Get problematic argument.
     *
     * @return  argument that lead to problems (or last ok argument)
     *          maybe <code>null</code>
     */
    public final Argument getArgument() {
        return this.argument;
    }


    /**
     * Set the problematic argument.
     *
     * @param  argument that lead to problems (or last ok argument)
     */
    public final void setArgument(final Argument argument) {
        this.argument = argument;
    }


    /**
     * Get secundary argument.
     *
     * @return  argument that illustrates the problem
     *          maybe <code>null</code>
     */
    public final Argument getSecondaryArgument() {
        return this.secundaryArgument;
    }


    /**
     * Problem at begin of argument?
     *
     * @return  did <code>argument</code> lead to problems?
     */
    public final boolean isBegin() {
        return this.begin;
    }


}
