package org.flymine.codegen;

/*
 * Copyright (C) 2002-2003 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;

import java.io.File;

import org.flymine.metadata.Model;

/**
 * Creates and runs a ModelOutput process to generate java or config files.
 *
 * @author Richard Smith
 */

public class ModelOutputTask extends Task
{
    protected File destDir;
    protected Model model;
    protected String type;

    /**
     * Sets the directory that output should be written to.
     * @param destDir the directory location
     */
    public void setDestDir(File destDir) {
        this.destDir = destDir;
    }

    /**
     * Set the type of model output required.
     * @param type the type of output
     */
    public void setType(String type) {
        this.type = type.toLowerCase();
    }

    /**
     * Set the model to be used.
     * @param modelName the model to be used
     */
    public void setModel(String modelName) {
        try {
            model = Model.getInstanceByName(modelName);
        } catch (Exception e) {
            throw new BuildException(e);
        }
    }

    /**
     * @see Task#execute
     * @throws BuildException
     */
    public void execute() throws BuildException {
        if (this.destDir == null) {
            throw new BuildException("destDir attribute is not set");
        }
        if (this.type == null) {
            throw new BuildException("type attribute is not set");
        }
        if (this.model == null) {
            throw new BuildException("model attribute is not set");
        }

        ModelOutput mo = null;

        try {
            if (type.equals("java")) {
                mo = new JavaModelOutput(model, destDir);
            } else if (type.equals("flyminetorque")) {
                mo = new FlyMineTorqueModelOutput(model, destDir);
            } else {
                throw new BuildException("Unrecognised value for output type: " + type);
            }
        } catch (Exception e) {
            throw new BuildException(e);
        }

        if (mo != null) {
            mo.process();
        } else {
            throw new BuildException("Error building ModelOutput");
        }
    }
}


@@ -2331,146 +2331,21 @@
     
-if (mo != null) %7B%0A            mo.process();%0A        %7D else %7B%0A            throw new BuildException(%22Error building ModelOutput%22);%0A        %7D
+mo.process();
 %0A   

Remove redundant code