KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > framework > amoda > environment > ant > ANTTaskEnvironment


1 /*
2  * Project: AMODA - Abstract Modeled Application
3  * Class: de.gulden.framework.amoda.environment.ant.ANTTaskEnvironment
4  * Version: snapshot-beautyj-1.1
5  *
6  * Date: 2004-09-29
7  *
8  * This is a snapshot version of the AMODA 0.2 development branch,
9  * it is not released as a seperate version.
10  * For AMODA, see http://amoda.berlios.de/.
11  *
12  * This is licensed under the GNU Lesser General Public License (LGPL)
13  * and comes with NO WARRANTY.
14  *
15  * Author: Jens Gulden
16  * Email: amoda@jensgulden.de
17  */

18
19 package de.gulden.framework.amoda.environment.ant;
20
21 import de.gulden.framework.amoda.environment.commandline.*;
22 import de.gulden.framework.amoda.generic.core.*;
23 import de.gulden.framework.amoda.model.core.*;
24 import de.gulden.framework.amoda.model.data.*;
25 import de.gulden.framework.amoda.model.data.Value;
26 import de.gulden.framework.amoda.model.interaction.*;
27 import java.lang.*;
28 import java.util.*;
29
30 /**
31  * Class ANTTaskEnvironment.
32  *
33  * @author Jens Gulden
34  * @version snapshot-beautyj-1.1
35  */

36 public class ANTTaskEnvironment extends CommandLineApplicationEnvironment {
37
38     // ------------------------------------------------------------------------
39
// --- fields ---
40
// ------------------------------------------------------------------------
41

42     protected List inputValues = new ArrayList();
43
44     protected ANTTaskApplicationWrapper taskWrapper;
45
46
47     // ------------------------------------------------------------------------
48
// --- methods ---
49
// ------------------------------------------------------------------------
50

51     public ANTTaskApplicationWrapper getTaskWrapper() {
52         return taskWrapper;
53     }
54
55     public void setTaskWrapper(ANTTaskApplicationWrapper aNTTaskApplicationWrapper) {
56         if (this.taskWrapper != aNTTaskApplicationWrapper) {
57             this.taskWrapper = aNTTaskApplicationWrapper;
58             if (aNTTaskApplicationWrapper != null) aNTTaskApplicationWrapper.setEnvironment(this);
59         }
60     }
61
62     public ArgsParser createArgsParser() {
63         return null;
64     }
65
66     public void launch(Application application) {
67         GenericApplication genericApplication=(GenericApplication)application; // application must be of type GenericApplication
68
setGenericApplication(genericApplication);
69         // everything has been initialized before through called from ANT, so directly launch now
70
try {
71             launchAfterInit(genericApplication);
72         } catch (Throwable JavaDoc t) {
73             getGenericApplication().fatalError(t);
74         }
75     }
76
77     public void doErrorMessage(ErrorMessage msg) {
78         if (msg.exitApplication()) {
79             Throwable JavaDoc t=msg.getCause();
80             if (t!=null) {
81                 throw new org.apache.tools.ant.BuildException(msg.getText()+" - "+t.getMessage(),t);
82             } else {
83                 throw new org.apache.tools.ant.BuildException(msg.getText());
84             }
85         } else {
86             getTaskWrapper().log(msg.getText(),org.apache.tools.ant.Project.MSG_ERR);
87         }
88     }
89
90     public Value[] getInputValues() {
91         de.gulden.framework.amoda.generic.data.GenericValue[] v = new de.gulden.framework.amoda.generic.data.GenericValue[inputValues.size()];
92         for (int i=0; i<v.length; i++) {
93             v[i] = new de.gulden.framework.amoda.generic.data.GenericValue();
94             Object JavaDoc o = inputValues.get(i);
95             if (o instanceof Src) { // <src path="..."/>
96
v[i].setType(java.io.File JavaDoc.class);
97                 v[i].set(((Src)o).getPath());
98             } else if (o instanceof de.gulden.framework.amoda.environment.ant.Value) { // <value input="..."/>
99
v[i].setType(String JavaDoc.class);
100                 v[i].set(((de.gulden.framework.amoda.environment.ant.Value)o).getInput());
101             }
102         }
103         return v;
104     }
105
106     void addInput(Object JavaDoc input) {
107         // All inner tags of the ANT-wrapped application are considered to be input values from AMODA's point of view
108
// currently, input can be of type "Src" or "Value", which mean any AMODA application running in ANT
109
// can have <src path=".."> or <value input=".."> tags as children.
110
inputValues.add(input);
111         /*
112         de.gulden.framework.amoda.model.data.Value[] oldV = getInputValues();
113         de.gulden.framework.amoda.model.data.Value[] v;
114         if (oldV != null) {
115             v = new de.gulden.framework.amoda.model.data.Value[ oldV.length + 1 ];
116             System.arraycopy(oldV, 0, v, 0, oldV.length);
117         } else {
118             v = new de.gulden.framework.amoda.model.data.Value[1];
119         }
120         v[v.length-1] = value;
121         setInputValues(v);*/

122     }
123
124 } // end ANTTaskEnvironment
125
Popular Tags