KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > task > LoaderTask


1 /*
2
3      Loader - tool for transfering data from one JDBC source to another and
4      doing transformations during copy.
5
6     Copyright (C) 2002 Together
7
8     This library is free software; you can redistribute it and/or
9     modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     Lesser General Public License for more details.
17
18     You should have received a copy of the GNU Lesser General Public
19     License along with this library; if not, write to the Free Software
20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22  LoaderTask.java
23  Date: 15.06.2002.
24  @version 1.0
25  @author:
26  Milosevic Sinisa sinisami@eunet.yu
27  Radeka Dusan diradeka@neobee.net
28  */

29
30 package org.webdocwf.util.loader.task;
31
32 import java.io.BufferedReader JavaDoc;
33 import java.io.InputStreamReader JavaDoc;
34
35 import org.apache.tools.ant.BuildException;
36 import org.apache.tools.ant.Task;
37
38 /**
39 * <p>
40 * Loader Task class extends jakarta-ant Task class and uses to start Loader
41 * application as a jakarta-ant task in build.xml file.
42 * </p>
43 * <p>
44 * Attributes of LoaderTask represents Loader parameters:<br>
45 * <br>
46 * loadJobFileName attribute - defines loader job<br>
47 * mode attribute - defines mode <br>
48 * restartIndicator attribute - defines restart <br>
49 * userID attribute - defines user ID <br>
50 * logDirName attribute - defines log directory <br>
51 * logFileName attribute - defines log file <br>
52 * vendorFileName attribute - defines vendor file <br>
53 * onErrorContinue attribute - defines continue or not on error<br>
54 * commitCount attribute - defines commit count<br>
55 * additionalPaths tag - defines single or group of additionalPath tags<br>
56 * additionalPath tag - defines tag with path attribute <br>
57 * pathToConfFile attribute - defines path to conf file in jar<br>
58 * variables tag - defines single or group of variable tags<br>
59 * variable tag - defines tag with path attribute <br>
60 * name attribute - defines variable name<br>
61 * value attribute - defines variable value<br>
62 * <br>
63 * </p>
64 **/

65 public class LoaderTask extends Task {
66     private String JavaDoc loadJobFileName;
67     private String JavaDoc mode;
68     private String JavaDoc restartIndicator;
69     private String JavaDoc userID;
70     private String JavaDoc logDirName;
71     private String JavaDoc logFileName;
72     private String JavaDoc vendorFileName;
73     private String JavaDoc onErrorContinue;
74     private String JavaDoc commitCount;
75     private String JavaDoc tableNames;
76     private String JavaDoc additionalPaths;
77     private String JavaDoc additionalPath;
78
79     private String JavaDoc variables;
80
81     private String JavaDoc strLoaderExec = "";
82
83     private String JavaDoc returnCode;
84     private String JavaDoc pathToConfFile;
85
86     private String JavaDoc JAVAEXE = "java";
87     private final String JavaDoc LOADER = "org.webdocwf.util.loader.Loader";
88     /**
89     * The method executing the task
90     **/

91     public void execute() throws BuildException {
92
93         try {
94             //find java.exe
95
String JavaDoc sep = System.getProperty("file.separator");
96             JAVAEXE = System.getProperty("java.home") + sep + "bin" + sep + "java";
97
98             if (this.loadJobFileName == null) {
99                 throw (new BuildException("loadJobFileName attribute must be set! ", location));
100             } else {
101
102                 if (this.additionalPath != null) {
103                     this.strLoaderExec += "-classpath " + this.additionalPath.substring(0, this.additionalPath.length() - 1) + " ";
104                 }
105
106                 this.strLoaderExec += LOADER + " ";
107
108                 if (this.mode != null) {
109                     if (this.mode.equalsIgnoreCase("none")) {
110                         this.strLoaderExec += "-m none ";
111                     } else if (this.mode.equalsIgnoreCase("normal")) {
112                         this.strLoaderExec += "-m normal ";
113                     } else if (this.mode.equalsIgnoreCase("full")) {
114                         this.strLoaderExec += "-m full ";
115                     }
116                 }
117                 if (this.restartIndicator != null && this.restartIndicator.equalsIgnoreCase("yes")) {
118                     this.strLoaderExec += "-r ";
119                 }
120
121                 if (this.userID != null) {
122                     this.strLoaderExec += "-u " + this.userID + " ";
123                 }
124
125                 if (this.variables != null) {
126                     if (this.variables.endsWith(";"))
127                         this.variables = this.variables.substring(0, this.variables.length() - 1);
128                     this.strLoaderExec += "-v " + this.variables + " ";
129                 }
130
131                 if (this.logDirName != null) {
132                     this.strLoaderExec += "-l " + this.logDirName + " ";
133                 }
134
135                 if (this.logFileName != null) {
136                     this.strLoaderExec += "-f " + this.logFileName + " ";
137                 }
138
139                 if (this.vendorFileName != null) {
140                     this.strLoaderExec += "-d " + this.vendorFileName + " ";
141                 }
142
143                 if (this.onErrorContinue != null && this.onErrorContinue.equalsIgnoreCase("true")) {
144                     this.strLoaderExec += "-e ";
145                 }
146
147                 if (this.commitCount != null) {
148                     this.strLoaderExec += "-c " + this.commitCount + " ";
149                 }
150                 if (this.returnCode != null) {
151                     this.strLoaderExec += "-rc " + this.returnCode + " ";
152                 }
153                 if (this.pathToConfFile != null) {
154                     this.strLoaderExec += "-cjs " + this.pathToConfFile + " ";
155                 }
156                 if (this.tableNames != null) {
157                     if (this.tableNames.endsWith(";"))
158                         this.tableNames = this.tableNames.substring(0, this.tableNames.length() - 1);
159                     this.strLoaderExec += "-it " + this.tableNames + " ";
160                 }
161                                 
162
163                 this.strLoaderExec += this.loadJobFileName;
164
165                 String JavaDoc command = JAVAEXE + " " + this.strLoaderExec;
166                 Process JavaDoc process = Runtime.getRuntime().exec(command);
167                 java.io.InputStream JavaDoc inputstream = process.getInputStream();
168                 BufferedReader JavaDoc bufferedreader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(inputstream));
169                 java.io.InputStream JavaDoc inputstream1 = process.getErrorStream();
170                 BufferedReader JavaDoc bufferedreader1 = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(inputstream1));
171                 (new ErrorReader(bufferedreader1)).start();
172                 String JavaDoc s1;
173                 while ((s1 = bufferedreader.readLine()) != null) {
174                     System.out.println(s1);
175
176                 }
177                 int k = process.waitFor();
178                 if (k != 0)
179                     throw (new BuildException("Loader: Error occured!", location));
180             }
181         } catch (Throwable JavaDoc le) {
182             System.out.println(le);
183         }
184
185     }
186
187     /**
188     * The setter for the "loadJob" attribute
189     **/

