KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > installer > CompileResult


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2003 Tino Schwarze
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.installer;
23
24 /**
25  * This class describes the result of the compilation.
26  *
27  * This class is here because error handling is not straight-forward with regard to compilation.
28  *
29  * The error condition consists of an error message, the full command line which failed to execute
30  * plus it's stdout and stderr. The reason for this class to exist is that there are three possible
31  * reactions to the error (chosen by the user).
32  * <ol>
33  * <li>abort</li>
34  * <li>ignore (continue anyway)</li>
35  * <li>reconfigure</li>
36  * </ol>
37  *
38  * @author Tino Schwarze
39  */

40 public class CompileResult
41 {
42
43     // -------- public constants ---------------
44
// arbitrary values
45
public final static int SUCCESS = 42;
46
47     public final static int FAILED = 23;
48
49     public final static int ACTION_ABORT = 27;
50
51     public final static int ACTION_CONTINUE = 39;
52
53     public final static int ACTION_RECONFIGURE = 31;
54
55     // -------- private variables ---------------
56
// we're optimistic...
57
private int status = SUCCESS;
58
59     // here we're pessimistic
60
private int action = ACTION_ABORT;
61
62     /** the error message */
63     private String JavaDoc message = null;
64
65     /** the command line */
66     private String JavaDoc[] cmdline = null;
67
68     /** the stdout of the command */
69     private String JavaDoc stdout = null;
70
71     /** the stderr of the command */
72     private String JavaDoc stderr = null;
73
74     /** constructor, create a new successful result */
75     public CompileResult()
76     {
77         this.status = SUCCESS;
78         this.action = ACTION_CONTINUE;
79     }
80
81     /**
82      * creates a new CompileResult with status FAILED
83      *
84      * @param message description of the exception
85      * @param cmdline full command line of failed command
86      * @param stdout standard output of failed command
87      * @param stderr standard error of failed command
88      */

89     public CompileResult(String JavaDoc message, String JavaDoc[] cmdline, String JavaDoc stdout, String JavaDoc stderr)
90     {
91         this.message = message;
92         this.status = FAILED;
93         this.cmdline = cmdline;
94         this.stdout = stdout;
95         this.stderr = stderr;
96     }
97
98     public void setStatus(int status)
99     {
100         if ((status == SUCCESS) || (status == FAILED))
101         {
102             this.status = status;
103         }
104     }
105
106     public int getStatus()
107     {
108         return this.status;
109     }
110
111     public void setAction(int action)
112     {
113         if ((action == ACTION_ABORT) || (action == ACTION_CONTINUE)
114                 || (action == ACTION_RECONFIGURE))
115         {
116             this.action = action;
117         }
118
119     }
120
121     public int getAction()
122     {
123         return this.action;
124     }
125
126     /** check for success (convenience function) */
127     public boolean isSuccess()
128     {
129         return (this.status == SUCCESS);
130     }
131
132     /** check whether to abort (convenience function) */
133     public boolean isAbort()
134     {
135         return ((this.status == FAILED) && (this.action == ACTION_ABORT));
136     }
137
138     /**
139      * check whether to continue (convenience function)
140      *
141      * @return true if status is SUCCESS or action is CONTINUE
142      */

143     public boolean isContinue()
144     {
145         return ((this.status == SUCCESS) || (this.action == ACTION_CONTINUE));
146     }
147
148     /** check whether to reconfigure (convenience function) */
149     public boolean isReconfigure()
150     {
151         return ((this.status == FAILED) && (this.action == ACTION_RECONFIGURE));
152     }
153
154     /**
155      * return error message
156      *
157      * @return the error message describing the action that failed (might be null)
158      */

159     public String JavaDoc getMessage()
160     {
161         return this.message;
162     }
163
164     /**
165      * get command line of failed command as a string
166      *
167      * @return command line of failed command
168      */

169     public String JavaDoc getCmdline()
170     {
171         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
172         for (int i = 0; i < this.cmdline.length; ++i)
173         {
174             if (sb.length() > 0) sb.append(' ');
175             sb.append(this.cmdline[i]);
176         }
177         return sb.toString();
178     }
179
180     /**
181      * get command line of failed command as an array of strings
182      *
183      * @return command line of failed command
184      */

185     public String JavaDoc[] getCmdlineArray()
186     {
187         return this.cmdline;
188     }
189
190     public String JavaDoc getStdout()
191     {
192         return this.stdout;
193     }
194
195     public String JavaDoc getStderr()
196     {
197         return this.stderr;
198     }
199
200 }
201
Popular Tags