@@ -0,0 +1,3182 @@
+package org.flymine.task;%0A%0Aimport org.apache.tools.ant.Task;%0Aimport org.apache.tools.ant.BuildException;%0A%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.InputStream;%0Aimport java.io.FileWriter;%0A%0Aimport org.flymine.modelproduction.AbstractModelParser;%0Aimport org.flymine.modelproduction.uml.XmiParser;%0Aimport org.flymine.modelproduction.acedb.AceModelParser;%0Aimport org.flymine.metadata.Model;%0A%0A/**%0A * Ant task that calls a parser to build a FlyMine model from an external source%0A * and persist it as xml.%0A *%0A * @author Richard Smith%0A */%0A%0Apublic class ModelGenerationTask extends Task%0A%7B%0A    protected String modelName;%0A    protected File destDir;%0A    protected String type;%0A    protected File source;%0A%0A    /**%0A     * Set name of the model to be created.%0A     * @param modelName name of the model%0A     */%0A    public void setModelName(String modelName) %7B%0A        this.modelName = modelName;%0A    %7D%0A%0A    /**%0A     * Set the directory to create output xml file in.%0A     * @param destDir destination directory for output%0A     */%0A    public void setDestDir(File destDir) %7B%0A        this.destDir = destDir;%0A    %7D%0A%0A    /**%0A     * Set the type of input to be parsed.%0A     * @param type type of source model to be parsed%0A     */%0A    public void setType(String type) %7B%0A        this.type = type.toLowerCase();%0A    %7D%0A%0A    /**%0A     * Set the source file to be parsed.%0A     * @param source the file to be parsed%0A     */%0A    public void setSource(File source) %7B%0A        this.source = source;%0A    %7D%0A%0A%0A    /**%0A     * @see Task#execute%0A     * @throws BuildException%0A     */%0A    public void execute() throws BuildException %7B%0A        if (this.destDir == null) %7B%0A            throw new BuildException(%22destDir attribute is not set%22);%0A        %7D%0A        if (this.type == null) %7B%0A            throw new BuildException(%22type attribute is not set%22);%0A        %7D%0A        if (this.modelName == null) %7B%0A            throw new BuildException(%22modelName attribute is not set%22);%0A        %7D%0A        if (this.source == null) %7B%0A            throw new BuildException(%22source attribute is not set%22);%0A        %7D%0A%0A        if (!source.exists()) %7B%0A            throw new BuildException(%22source file (%22 + source + %22) does not exist.%22);%0A        %7D%0A%0A        AbstractModelParser parser = null;%0A        Model model = null;%0A%0A        if (type.equals(%22xmi%22)) %7B%0A            parser = new XmiParser();%0A        %7D else if (type.equals(%22acedb%22)) %7B%0A            parser = new AceModelParser();%0A        %7D else %7B%0A            throw new BuildException(%22Unrecognised value for type: %22 + type);%0A        %7D%0A%0A%0A        try %7B%0A            FileInputStream fis = new FileInputStream(source);%0A            model = parser.process((InputStream) fis);%0A        %7D catch (Exception e) %7B%0A            throw new BuildException(e);%0A        %7D%0A%0A        if (model == null) %7B%0A            throw new BuildException(%22model not generated correctly%22);%0A        %7D%0A%0A        try %7B%0A            File output = new File(destDir, modelName + %22_model.xml%22);%0A            FileWriter writer = new FileWriter(output);%0A            writer.write(model.toString());%0A            writer.close();%0A        %7D catch (Exception e) %7B%0A            throw new BuildException(e);%0A        %7D%0A%0A    %7D%0A%0A%0A%7D%0A

call parsers on source models and output resulting FlyMine model as xml