View Javadoc
1 /* 2 LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus. 3 Copyright (C) 2003 Together 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 This library is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 Lesser General Public License for more details. 12 You should have received a copy of the GNU Lesser General Public 13 License along with this library; if not, write to the Free Software 14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 */ 16 17 package org.webdocwf.util.loader.wizard; 18 19 import java.util.HashMap; 20 import java.util.Map; 21 import java.util.StringTokenizer; 22 23 import javax.swing.JTextArea; 24 25 import org.webdocwf.util.loader.BufferOctopusClass; 26 import org.webdocwf.util.loader.Loader; 27 import org.webdocwf.util.loader.LoaderException; 28 import org.webdocwf.util.loader.ReturnCode; 29 30 /*** 31 * ExecOctopusThread class execute thread which control Octopus application 32 * @author Radoslav Dutina 33 * @version 1.0 34 */ 35 public class OctopusLoaderThread 36 extends Thread { 37 private OctopusLoaderData initData; 38 // TraceDialog td = null; //trace dialog of this Thread 39 private JTextArea td; 40 private String errorMsg = null; 41 42 /*** 43 * Construct the objecto of ExecOctopusThread class with associated parameters 44 * @param traceArea is desktop frame of wizard application 45 * @param initData is object which contain input parameters of wizard application 46 * @param errorMsg is error message 47 */ 48 public OctopusLoaderThread(OctopusLoaderData initData, 49 String errorMsg,JTextArea traceArea) { 50 this.initData = initData; 51 this.errorMsg = errorMsg; 52 td = traceArea; 53 // desktop.add(td); 54 } 55 56 57 /*** 58 * This method append line in to trace area 59 * @param s is value which to be set 60 */ 61 public void appendLine(String s) { 62 td.append(s); 63 td.getCaret().setDot(td.getText().length() - 1); 64 } 65 66 /*** 67 * Run the thread 68 */ 69 public void run() { 70 td.setVisible(true); 71 // td.setDefaultFocus(); 72 if (errorMsg != null) { 73 appendLine(errorMsg + "\n"); 74 // td.setButtonEnabled(); 75 // td.setButtonName("Open"); 76 77 } 78 else { 79 OctopusLoader octopus = null; 80 OctopusThread octopusThread = null; 81 try { 82 octopus = new OctopusLoader(initData); 83 String[] process = octopus.generateAll(); 84 if (process.length != 0) { 85 BufferOctopusClass.getInstance(); 86 BufferOctopusClass.getInstance().setUsed(); 87 88 octopusThread = new OctopusThread(process); 89 octopusThread.start(); 90 91 while (octopusThread.isAlive()) { 92 String value = BufferOctopusClass.getInstance().readFromBuffer(); 93 if (value.indexOf("***TogetherGroop***") == -1) 94 appendLine(value + "\n"); 95 else 96 break; 97 } 98 // setButtonEnabled(); 99 } 100 else { 101 appendLine("Some error is occur! " + "\n" +"Application build fails!"); 102 } 103 104 // setButtonName("Open"); 105 // td.setTitle("Building TDT Application(Done)"); 106 } 107 catch (Exception e) { 108 // td.setTitle("Building TDT Application(ERROR)"); 109 String message=e.getMessage(); 110 if(message.indexOf(-1)!=-1||message.indexOf(0)!=-1) 111 message="Application build fails!"; 112 113 BufferOctopusClass.getInstance().writeToBuffer(message + "\n"); 114 BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***"); 115 BufferOctopusClass.getInstance().empty(); 116 // td.setButtonEnabled(); 117 // td.setButtonName("Open"); 118 e.printStackTrace(System.out); 119 } 120 BufferOctopusClass.getInstance().empty(); 121 } 122 } 123 124 /*** 125 * This class creates new thread 126 */ 127 class OctopusThread 128 extends Thread { 129 private String[] args; 130 131 /*** 132 * Initialise the thread 133 * @param args represents the arguments 134 */ 135 public OctopusThread(String[] args) { 136 this.args = args; 137 } 138 139 /*** 140 * Run the thread 141 */ 142 public void run() { 143 String loadJobFileName = null; 144 String mode = null; 145 String userID = null; 146 String logDirName = null; 147 String logFileName = null; 148 boolean restartIndicator = false; 149 Map variableValues = null; 150 String strVariableValues = null; 151 String vendorFileName = null; 152 boolean onErrorContinue = false; 153 String additionalPaths = null; 154 String includeTables[]=null; 155 String confJarStructure=null; 156 int defaultReturnCode = 1; 157 int commitCount = 100; 158 if (args.length > 0 && args.length < 24) { 159 loadJobFileName = args[args.length - 1]; 160 for (int i = 0; i < args.length - 1; i = i + 1) { 161 if (args[i].equalsIgnoreCase("-m")) 162 mode = args[++i]; 163 else if (args[i].equalsIgnoreCase("-r")) 164 restartIndicator = true; 165 else if (args[i].equalsIgnoreCase("-u")) 166 userID = args[++i]; 167 else if (args[i].equalsIgnoreCase("-l")) 168 logDirName = args[++i]; 169 else if (args[i].equalsIgnoreCase("-f")) 170 logFileName = args[++i]; 171 else if (args[i].equalsIgnoreCase("-d")) 172 vendorFileName = args[++i]; 173 else if (args[i].equalsIgnoreCase("-e")){ 174 String value=args[++i]; 175 if(value.equalsIgnoreCase("true")) 176 onErrorContinue = true; 177 else 178 onErrorContinue = false; 179 }else if (args[i].equalsIgnoreCase("-p")) 180 additionalPaths = args[++i]; 181 else if (args[i].equalsIgnoreCase("-c")) 182 commitCount = (new Integer(args[++i])).intValue(); 183 else if (args[i].equalsIgnoreCase("-v")) { 184 strVariableValues = args[++i]; 185 variableValues = new HashMap(convertToMap(strVariableValues)); 186 } 187 else if (args[i].equalsIgnoreCase("-rc")) { 188 defaultReturnCode = (new Integer(args[++i])).intValue(); 189 ReturnCode.isParameter = true; 190 } 191 else if (args[i].equalsIgnoreCase("-cjs")) 192 confJarStructure = args[++i]; 193 else if (args[i].equalsIgnoreCase("-it")) { 194 String array=args[++i]; 195 StringTokenizer st=new StringTokenizer(array,";"); 196 includeTables=new String[st.countTokens()]; 197 int pos=0; 198 while(st.hasMoreTokens()){ 199 includeTables[pos]=st.nextToken(); 200 pos++; 201 } 202 } 203 } 204 } 205 else 206 printUsage(); 207 Loader l = new Loader(loadJobFileName, mode, userID, logDirName, 208 logFileName, restartIndicator, variableValues, 209 vendorFileName,onErrorContinue,additionalPaths, commitCount, 210 defaultReturnCode, includeTables,confJarStructure); 211 212 try { 213 l.load(); 214 } 215 catch (LoaderException le) { 216 // td.setTitle("Building TDT Application(ERROR)"); 217 // td.setButtonEnabled(); 218 // td.setButtonName("Open"); 219 BufferOctopusClass.getInstance().writeToBuffer("LoaderException: " + "\n"); 220 BufferOctopusClass.getInstance().writeToBuffer(le.getStackTraceAsString() + "\n"); 221 try { 222 Thread.sleep(100); 223 BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***"); 224 } 225 catch (Exception ex) { 226 appendLine(ex.getMessage()); 227 } 228 l = null; 229 return; 230 } catch (Throwable th) { 231 // td.setTitle("Building TDT Application(ERROR)"); 232 // td.setButtonEnabled(); 233 // td.setButtonName("Open"); 234 BufferOctopusClass.getInstance().writeToBuffer(th.getMessage()); 235 try { 236 Thread.sleep(100); 237 BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***"); 238 } 239 catch (Exception ex) { 240 appendLine(ex.getMessage()); 241 } 242 th.printStackTrace(System.out); 243 l = null; 244 return; 245 } 246 try{ 247 Thread.sleep(1000); 248 BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***"); 249 }catch (Exception ex){ 250 appendLine(ex.getMessage()); 251 } 252 l = null; 253 return; 254 } 255 256 /*** 257 * put your documentation comment here 258 */ 259 public void printUsage() { 260 System.out.println( 261 "Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename"); 262 BufferOctopusClass.getInstance().writeToBuffer( 263 "Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename"); 264 System.out.println(" Options:"); 265 BufferOctopusClass.getInstance().writeToBuffer(" Options:"); 266 System.out.println(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'."); 267 BufferOctopusClass.getInstance().writeToBuffer(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'."); 268 System.out.println(" -r starts the Loader in restart mode after abnormal termination in a prior execution. \n"); 269 BufferOctopusClass.getInstance().writeToBuffer(" -r starts the Loader in restart mode after abnormal termination in a prior execution. \n"); 270 System.out.println(" -u defines the current UserID used in UserID value columns. \n"); 271 BufferOctopusClass.getInstance().writeToBuffer(" -u defines the current UserID used in UserID value columns. \n"); 272 System.out.println(" -v defines variables used in variable columns. \n"); 273 BufferOctopusClass.getInstance().writeToBuffer(" -v defines variables used in variable columns. \n"); 274 System.out.println(" -l defines the logfile directory. The default is the current working directory. \n"); 275 BufferOctopusClass.getInstance().writeToBuffer(" -v defines variables used in variable columns. \n"); 276 System.out.println(" -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n"); 277 BufferOctopusClass.getInstance().writeToBuffer(" -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n"); 278 System.out.println(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n"); 279 BufferOctopusClass.getInstance().writeToBuffer(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n"); 280 System.out.println(" -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n"); 281 BufferOctopusClass.getInstance().writeToBuffer(" -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n"); 282 System.out.println(" -p Extend the classpath with additional paths \n"); 283 BufferOctopusClass.getInstance().writeToBuffer(" -p Extend the classpath with additional paths \n"); 284 System.out.println(" -c Sets the default commit count. System default is '100'. \n"); 285 BufferOctopusClass.getInstance().writeToBuffer(" -c Sets the default commit count. System default is '100'. \n"); 286 System.out.println(" -rc Sets the default error return code. System default is '1'. \n"); 287 BufferOctopusClass.getInstance().writeToBuffer(" -rc Sets the default error return code. System default is '1'. \n"); 288 System.out.println(" -it Sets the table names which will be proccesed "); 289 BufferOctopusClass.getInstance().writeToBuffer(" -it Sets the table names which will be proccesed "); 290 291 } 292 293 /*** 294 * put your documentation comment here 295 * @param values represents map values 296 * @return those values 297 */ 298 private Map convertToMap(String values) { 299 Map mapValues = new HashMap(); 300 int i = values.indexOf(";"); 301 int k = 0; 302 String part = new String(values); 303 if (i != -1) { 304 while (i != -1) { 305 part = new String(values.substring(k, k + i)); 306 int j = part.indexOf("="); 307 String strObject = part.substring(0, j); 308 String strValue = part.substring(j + 1); 309 if (strValue.equals("")) 310 strValue = null; 311 mapValues.put(strObject, strValue); 312 k += i + 1; 313 i = values.substring(k).indexOf(";"); 314 } 315 if (! (values.substring(k).trim().equals("") || 316 values.substring(k).trim().equals(";"))) { 317 part = new String(values.substring(k)); 318 int j = part.indexOf("="); 319 String strObject = part.substring(0, j); 320 String strValue = part.substring(j + 1); 321 if (strValue.equals("")) 322 strValue = null; 323 mapValues.put(strObject, strValue); 324 } 325 } 326 else { 327 int j = values.indexOf("="); 328 String strObject = values.substring(k, j); 329 String strValue = values.substring(j + 1); 330 if (strValue.equals("")) 331 strValue = null; 332 mapValues.put(strObject, strValue); 333 } 334 return mapValues; 335 } 336 } 337 }

This page was automatically generated by Maven