⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staflogviewer.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2001, 2004                                        *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/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.*;class STAFLogViewer{    String helpText = "\nSTAFLogViewer Help\n\n" +        "-machine <machineName> -machineNickname <machineNickname> " +        "-handle <logHandle> -name <logName>\n" + "-help\n" + "-version";    String kVersion = "3.0.0";    public static void main(String argv[])    {        new STAFLogViewer(argv);    }    public STAFLogViewer(String argv[])    {        if ((argv.length < 1) || (argv.length > 6))        {            System.out.println("Invalid parameters");            System.out.println(helpText);            System.exit(0);        }        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].equals("-machine"))                    {                        fMachine = argv[i+1];                    }                    else if (argv[i].equals("-machineNickname"))                    {                        fMachineNickname = argv[i+1];                    }                    else if (argv[i].equals("-handle"))                    {                        fLogHandle = argv[i+1];                    }                    else if (argv[i].equals("-name"))                    {                        fLogName = argv[i+1];                    }                }            }        }        try        {            fHandle = new STAFHandle("STAFLogViewer");            if (fMachine.equalsIgnoreCase("local"))            {                fMachine = (fHandle.submit2(                    "local", "VAR", "RESOLVE STRING {STAF/Config/Machine}")).                    result;            }            // Submit a request to query the log            String request = "QUERY MACHINE " + fMachineNickname +                " HANDLE " + fLogHandle + " LOGNAME " + fLogName;            STAFResult stafResult = fHandle.submit2(fMachine, "LOG", request);            if (stafResult.rc != 0)            {                System.out.println(                    "Error on query log request to machine " + fMachine +                    "  Request=" + request + ", RC=" + stafResult.rc +                    ", Result=" + stafResult.result);                return;            }            // Unmarshall the output from the request and create a outputList            // containing the results (timestamp, level, and message)            java.util.List outputList;            try            {                STAFMarshallingContext outputContext =                    STAFMarshallingContext.unmarshall(stafResult.result);                outputList = (java.util.List)outputContext.getRootObject();            }            catch (Exception e)            {                System.out.println(                    "Invalid result format from query log request to " +                    "machine " + fMachine + "  Request=" + request);                e.printStackTrace();                return;            }            // Create a vector (logLines) from the outputList            Iterator iter = outputList.iterator();            Vector logLines = new Vector();            int i = 0;            try            {                while (iter.hasNext())                {                    i++;                    Map logRecord = (Map)iter.next();                    Vector thisLogData = new Vector();                    thisLogData.add((String)logRecord.get("timestamp"));                    thisLogData.add((String)logRecord.get("level"));                    thisLogData.add((String)logRecord.get("message"));                    logLines.add(thisLogData);                }            }            catch (Exception e)            {                System.out.println(                    "Invalid format for log record #" + i +                    " in log " + fLogName + " for machine " + fMachine +                    ", handle " + fLogHandle);                e.printStackTrace();                return;            }            String frameTitle = "Log on Machine " + fMachine +                " - " + request;            STAFLogFrame logFrame = new STAFLogFrame(frameTitle, logLines);            logFrame.setSize(500, 300);            logFrame.show();            String osName = System.getProperties().getProperty("os.name");            if (osName.equals("Windows 2000"))            {                logFrame.setState(JFrame.ICONIFIED);                logFrame.setState(JFrame.NORMAL);            }            else            {                logFrame.toFront();            }        }        catch(STAFException e)        {            System.out.println("Error registering with STAF, RC: " + e.rc);            System.exit(e.rc);        }        catch(Exception e)        {            e.printStackTrace();        }    }    public class STAFLogFrame extends JFrame    {        public STAFLogFrame(String title, Vector logLines)        {            super(title);            Vector columnNames = new Vector();            columnNames.add(new String("Timestamp"));            columnNames.add(new String("Level"));            columnNames.add(new String("Message"));            JTable logTable = new JTable(logLines, columnNames);            logTable.setRowSelectionAllowed(false);            logTable.setColumnSelectionAllowed(false);            JScrollPane logScroll = new JScrollPane(logTable);            getContentPane().add(logScroll);            addWindowListener(new WindowAdapter()            {                public void windowClosing(WindowEvent event)            {                    dispose();                    System.exit(0);            }        });        }    }    private STAFHandle fHandle;    private String fMachine;    private String fMachineNickname;    private String fLogHandle;    private String fLogName;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -