📄 octopusloaderthread.java
字号:
/*
LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
Copyright (C) 2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.webdocwf.util.loader.wizard;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import javax.swing.JTextArea;
import org.webdocwf.util.loader.BufferOctopusClass;
import org.webdocwf.util.loader.Loader;
import org.webdocwf.util.loader.LoaderException;
import org.webdocwf.util.loader.ReturnCode;
/**
* ExecOctopusThread class execute thread which control Octopus application
* @author Radoslav Dutina
* @version 1.0
*/
public class OctopusLoaderThread
extends Thread {
private OctopusLoaderData initData;
// TraceDialog td = null; //trace dialog of this Thread
private JTextArea td;
private String errorMsg = null;
/**
* Construct the objecto of ExecOctopusThread class with associated parameters
* @param traceArea is desktop frame of wizard application
* @param initData is object which contain input parameters of wizard application
* @param errorMsg is error message
*/
public OctopusLoaderThread(OctopusLoaderData initData,
String errorMsg,JTextArea traceArea) {
this.initData = initData;
this.errorMsg = errorMsg;
td = traceArea;
// desktop.add(td);
}
/**
* This method append line in to trace area
* @param s is value which to be set
*/
public void appendLine(String s) {
td.append(s);
td.getCaret().setDot(td.getText().length() - 1);
}
/**
* Run the thread
*/
public void run() {
td.setVisible(true);
// td.setDefaultFocus();
if (errorMsg != null) {
appendLine(errorMsg + "\n");
// td.setButtonEnabled();
// td.setButtonName("Open");
}
else {
OctopusLoader octopus = null;
OctopusThread octopusThread = null;
try {
octopus = new OctopusLoader(initData);
String[] process = octopus.generateAll();
if (process.length != 0) {
BufferOctopusClass.getInstance();
BufferOctopusClass.getInstance().setUsed();
octopusThread = new OctopusThread(process);
octopusThread.start();
while (octopusThread.isAlive()) {
String value = BufferOctopusClass.getInstance().readFromBuffer();
if (value.indexOf("***TogetherGroop***") == -1)
appendLine(value + "\n");
else
break;
}
// setButtonEnabled();
}
else {
appendLine("Some error is occur! " + "\n" +"Application build fails!");
}
// setButtonName("Open");
// td.setTitle("Building Octopus Application(Done)");
}
catch (Exception e) {
// td.setTitle("Building Octopus Application(ERROR)");
String message=e.getMessage();
if(message.indexOf(-1)!=-1||message.indexOf(0)!=-1)
message="Application build fails!";
BufferOctopusClass.getInstance().writeToBuffer(message + "\n");
BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***");
BufferOctopusClass.getInstance().empty();
// td.setButtonEnabled();
// td.setButtonName("Open");
e.printStackTrace(System.out);
}
BufferOctopusClass.getInstance().empty();
}
}
/**
* This class creates new thread
*/
class OctopusThread
extends Thread {
private String[] args;
/**
* Initialise the thread
* @param args represents the arguments
*/
public OctopusThread(String[] args) {
this.args = args;
}
/**
* Run the thread
*/
public void run() {
String loadJobFileName = null;
String mode = null;
String userID = null;
String logDirName = null;
String logFileName = null;
boolean restartIndicator = false;
Map variableValues = null;
String strVariableValues = null;
String vendorFileName = null;
boolean onErrorContinue = false;
String additionalPaths = null;
String includeTables[]=null;
String confJarStructure=null;
int defaultReturnCode = 1;
int commitCount = 100;
if (args.length > 0 && args.length < 24) {
loadJobFileName = args[args.length - 1];
for (int i = 0; i < args.length - 1; i = i + 1) {
if (args[i].equalsIgnoreCase("-m"))
mode = args[++i];
else if (args[i].equalsIgnoreCase("-r"))
restartIndicator = true;
else if (args[i].equalsIgnoreCase("-u"))
userID = args[++i];
else if (args[i].equalsIgnoreCase("-l"))
logDirName = args[++i];
else if (args[i].equalsIgnoreCase("-f"))
logFileName = args[++i];
else if (args[i].equalsIgnoreCase("-d"))
vendorFileName = args[++i];
else if (args[i].equalsIgnoreCase("-e")){
String value=args[++i];
if(value.equalsIgnoreCase("true"))
onErrorContinue = true;
else
onErrorContinue = false;
}else if (args[i].equalsIgnoreCase("-p"))
additionalPaths = args[++i];
else if (args[i].equalsIgnoreCase("-c"))
commitCount = (new Integer(args[++i])).intValue();
else if (args[i].equalsIgnoreCase("-v")) {
strVariableValues = args[++i];
variableValues = new HashMap(convertToMap(strVariableValues));
}
else if (args[i].equalsIgnoreCase("-rc")) {
defaultReturnCode = (new Integer(args[++i])).intValue();
ReturnCode.isParameter = true;
}
else if (args[i].equalsIgnoreCase("-cjs"))
confJarStructure = args[++i];
else if (args[i].equalsIgnoreCase("-it")) {
String array=args[++i];
StringTokenizer st=new StringTokenizer(array,";");
includeTables=new String[st.countTokens()];
int pos=0;
while(st.hasMoreTokens()){
includeTables[pos]=st.nextToken();
pos++;
}
}
}
}
else
printUsage();
Loader l = new Loader(loadJobFileName, mode, userID, logDirName,
logFileName, restartIndicator, variableValues,
vendorFileName,onErrorContinue,additionalPaths, commitCount,
defaultReturnCode, includeTables,confJarStructure);
try {
l.load();
}
catch (LoaderException le) {
// td.setTitle("Building Octopus Application(ERROR)");
// td.setButtonEnabled();
// td.setButtonName("Open");
BufferOctopusClass.getInstance().writeToBuffer("Check input parameters!" + "\n");
try {
Thread.sleep(100);
BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***");
}
catch (Exception ex) {
appendLine(ex.getMessage());
}
l = null;
return;
} catch (Throwable th) {
// td.setTitle("Building Octopus Application(ERROR)");
// td.setButtonEnabled();
// td.setButtonName("Open");
BufferOctopusClass.getInstance().writeToBuffer(th.getMessage());
try {
Thread.sleep(100);
BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***");
}
catch (Exception ex) {
appendLine(ex.getMessage());
}
th.printStackTrace(System.out);
l = null;
return;
}
try{
Thread.sleep(1000);
BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***");
}catch (Exception ex){
appendLine(ex.getMessage());
}
l = null;
return;
}
/**
* put your documentation comment here
*/
public void printUsage() {
System.out.println(
"Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
BufferOctopusClass.getInstance().writeToBuffer(
"Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
System.out.println(" Options:");
BufferOctopusClass.getInstance().writeToBuffer(" Options:");
System.out.println(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
BufferOctopusClass.getInstance().writeToBuffer(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
System.out.println(" -r starts the Loader in restart mode after abnormal termination in a prior execution. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -r starts the Loader in restart mode after abnormal termination in a prior execution. \n");
System.out.println(" -u defines the current UserID used in UserID value columns. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -u defines the current UserID used in UserID value columns. \n");
System.out.println(" -v defines variables used in variable columns. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -v defines variables used in variable columns. \n");
System.out.println(" -l defines the logfile directory. The default is the current working directory. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -v defines variables used in variable columns. \n");
System.out.println(" -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
System.out.println(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n");
System.out.println(" -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n");
System.out.println(" -p Extend the classpath with additional paths \n");
BufferOctopusClass.getInstance().writeToBuffer(" -p Extend the classpath with additional paths \n");
System.out.println(" -c Sets the default commit count. System default is '100'. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -c Sets the default commit count. System default is '100'. \n");
System.out.println(" -rc Sets the default error return code. System default is '1'. \n");
BufferOctopusClass.getInstance().writeToBuffer(" -rc Sets the default error return code. System default is '1'. \n");
System.out.println(" -it Sets the table names which will be proccesed ");
BufferOctopusClass.getInstance().writeToBuffer(" -it Sets the table names which will be proccesed ");
}
/**
* put your documentation comment here
* @param values represents map values
* @return those values
*/
private Map convertToMap(String values) {
Map mapValues = new HashMap();
int i = values.indexOf(";");
int k = 0;
String part = new String(values);
if (i != -1) {
while (i != -1) {
part = new String(values.substring(k, k + i));
int j = part.indexOf("=");
String strObject = part.substring(0, j);
String strValue = part.substring(j + 1);
if (strValue.equals(""))
strValue = null;
mapValues.put(strObject, strValue);
k += i + 1;
i = values.substring(k).indexOf(";");
}
if (! (values.substring(k).trim().equals("") ||
values.substring(k).trim().equals(";"))) {
part = new String(values.substring(k));
int j = part.indexOf("=");
String strObject = part.substring(0, j);
String strValue = part.substring(j + 1);
if (strValue.equals(""))
strValue = null;
mapValues.put(strObject, strValue);
}
}
else {
int j = values.indexOf("=");
String strObject = values.substring(k, j);
String strValue = values.substring(j + 1);
if (strValue.equals(""))
strValue = null;
mapValues.put(strObject, strValue);
}
return mapValues;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -