1 29 30 package org.webdocwf.util.loader.task; 31 32 import java.io.BufferedReader ; 33 import java.io.InputStreamReader ; 34 35 import org.apache.tools.ant.BuildException; 36 import org.apache.tools.ant.Task; 37 38 65 public class LoaderTask extends Task { 66 private String loadJobFileName; 67 private String mode; 68 private String restartIndicator; 69 private String userID; 70 private String logDirName; 71 private String logFileName; 72 private String vendorFileName; 73 private String onErrorContinue; 74 private String commitCount; 75 private String tableNames; 76 private String additionalPaths; 77 private String additionalPath; 78 79 private String variables; 80 81 private String strLoaderExec = ""; 82 83 private String returnCode; 84 private String pathToConfFile; 85 86 private String JAVAEXE = "java"; 87 private final String LOADER = "org.webdocwf.util.loader.Loader"; 88 91 public void execute() throws BuildException { 92 93 try { 94 String 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 command = JAVAEXE + " " + this.strLoaderExec; 166 Process process = Runtime.getRuntime().exec(command); 167 java.io.InputStream inputstream = process.getInputStream(); 168 BufferedReader bufferedreader = new BufferedReader (new InputStreamReader (inputstream)); 169 java.io.InputStream inputstream1 = process.getErrorStream(); 170 BufferedReader bufferedreader1 = new BufferedReader (new InputStreamReader (inputstream1)); 171 (new ErrorReader(bufferedreader1)).start(); 172 String 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 le) { 182 System.out.println(le); 183 } 184 185 } 186 187 190 public void setLoadJob(String msg) { 191 this.loadJobFileName = msg; 192 } 193 194 197 public void setMode(String msg) { 198 this.mode = msg; 199 } 200 201 204 public void setUserID(String msg) { 205 this.userID = msg; 206 } 207 208 211 public void setLogDir(String msg) { 212 this.logDirName = msg; 213 } 214 215 218 public void setLogFile(String msg) { 219 this.logFileName = msg; 220 } 221 222 225 public void setRestartIndicator(String msg) { 226 this.restartIndicator = msg; 227 } 228 229 232 public void setVendorFile(String msg) { 233 this.vendorFileName = msg; 234 } 235 236 239 public void setOnErrorContinue(String msg) { 240 this.onErrorContinue = msg; 241 } 242 243 246 public void setCommitCount(String msg) { 247 this.commitCount = msg; 248 } 249 250 253 public void setReturnCode(String rc) { 254 this.returnCode = rc; 255 } 256 257 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 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 274 public void setPathToConfFile(String string) { 275 this.pathToConfFile = string; 276 } 277 278 281 public void setTableNames(String string) { 282 this.tableNames = string; 283 } 284 285 } 286 | Popular Tags |