📄 staflogviewer.java
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2006 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/package com.ibm.staf;import com.ibm.staf.*;import com.ibm.staf.service.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;import javax.swing.table.*;import javax.swing.event.TableModelListener;import javax.swing.event.TableModelEvent;public class STAFLogViewer extends JFrame{ static String helpText = "\nSTAFLogViewer Help\n\n" + "Description:\n\n" + "The STAFLogViewer displays a STAF log on any machine currently " + "running STAF.\n\n" + "Parameters:\n\n" + "-machine <Log Service Machine Name>\n" + "-serviceName <Log Service Name>\n" + "-queryRequest <LOG QUERY Request>\n" + "-levelMask <LEVELMASK option>\n" + "-fontName <Font Name>\n" + "-help\n" + "-version\n\n" + "Notes:\n\n" + "1) You must specify one of the following parameters:\n" + " -queryRequest or -help or -version.\n" + "2) If the -machine option is not specified, it defaults to local.\n" + "3) If the -serviceName option is not specified, it defaults to " + "LOG.\n" + "4) The -queryRequest parameter is required (unless you specified " + "-help or\n-version) and must be a valid QUERY request for the LOG " + "service.\n" + "5) The -levelMask parameter is optional. It defaults to display all " + "log levels.\n" + "6) If the -fontName option isn't specified, it defaults to the " + "Monospaced font.\n" + "7) If specifying the -help or -version option, it must be the " + "first (and only)\noption specified.\n\n" + "Examples: (Enter as a single command)\n\n" + "java com.ibm.staf.STAFLogViewer -machine awesvc3\n" + " -queryRequest \"QUERY GLOBAL LOGNAME CIS LAST 50\"\n\n" + "java com.ibm.staf.STAFLogViewer -levelMask \"ERROR WARNING\"\n" + " -queryRequest \"QUERY MACHINE {STAF/Config/MachineNickname}\n" + " LOGNAME email ALL\""; static String kVersion = "3.0.2"; public static void main(String argv[]) { String machine = "local"; String serviceName = "LOG"; String queryRequest = ""; String fontName = "Monospaced"; String levelMask = ""; int minArgsAllowed = 1; int maxArgsAllowed = 8; boolean queryRequestArg = false; if (argv.length < minArgsAllowed) { System.out.println( "\nERROR: Must specify " + minArgsAllowed + " of the " + "following parameters: -queryRequest, -help, or -version"); System.out.println(helpText); System.exit(1); } else if (argv.length > maxArgsAllowed) { System.out.println( "\nERROR: Too many arguments. You specified " + argv.length + " arguments, but only up to " + maxArgsAllowed + " arguments are allowed."); System.out.println(helpText); System.exit(1); } else { if (argv[0].equalsIgnoreCase("-HELP")) { System.out.println(helpText); System.exit(0); } else if (argv[0].equalsIgnoreCase("-VERSION")) { System.out.println(kVersion); System.exit(0); } else { for (int i = 0; i < argv.length; i++) { if (argv[i].equalsIgnoreCase("-machine")) { if ((i+1) >= argv.length) { System.out.println( "\nERROR: Parameter -machine requires " + "a value"); System.out.println(helpText); System.exit(1); } machine = argv[i+1]; i++; } else if (argv[i].equalsIgnoreCase("-queryRequest")) { if ((i+1) > argv.length - 1) { System.out.println( "\nERROR: Parameter -queryRequest requires " + "a value"); System.out.println(helpText); System.exit(1); } queryRequestArg = true; queryRequest = argv[i+1]; i++; } else if (argv[i].equalsIgnoreCase("-levelMask")) { if ((i+1) > argv.length - 1) { System.out.println( "\nERROR: Parameter -levelMask requires " + "a value"); System.out.println(helpText); System.exit(1); } levelMask = argv[i+1]; i++; } else if (argv[i].equalsIgnoreCase("-fontName")) { if ((i+1) > argv.length - 1) { System.out.println( "\nERROR: Parameter -fontName requires " + "a value"); System.out.println(helpText); System.exit(1); } fontName = argv[i+1]; i++; } else if (argv[i].equalsIgnoreCase("-version")) { System.out.println( "\nERROR: Parameter -version must be specified " + "as the first and only parameter"); System.out.println(helpText); System.exit(1); } else if (argv[i].equalsIgnoreCase("-help")) { System.out.println( "\nERROR: Parameter -help must be specified as " + "the first and only parameter"); System.out.println(helpText); System.exit(1); } else { System.out.println( "Invalid parameter name: " + argv[i]); System.out.println(helpText); System.exit(1); } } if (!queryRequestArg) { System.out.println( "\nERROR: Must specify " + minArgsAllowed + " of the following parameters: " + "-queryRequest, -help, or -version"); System.out.println(helpText); System.exit(1); } } } new STAFLogViewer(new JFrame(), null, machine, serviceName, queryRequest, levelMask, fontName); } public STAFLogViewer(Component parent, STAFHandle handle, String queryRequest) { this(parent, handle, "local", "LOG", queryRequest, "", "Monospaced"); } public STAFLogViewer(Component parent, STAFHandle handle, String machine, String queryRequest) { this(parent, handle, machine, "LOG", queryRequest, "", "Monospaced"); } public STAFLogViewer(Component parent, STAFHandle handle, String machine, String serviceName, String queryRequest) { this(parent, handle, machine, serviceName, queryRequest, "", "Monospaced"); } public STAFLogViewer(Component parent, STAFHandle handle, String machine, String serviceName, String queryRequest, String levelMask) { this(parent, handle, machine, serviceName, queryRequest, levelMask, "Monospaced"); } public STAFLogViewer(Component parent, STAFHandle handle, String machine, String serviceName, String queryRequest, String levelMask, String fontName) { this.parent = parent; fMachine = machine; fServiceName = serviceName; fQueryRequest = queryRequest; fLevelMask = levelMask; fFontName = fontName; STAFResult res; // If a handle was specified, don't do a system exit if (handle != null) fSystemExit = false; try { if (handle == null) { fHandle = new STAFHandle("STAFLogViewer"); } else { res = handle.submit2( "local", "HANDLE", "CREATE HANDLE NAME " + "STAFLogViewer"); if (res.rc == 0) { fHandle = new STAFHandle(new Integer(res.result).intValue()); } else { fHandle = handle; } } } catch(STAFException e) { System.out.println("Error registering with STAF, RC: " + e.rc); //e.printStackTrace(); if (! fSystemExit) return; else System.exit(0); } String frameTitle = "STAF " + fMachine + " " + fServiceName + " " + fQueryRequest; fLogFrame = new STAFLogFrame(frameTitle); Vector logLines = refreshTable(false); if (logLines == null) { if (! fSystemExit) return; else System.exit(0); } if (logLines.size() == 0) { JOptionPane.showMessageDialog( parent, "Log + has no entries\n\n" + fLogFrame.getTitle(), "No Log Entries", JOptionPane.INFORMATION_MESSAGE); if (! fSystemExit) return; else System.exit(0); } fLogFrame.setSize(800, 400); fLogFrame.show(); String osName = System.getProperties().getProperty("os.name"); if (osName.equals("Windows 2000")) { fLogFrame.setState(JFrame.ICONIFIED); fLogFrame.setState(JFrame.NORMAL); } else { fLogFrame.toFront(); } } public Vector getLogLines(boolean returnEmptyVector) { STAFResult stafResult = null; if (fLevelMask != "") { // If the LEVELMASK was specified, only do this processing the // initial time the log is displayed, since the user may change the // selected levels by using the menu bar processLevelMask(); fLevelMask = ""; } String frameTitle = "STAF " + fMachine + " " + fServiceName + " " + fQueryRequest; fLogFrame.setTitle(frameTitle); stafResult = fHandle.submit2(fMachine, fServiceName, fQueryRequest + getLogMask()); if (stafResult.rc == 4010) { STAFResult result1 = fHandle.submit2(fMachine, fServiceName, "LIST SETTINGS"); STAFMarshallingContext mc = STAFMarshallingContext.unmarshall(result1.result); Map processCompletionMap = (Map)mc.getRootObject(); String defaultMaxQueryRecords = (String)processCompletionMap.get("defaultMaxQueryRecords"); JOptionPane.showMessageDialog( parent, "Your query criteria selected more records than " + "allowed by\nthe DefaultMaxQueryRecords setting. Use the " +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -