// $Id: Axiom.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.logic.paragraph;


import com.meyling.principia.argument.AbstractArgumentList;
import com.meyling.principia.argument.Argument;
import com.meyling.principia.argument.ArgumentException;
import com.meyling.principia.logic.basic.Formula;
import com.meyling.principia.module.Module;
import com.meyling.principia.module.ModuleCreator;


/**
 * Logical Axiom.
 * @version $Revision: 1.6 $
 * @author  Michael Meyling
 */
public class Axiom extends AbstractArgumentList implements Argument,
        ParagraphCheck {


    /**
     * Constructs a logical Axiom.
     *
     * @param   arguments     formula to be an Axiom
     * @throws  ArgumentException    if there is not exactly one
     *          argument or the first argument is not an instance
     *          of {@link Formula} or it contains any
     *          {@link PatternVariable}.
     */
    public Axiom(final Argument[] arguments)
            throws ArgumentException {
        super(arguments);

        if (arguments.length != 1) {
            throw new ArgumentException(
                ParagraphConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_NUMBER,
                ModuleCreator.getName(this.getClass())
                + ParagraphConstants.OPERATOR_WITH_ONE_ARGUMENT);
        }
        if (!(arguments[0] instanceof Formula)) {
            throw new ArgumentException(
                ParagraphConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                ModuleCreator.getName(this.getClass())
                + ParagraphConstants.FIRST_ARGUMENT_TYPE
                + ParagraphConstants.FORMULA,
                arguments[0]);
        }
        if (arguments[0].containsPatternVariables()) {
            throw new ArgumentException(
                ParagraphConstants.CODE_CONSTRUCTOR_ARGUMENT_CHECK_FAILED,
                ParagraphConstants.NO_PATTERN_VARIABLE_IN_AXIOM,
                arguments[0]);
        }
    }


    /**
     * Tries to add this axiom.
     *
     * @param   module   module
     * @param   label    label of paragraph
     */
    public final void check(final Module module, final String label) {
        module.addAxiom(label, this, module);
    }


    /** @inherited */
    public final Argument create(final Argument[] arguments)
            throws ArgumentException {
        return new Axiom(arguments);
    }


    /** @inherited */
    public final String toString() {
        return "Axiom " + getArgument(0).toString();
    }


}
