ANTTaskEnvironment.java :  » Code-Analyzer » beautyJ » de » gulden » framework » amoda » environment » ant » Java Open Source

Java Open Source » Code Analyzer » beautyJ 
beautyJ » de » gulden » framework » amoda » environment » ant » ANTTaskEnvironment.java
/*
 * Project: AMODA - Abstract Modeled Application
 * Class:   de.gulden.framework.amoda.environment.ant.ANTTaskEnvironment
 * Version: snapshot-beautyj-1.1
 *
 * Date:    2004-09-29
 *
 * This is a snapshot version of the AMODA 0.2 development branch,
 * it is not released as a seperate version.
 * For AMODA, see http://amoda.berlios.de/.
 *  
 * This is licensed under the GNU Lesser General Public License (LGPL)
 * and comes with NO WARRANTY.
 *
 * Author:  Jens Gulden
 * Email:   amoda@jensgulden.de
 */

package de.gulden.framework.amoda.environment.ant;

import de.gulden.framework.amoda.environment.commandline.*;
import de.gulden.framework.amoda.generic.core.*;
import de.gulden.framework.amoda.model.core.*;
import de.gulden.framework.amoda.model.data.*;
import de.gulden.framework.amoda.model.data.Value;
import de.gulden.framework.amoda.model.interaction.*;
import java.lang.*;
import java.util.*;

/**
 * Class ANTTaskEnvironment.
 *  
 * @author  Jens Gulden
 * @version  snapshot-beautyj-1.1
 */
public class ANTTaskEnvironment extends CommandLineApplicationEnvironment {

    // ------------------------------------------------------------------------
    // --- fields                                                           ---
    // ------------------------------------------------------------------------

    protected List inputValues = new ArrayList();

    protected ANTTaskApplicationWrapper taskWrapper;


    // ------------------------------------------------------------------------
    // --- methods                                                          ---
    // ------------------------------------------------------------------------

    public ANTTaskApplicationWrapper getTaskWrapper() {
        return taskWrapper;
    }

    public void setTaskWrapper(ANTTaskApplicationWrapper aNTTaskApplicationWrapper) {
        if (this.taskWrapper != aNTTaskApplicationWrapper) {
            this.taskWrapper = aNTTaskApplicationWrapper;
            if (aNTTaskApplicationWrapper != null) aNTTaskApplicationWrapper.setEnvironment(this);
        }
    }

    public ArgsParser createArgsParser() {
        return null;
    }

    public void launch(Application application) {
        GenericApplication genericApplication=(GenericApplication)application; // application must be of type GenericApplication
        setGenericApplication(genericApplication);
        // everything has been initialized before through called from ANT, so directly launch now
        try {
            launchAfterInit(genericApplication);
        } catch (Throwable t) {
            getGenericApplication().fatalError(t);
        }
    }

    public void doErrorMessage(ErrorMessage msg) {
        if (msg.exitApplication()) {
            Throwable t=msg.getCause();
            if (t!=null) {
                throw new org.apache.tools.ant.BuildException(msg.getText()+" - "+t.getMessage(),t);
            } else {
                throw new org.apache.tools.ant.BuildException(msg.getText());
            }
        } else {
            getTaskWrapper().log(msg.getText(),org.apache.tools.ant.Project.MSG_ERR);
        }
    }

    public Value[] getInputValues() {
        de.gulden.framework.amoda.generic.data.GenericValue[] v = new de.gulden.framework.amoda.generic.data.GenericValue[inputValues.size()];
        for (int i=0; i<v.length; i++) {
            v[i] = new de.gulden.framework.amoda.generic.data.GenericValue();
            Object o = inputValues.get(i);
            if (o instanceof Src) { // <src path="..."/>
                v[i].setType(java.io.File.class);
                v[i].set(((Src)o).getPath());
            } else if (o instanceof de.gulden.framework.amoda.environment.ant.Value) { // <value input="..."/>
                v[i].setType(String.class);
                v[i].set(((de.gulden.framework.amoda.environment.ant.Value)o).getInput());
            }
        }
        return v;
    }

    void addInput(Object input) {
        // All inner tags of the ANT-wrapped application are considered to be input values from AMODA's point of view
        // currently, input can be of type "Src" or "Value", which mean any AMODA application running in ANT
        // can have <src path=".."> or <value input=".."> tags as children.
        inputValues.add(input);
        /*
        de.gulden.framework.amoda.model.data.Value[] oldV = getInputValues();
        de.gulden.framework.amoda.model.data.Value[] v;
        if (oldV != null) {
            v = new de.gulden.framework.amoda.model.data.Value[ oldV.length + 1 ];
            System.arraycopy(oldV, 0, v, 0, oldV.length);
        } else {
            v = new de.gulden.framework.amoda.model.data.Value[1];
        }
        v[v.length-1] = value;
        setInputValues(v);*/
    }

} // end ANTTaskEnvironment
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.