// $Id: Specification.java,v 1.5 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.module;


import com.meyling.principia.argument.AbstractArgumentList;
import com.meyling.principia.argument.Argument;
import com.meyling.principia.argument.ArgumentException;


/**
 * Describes a specificiation of a module, that means
 * its name, versions and possible &quot;physical&quot;
 * locations.
 *
 * @version $Revision: 1.5 $
 * @author  Michael Meyling
 */
public class Specification extends AbstractArgumentList
        implements Argument {

    /**
     * Constructs a module specification.
     *
     * @param   arguments    list of arguments
     * @throws  ArgumentException    if the argument list
     *          hasn't the length 4 or isn't made of
     *          {@link Name}, {@link Version}, {@link Version}
     *          and {@link LocationList} in exactly that order.
     */
    public Specification(final Argument[] arguments)
            throws ArgumentException {
        super(arguments);
        if (arguments.length != 4) {
            throw new ArgumentException(
                ModuleConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_NUMBER,
                ModuleCreator.getName(this.getClass())
                + ModuleConstants.OPERATOR_WITH_FOUR_ARGUMENTS);
        }
        if (!(arguments[0] instanceof Name)) {
            throw new ArgumentException(
                ModuleConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                ModuleCreator.getName(this.getClass())
                + ModuleConstants.FIRST_ARGUMENT_TYPE
                + ModuleCreator.getName(Name.class),
                arguments[0]);
        }
        if (!(arguments[1] instanceof Version)) {
            throw new ArgumentException(
                ModuleConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                ModuleCreator.getName(this.getClass())
                + ModuleConstants.SECOND_ARGUMENT_TYPE
                + ModuleCreator.getName(Version.class),
                arguments[1]);
        }
        if (!(arguments[2] instanceof Version)) {
            throw new ArgumentException(
                ModuleConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                ModuleCreator.getName(this.getClass())
                + ModuleConstants.THIRD_ARGUMENT_TYPE
                + ModuleCreator.getName(Version.class),
                arguments[2]);
        }
        if (!(arguments[3] instanceof LocationList)) {
            throw new ArgumentException(
                ModuleConstants.CODE_CONSTRUCTOR_WRONG_ARGUMENT_TYPE,
                ModuleCreator.getName(this.getClass())
                + ModuleConstants.FOURTH_ARGUMENT_TYPE
                + ModuleCreator.getName(LocationList.class),
                arguments[3]);
        }
    }


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



    /** @inherited */
    public final String toString() {
        StringBuffer buffer = new StringBuffer("Specification: ");
        for (int i = 0; i < getArgumentSize(); i++) {
            if (i != 0) {
                buffer.append(", ");
            };
            buffer.append(getArgument(i));
        }
        return buffer.toString();
    }


}