190     public void setLoadJob(String JavaDoc msg) {
191         this.loadJobFileName = msg;
192     }
193
194     /**
195     * The setter for the "mode" attribute
196     **/

197     public void setMode(String JavaDoc msg) {
198         this.mode = msg;
199     }
200
201     /**
202     * The setter for the "userID" attribute
203     **/

204     public void setUserID(String JavaDoc msg) {
205         this.userID = msg;
206     }
207
208     /**
209     * The setter for the "logDir" attribute
210     **/

211     public void setLogDir(String JavaDoc msg) {
212         this.logDirName = msg;
213     }
214
215     /**
216     * The setter for the "logFile" attribute
217     **/

218     public void setLogFile(String JavaDoc msg) {
219         this.logFileName = msg;
220     }
221
222     /**
223     * The setter for the "restartIndicator" attribute
224     **/

225     public void setRestartIndicator(String JavaDoc msg) {
226         this.restartIndicator = msg;
227     }
228
229     /**
230     * The setter for the "vendorFile" attribute
231     **/

232     public void setVendorFile(String JavaDoc msg) {
233         this.vendorFileName = msg;
234     }
235
236     /**
237     * The setter for the "onErrorContinue" attribute
238     **/

239     public void setOnErrorContinue(String JavaDoc msg) {
240         this.onErrorContinue = msg;
241     }
242
243     /**
244     * The setter for the "commitCount" attribute
245     **/

246     public void setCommitCount(String JavaDoc msg) {
247         this.commitCount = msg;
248     }
249
250     /**
251     * The setter for the "returnCode" attribute
252     **/

253     public void setReturnCode(String JavaDoc rc) {
254         this.returnCode = rc;
255     }
256
257     /**
258     * The setter for the "AdditionalPaths" tag
259     **/

260     public void addConfiguredAdditionalPaths(AdditionalPaths anInner) {
261         this.additionalPath = anInner.additionalPaths.substring(0, anInner.additionalPaths.indexOf("null")) + anInner.additionalPaths.substring(anInner.additionalPaths.indexOf("null") + 4, anInner.additionalPaths.length());
262     }
263
264     /**
265     * The setter for the "Variables" tag
266     **/

267     public void addConfiguredVariables(Variables anInner) {
268         this.variables = anInner.variables.substring(0, anInner.variables.indexOf("null")) + anInner.variables.substring(anInner.variables.indexOf("null") + 4, anInner.variables.length());
269     }
270
271     /**
272      * The setter for the "pathToConfFile" attribute
273      */

274     public void setPathToConfFile(String JavaDoc string) {
275         this.pathToConfFile = string;
276     }
277
278     /**
279     * The setter for the "tableNames" attribute
280      */

281     public void setTableNames(String JavaDoc string) {
282         this.tableNames = string;
283     }
284
285 }
286
Popular Tags