?? mainframe.java
字號:
JPanel p = new JPanel();
p.setLayout(new FlowLayout(FlowLayout.LEFT));
p.setBorder(new EtchedBorder());
p.add(new JLabel("Param " + (i + 1) + ":"));
JTextField tf = new JTextField("", 10);
tf.setEditable(false);
tf.setText(para.getQName().getLocalPart());
p.add(tf);
p.add(new JLabel("Type:"));
tf = new JTextField("", 10);
tf.setEditable(false);
String wsdlType = para.getType().getQName().getLocalPart();
String mode = invoker[0].getParameterModeString(para);
tf.setText(mode + " " + wsdlType);
p.add(tf);
if (para.getMode() != Parameter.OUT) {
// for IN and INOUT parameters
p.add(new JLabel("Value:"));
txtParameterValues[i] = new JTextField("", 10);
p.add(txtParameterValues[i]);
JButton btnChoose = new JButton("...");
btnChoose
.addActionListener(new MainFrame_btnChoose_actionAdapter(
this, i));
p.add(btnChoose);
} else {
txtParameterValues[i] = null;
}
paneCenter.add(p);
}
}
validate();
repaint();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getClass().getName() + ": "
+ ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
void btnTest_actionPerformed(ActionEvent e) {
// Begin invoking or testing
if (invoker == null || serviceName == null || portName == null
|| operationName == null || parameters == null) {
JOptionPane.showMessageDialog(this,
"Please specify location/service/operation and "
+ "assign values to all the parameters "
+ "before invoking/testing.", "WARNING",
JOptionPane.WARNING_MESSAGE);
return;
}
if (chbModel.isSelected()) {// 用戶選擇的是直接傳送內容
MainFrame_btnTest_Thread runnable = new MainFrame_btnTest_Thread();
Thread thread = new Thread(runnable);
thread.start();
} else {// 用戶選擇的是單個文件或者是整個目錄
int threads = 0;
try
{
threads = Integer.parseInt(txtLocation.getText());
}
catch(NumberFormatException ex1)
{
threads = 0;
}
if(threads <= 0)
{
JOptionPane.showMessageDialog(null, "Invoke threads must be larger than zero.", "WARNING", 2);
return;
}
runFD(threads);
}
}
class MainFrame_btnTest_Thread implements Runnable {
public void run() {
// 判斷調用的次數是否符合邏輯,必須大于0.
int times = 0;
try {
times = Integer.parseInt(txtTimes.getText());
} catch (NumberFormatException ex1) {
times = 0;
}
if (times <= 0) {
JOptionPane.showMessageDialog(null,
"Invoke times must be larger than zero.", "WARNING",
JOptionPane.WARNING_MESSAGE);
return;
}
// getParameterValues(times);
Vector parameterValues = new Vector();
Vector v = parameters.list;
int paraNumbers = v.size();
// if (chbModel.isSelected()) {// 用戶選擇的是直接傳送內容
if (txtParameterValues != null)// 當此服務有參數時
for (int i = 0; i < paraNumbers; i++) {
if (txtParameterValues[i] != null) {
String value = txtParameterValues[i].getText();
if (value == null
|| (value = value.trim()).length() == 0) {
JOptionPane.showMessageDialog(null,
"Please assign a value to paramter "
+ (i + 1), "WARNING",
JOptionPane.WARNING_MESSAGE);
return;
}
parameterValues.addElement(value);
}
}
try {
Map outputs = null;
long begin = Calendar.getInstance().getTime().getTime();
for (int i = 0; i < times; i++) {
outputs = invoker[0].invoke(serviceName, portName,
operationName, parameterValues);
}
long end = Calendar.getInstance().getTime().getTime();
long span = end - begin;
boolean isSave = false;
if (chb.isSelected()) {
isSave = true;
}
ResultDialog dlg = new ResultDialog(null, "RESULT", outputs,
span, times, isSave);
dlg.setVisible(true);
}// end try
catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getClass().getName()
+ ": " + ex.getMessage(), "ERROR",
JOptionPane.ERROR_MESSAGE);
}
}// end run
}// end class MainFrame_btnTest_Thread
void runFD(int threads) {
for (int i = 0; i < threads; i++) {
GetFDContentThread getFDContentThread = new GetFDContentThread(
threads);
Thread thread = new Thread(getFDContentThread);
thread.start();
}
}
class GetFDContentThread implements Runnable {
private int threads;
public GetFDContentThread(int threads) {
this.threads = threads;
}
public void run() {
Iterator it = fileListContent.iterator();
synchronized (fileListContent) {
while (it.hasNext()) {
fileNum++;
Vector parameterValues = new Vector();
parameterValues.addElement(it.next());
try {
Map outputs = null;
if (chbAll.isSelected()) {
for (int i = 0; i < invoker.length; i++) {
outputs = invoker[i].invoke(serviceName,
portName, operationName,
parameterValues);
boolean isSave = false;
if (chb.isSelected()) {
isSave = true;
}
ResultDialog dlg = new ResultDialog(null, "RESULT",
outputs, 0, threads, isSave);
}
} else {
int i = fileNum % invoker.length;
outputs = invoker[i].invoke(serviceName, portName,
operationName, parameterValues);
boolean isSave = false;
if (chb.isSelected())
isSave = true;
ResultDialog resultdialog1 = new ResultDialog(null,
"RESULT", outputs, 0L, threads, isSave);
}
it.remove();
// dlg.setVisible(true);
}// end try
catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getClass()
.getName()
+ ": " + ex.getMessage(), "ERROR",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
}
void btnChoose_actionPerformed(ActionEvent e, int i) {
try {
JFileChooser fc = new JFileChooser("...");
fc.setFileSelectionMode(fc.FILES_AND_DIRECTORIES);
fc.showOpenDialog(MainFrame.this);
txtParameterValues[i].setText(fc.getSelectedFile().getPath());
File file = new File(fc.getSelectedFile().getPath());
if (file.isFile()) {
fileListContent = new Vector();
getFileContent(fc.getSelectedFile().getPath(), true,
fileListContent);// 當選擇的是單個文件
} else {
getDirectoryContent(fc.getSelectedFile().getPath());// 當選擇的是一個目錄
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getClass().getName() + ": "
+ ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
// by shanben 2007/04/18 讀取指定的文件的內容
// 參數的作用是用來標識是對一個文件的讀取,還是對一個目錄下的所有文件的讀取。
// 在這里只實現了只有一個參數的情況。如果有多個參數的話,此處還需要修改。
void getFileContent(String filePath, boolean siglnFile,
Collection fileListContent) {
fileContent = "";
//FileReader reader = null;
BufferedReader br = null;
FileInputStream reader = null;
InputStreamReader isr = null;
try {
//reader = new FileReader(filePath);
//br = new BufferedReader(reader);
br = new BufferedReader(
new InputStreamReader(
new FileInputStream(filePath),"UTF-8"));
String str = "";
int intLength;
while ((str = br.readLine()) != null) {
if (siglnFile) {
fileContent += str;
} else {
fileContent += str;
}
}
fileListContent.add(fileContent);
// 測試用
System.out.println("========" + fileContent + "========");
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
//reader.close();
//isr.close();
br.close();
} catch (IOException ex1) {
ex1.printStackTrace();
}
}
}
// by shanben 2007/04/18 讀取一個目錄下所有文件路徑
void getDirectoryContent(String DirectoryPath) {
fileListContent = new Vector();
File file = new File(DirectoryPath);
fileList = file.listFiles();
Collection fl = new ArrayList();
for (int i = 0; i < fileList.length; i++) {
if (fileList[i].isFile()) {
fl.add(fileList[i]);
// 測試用
// System.out.println(fileList[i]);
}
}
Iterator it = fl.iterator();
while (it.hasNext()) {
String content = it.next().toString();
// System.out.println(content);
getFileContent(content, false, fileListContent);
}
// 測試用的
/*
* Iterator it1 = fileListContent.iterator(); while (it1.hasNext()) {
* System.out.println(it1.next()); }
*/
}
}
class MainFrame_btnExit_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_btnExit_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnExit_actionPerformed(e);
}
}
class MainFrame_btnAbout_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_btnAbout_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnAbout_actionPerformed(e);
}
}
class MainFrame_btnFind_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_btnFind_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnFind_actionPerformed(e);
}
}
class MainFrame_comboService_actionAdapter implements
java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_comboService_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.comboService_actionPerformed(e);
}
}
class MainFrame_comboOperation_actionAdapter implements
java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_comboOperation_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.comboOperation_actionPerformed(e);
}
}
class MainFrame_btnTest_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;
MainFrame_btnTest_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnTest_actionPerformed(e);
}
}
class MainFrame_btnChoose_actionAdapter implements
java.awt.event.ActionListener {
MainFrame adaptee;
private int i;
MainFrame_btnChoose_actionAdapter(MainFrame adaptee, int i) {
this.adaptee = adaptee;
this.i = i;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnChoose_actionPerformed(e, i);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -