View Javadoc
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 31 package org.webdocwf.util.loader.task; 32 33 import org.apache.tools.ant.Task; 34 import java.io.*; 35 import java.io.File; 36 import java.io.IOException; 37 import org.apache.tools.ant.taskdefs.Java; 38 import org.apache.tools.ant.BuildException; 39 40 41 42 /*** 43 * <p> 44 * Loader Task class extends jakarta-ant Task class and uses to start Loader 45 * application as a jakarta-ant task in build.xml file. 46 * </p> 47 * <p> 48 * Attributes of LoaderTask represents Loader parameters:<br> 49 * <br> 50 * mode attribute - defines mode <br> 51 * restartIndicator attribute - defines restart <br> 52 * userID attribute - defines user ID <br> 53 * logDir attribute - defines log directory <br> 54 * logFile attribute - defines log file <br> 55 * vendorFile attribute - defines vendor file <br> 56 * onErrorContinue attribute - defines continue or not on error<br> 57 * commitCount attribute - defines commit count<br> 58 * loadJob attribute - defines loader job<br> 59 * onErrorContinue attribute - defines continue or not on error<br> 60 * additionalPaths tag - defines single or group of additionalPath tags<br> 61 * additionalPath tag - defines tag with path attribute <br> 62 * path attribute - defines classpath<br> 63 * variables tag - defines single or group of variable tags<br> 64 * variable tag - defines tag with path attribute <br> 65 * name attribute - defines variable name<br> 66 * value attribute - defines variable value<br> 67 * <br> 68 * </p> 69 **/ 70 public class LoaderTask extends Task { 71 private String loadJobFileName; 72 private String mode; 73 private String userID; 74 private String logDirName; 75 private String logFileName; 76 private String restartIndicator; 77 private String vendorFileName; 78 private String onErrorContinue; 79 private String additionalPaths; 80 private String commitCount; 81 private String strLoaderExec = ""; 82 private String additionalPath; 83 private String variables; 84 private String returnCode; 85 86 87 private final String JAVAEXE = "java"; 88 private final String LOADER = "org.webdocwf.util.loader.Loader"; 89 /*** 90 * The method executing the task 91 **/ 92 public void execute() throws BuildException { 93 94 try{ 95 96 if(this.loadJobFileName==null) { 97 throw (new BuildException("loadJobFileName attribute must be set! ",location)); 98 } 99 else { 100 101 if(this.additionalPath!=null) { 102 this.strLoaderExec += "-classpath "+this.additionalPath.substring(0, this.additionalPath.length()-1)+" "; 103 } 104 105 this.strLoaderExec += LOADER+" "; 106 107 if(this.mode!=null) { 108 if(this.mode.equalsIgnoreCase("none")) { 109 this.strLoaderExec += "-m none "; 110 } else if(this.mode.equalsIgnoreCase("normal")) { 111 this.strLoaderExec += "-m normal "; 112 } else if(this.mode.equalsIgnoreCase("full")) { 113 this.strLoaderExec += "-m full "; 114 } 115 } 116 if(this.restartIndicator!=null && this.restartIndicator.equalsIgnoreCase("yes")) { 117 this.strLoaderExec += "-r "; 118 } 119 120 if(this.userID!=null) { 121 this.strLoaderExec += "-u "+this.userID+" "; 122 } 123 124 if(this.variables!=null) { 125 if(this.variables.endsWith(";")) 126 this.variables=this.variables.substring(0, this.variables.length()-1); 127 this.strLoaderExec += "-v "+this.variables+" "; 128 } 129 130 if(this.logDirName!=null) { 131 this.strLoaderExec += "-l "+this.logDirName+" "; 132 } 133 134 if(this.logFileName!=null) { 135 this.strLoaderExec += "-f "+this.logFileName+" "; 136 } 137 138 if(this.vendorFileName!=null) { 139 this.strLoaderExec += "-d "+this.vendorFileName+" "; 140 } 141 142 if(this.onErrorContinue!=null && this.onErrorContinue.equalsIgnoreCase("true")) { 143 this.strLoaderExec += "-e "; 144 } 145 146 if(this.commitCount!=null) { 147 this.strLoaderExec += "-c "+this.commitCount+" "; 148 } 149 if(this.returnCode!=null) { 150 this.strLoaderExec += "-rc "+this.returnCode+" "; 151 } 152 153 154 this.strLoaderExec += this.loadJobFileName; 155 156 String command = JAVAEXE+" "+this.strLoaderExec; 157 Process process = Runtime.getRuntime().exec(command); 158 java.io.InputStream inputstream = process.getInputStream(); 159 BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream)); 160 java.io.InputStream inputstream1 = process.getErrorStream(); 161 BufferedReader bufferedreader1 = new BufferedReader(new InputStreamReader(inputstream1)); 162 (new ErrorReader(bufferedreader1)).start(); 163 String s1; 164 while((s1 = bufferedreader.readLine()) != null) 165 { 166 System.out.println(s1); 167 168 } 169 int k = process.waitFor(); 170 if (k!=0) 171 throw (new BuildException("Loader: Error occured!",location)); 172 } 173 }catch (Throwable le) { 174 System.out.println(le); 175 } 176 177 } 178 179 180 /*** 181 * The setter for the "loadJob" attribute 182 **/ 183 public void setLoadJob(String msg) { 184 this.loadJobFileName = msg; 185 } 186 187 /*** 188 * The setter for the "mode" attribute 189 **/ 190 public void setMode(String msg) { 191 this.mode = msg; 192 } 193 194 /*** 195 * The setter for the "userID" attribute 196 **/ 197 public void setUserID(String msg) { 198 this.userID = msg; 199 } 200 201 /*** 202 * The setter for the "logDir" attribute 203 **/ 204 public void setLogDir(String msg) { 205 this.logDirName = msg; 206 } 207 208 /*** 209 * The setter for the "logFile" attribute 210 **/ 211 public void setLogFile(String msg) { 212 this.logFileName = msg; 213 } 214 215 /*** 216 * The setter for the "restartIndicator" attribute 217 **/ 218 public void setRestartIndicator(String msg) { 219 this.restartIndicator = msg; 220 } 221 222 /*** 223 * The setter for the "vendorFile" attribute 224 **/ 225 public void setVendorFile(String msg) { 226 this.vendorFileName = msg; 227 } 228 229 /*** 230 * The setter for the "onErrorContinue" attribute 231 **/ 232 public void setOnErrorContinue(String msg) { 233 this.onErrorContinue = msg; 234 } 235 236 /*** 237 * The setter for the "commitCount" attribute 238 **/ 239 public void setCommitCount(String msg) { 240 this.commitCount = msg; 241 } 242 243 /*** 244 * The setter for the "returnCode" attribute 245 **/ 246 public void setReturnCode(String rc) { 247 this.returnCode = rc; 248 } 249 250 /*** 251 * The setter for the "AdditionalPaths" tag 252 **/ 253 public void addConfiguredAdditionalPaths(AdditionalPaths anInner) { 254 this.additionalPath = anInner.additionalPaths.substring(0,anInner.additionalPaths.indexOf("null"))+ 255 anInner.additionalPaths.substring(anInner.additionalPaths.indexOf("null")+4, 256 anInner.additionalPaths.length()); 257 } 258 259 /*** 260 * The setter for the "Variables" tag 261 **/ 262 public void addConfiguredVariables(Variables anInner) { 263 this.variables = anInner.variables.substring(0,anInner.variables.indexOf("null"))+ 264 anInner.variables.substring(anInner.variables.indexOf("null")+4, 265 anInner.variables.length()); 266 } 267 268 269 } 270

This page automatically generated by Maven