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

📄 timercmdparser.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ibm.staf.service.timer;/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002, 2004, 2005                                  *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************//****************************************************************************///// Class: TimerCmdParser//// Logical Name: TimerCmdParser.java//// Description: This class parsers commands received from STAF.////// History://// DATE       DEVELOPER   CHANGE DESCRIPTION// ---------- ----------- -----------------------------------// 02/01/2000 C Alkov     Original Program///****************************************************************************/import com.ibm.staf.*;import com.ibm.staf.service.*;import com.ibm.staf.wrapper.STAFLog;import java.util.Enumeration;public class TimerCmdParser{    private Timer fTimer;    private STAFCommandParser registerParser;    private STAFCommandParser unregisterParser;    private STAFCommandParser listParser;    private STAFCommandParser watchParser;    private STAFCommandParser unwatchParser;    private final static String REGISTER = "REGISTER";    private final static String UNREGISTER = "UNREGISTER";    private final static String LIST = "LIST";    private final static String SP = " ";    private final static String TYPE = "TYPE";    private final static String FREQUENCY = "FREQUENCY";    private final static String PRIORITY = "PRIORITY";    private final static String MACHINE = "MACHINE";    private final static String HANDLE = "HANDLE";    private final static String KEY = "KEY";    private final static String TIMERS = "TIMERS";    private final static String HELP = "HELP";    private final static String VERSION = "VERSION";    private final static String REFRESH = "REFRESH";    private final static String UNREGONNOPATH = "UNREGONNOPATH";    private final static String UNREGONNOHANDLE = "UNREGONNOHANDLE";    private final static String NAME = "NAME";    private final static String BYNAME = "BYNAME";    private final static String LONG = "LONG";    private final static String WATCHES = "WATCHES";    private final static String WATCH = "WATCH";    private final static String UNWATCH = "UNWATCH";    private final static String MARGIN = "MARGIN";    private final static String INVALIDOPTION =      "You must have at least 1, but no more than 1 of the options,"+      " REGISTER UNREGISTER WATCH UNWATCH LIST REFRESH VERSION HELP";    private final static String BADFREQUENCY =      "The value for FREQUENCY must be an integer.";    private final static String BADMARGIN =      "The value for MARGIN must be an integer.";    private final static String BADPRIORITY =      "The value for PRIORITY must be an integer.";    private final static String BADHANDLE =      "The value for HANDLE must be an integer.";/****************************************************************************///// Method://   Constructor//// Description://   Constructor method for TimerCmdParser class.//// Input://   timer - The instance of the Timer service creating this CmdParser.//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public TimerCmdParser(Timer timer){    fTimer = timer;    /* Create registerParser */    registerParser = new STAFCommandParser();    registerParser.addOption(REGISTER, 1, STAFCommandParser.VALUENOTALLOWED);    registerParser.addOption(TYPE, 1, STAFCommandParser.VALUEREQUIRED);    registerParser.addOption(FREQUENCY, 1, STAFCommandParser.VALUEREQUIRED);    registerParser.addOption(KEY, 1, STAFCommandParser.VALUEREQUIRED);    registerParser.addOption(PRIORITY, 1, STAFCommandParser.VALUEREQUIRED);    registerParser.addOption(UNREGONNOPATH, 1,        STAFCommandParser.VALUEREQUIRED);    registerParser.addOption(UNREGONNOHANDLE, 1,        STAFCommandParser.VALUEREQUIRED);    registerParser.addOption(BYNAME, 1, STAFCommandParser.VALUENOTALLOWED);    registerParser.addOptionGroup(REGISTER, 1, 1);    registerParser.addOptionGroup(TYPE, 1, 1);    registerParser.addOptionGroup(FREQUENCY, 1, 1);    /* Create unregisterParser */    unregisterParser = new STAFCommandParser();    unregisterParser.addOption(UNREGISTER, 1,        STAFCommandParser.VALUENOTALLOWED);    unregisterParser.addOption(TYPE, 1, STAFCommandParser.VALUEREQUIRED);    unregisterParser.addOption(MACHINE, 1, STAFCommandParser.VALUEREQUIRED);    unregisterParser.addOption(HANDLE, 1, STAFCommandParser.VALUEREQUIRED);    unregisterParser.addOption(NAME, 1, STAFCommandParser.VALUEREQUIRED);    unregisterParser.addOption(KEY, 1, STAFCommandParser.VALUEREQUIRED);    unregisterParser.addOption(BYNAME, 1, STAFCommandParser.VALUENOTALLOWED);    unregisterParser.addOptionGroup(UNREGISTER, 1, 1);    unregisterParser.addOptionGroup(TYPE, 1, 1);    unregisterParser.addOptionGroup(NAME+SP+HANDLE, 0, 1);    unregisterParser.addOptionGroup(MACHINE+SP+BYNAME, 0, 1);    unregisterParser.addOptionNeed(MACHINE, HANDLE+SP+NAME);    unregisterParser.addOptionNeed(HANDLE, MACHINE);    unregisterParser.addOptionNeed(NAME, MACHINE);    /* Create listParser */    listParser = new STAFCommandParser();    listParser.addOption(LIST,      1, STAFCommandParser.VALUENOTALLOWED);    listParser.addOption(TIMERS,    1, STAFCommandParser.VALUENOTALLOWED);    listParser.addOption(WATCHES,   1, STAFCommandParser.VALUENOTALLOWED);    listParser.addOption(LONG, 1, STAFCommandParser.VALUENOTALLOWED);    listParser.addOption("SETTINGS", 1, STAFCommandParser.VALUENOTALLOWED);    listParser.addOptionGroup(LIST, 1, 1);    listParser.addOptionGroup(TIMERS+SP+WATCHES+SP+"SETTINGS", 1, 1);    listParser.addOptionNeed(LONG, TIMERS);    /* Create watchParser */    watchParser = new STAFCommandParser();    watchParser.addOption(WATCH, 1, STAFCommandParser.VALUENOTALLOWED);    watchParser.addOption(MACHINE, 1, STAFCommandParser.VALUEREQUIRED);    watchParser.addOption(FREQUENCY, 1, STAFCommandParser.VALUEREQUIRED);    watchParser.addOption(MARGIN, 1, STAFCommandParser.VALUEREQUIRED);    watchParser.addOptionGroup(WATCH, 1, 1);    watchParser.addOptionGroup(MACHINE, 1, 1);    watchParser.addOptionGroup(FREQUENCY, 1, 1);    /* Create unwatchParser */    unwatchParser = new STAFCommandParser();    unwatchParser.addOption(UNWATCH, 1, STAFCommandParser.VALUENOTALLOWED);    unwatchParser.addOption(MACHINE, 1, STAFCommandParser.VALUEREQUIRED);    unwatchParser.addOptionGroup(UNWATCH, 1, 1);    unwatchParser.addOptionGroup(MACHINE, 1, 1);}/****************************************************************************///// Method://   parse//// Description://   This method parses the first word of the request and handles//   accordingly.//// Input://   STAFServiceInterfaceLevel30 request information//   (including the submitting machine name, the submitting handle name,//    the submitting handle#, a string containing any command//    options & option values).//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult parse(STAFServiceInterfaceLevel30.RequestInfo info){    info.request = info.request.toUpperCase();    STAFResult result = null;    if (info.request.startsWith(REGISTER))    {        result = parseRegister(info);    }    else if (info.request.startsWith(UNREGISTER))    {        result = parseUnregister(info);    }    else if (info.request.startsWith(WATCH))    {        result = parseWatch(info);    }    else if (info.request.startsWith(UNWATCH))    {        result = parseUnwatch(info);    }    else if (info.request.startsWith(LIST))    {        result = parseList(info);    }    else if (info.request.startsWith(HELP))    {        // Verify the requester has at least trust level 1        STAFResult trustResult = STAFUtil.validateTrust(            1, fTimer.sServiceName, "HELP", fTimer.localMachine, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        result = fTimer.reqHandler.help(fTimer.sServiceName);    }    else if (info.request.startsWith(VERSION))    {        // Verify the requester has at least trust level 1        STAFResult trustResult = STAFUtil.validateTrust(            1, fTimer.sServiceName, "VERSION", fTimer.localMachine, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        result = fTimer.reqHandler.version(info);    }    else if (info.request.startsWith(REFRESH))    {        // Verify the requester has at least trust level 3        STAFResult trustResult = STAFUtil.validateTrust(            3, fTimer.sServiceName, "REFRESH", fTimer.localMachine, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        result = fTimer.reqHandler.refresh();    }    else    {        result = new STAFResult(STAFResult.InvalidRequestString, INVALIDOPTION);    }    return result;}/****************************************************************************///// Method://   parseList//// Description://   This method parses parameters for the List command.//// Input://   STAFServiceInterfaceLevel30 request information//   (including the submitting machine name, the submitting handle name,//    the submitting handle#, a string containing any command//    options & option values).//// Exceptions Thrown://   none//// Notes://   private method///****************************************************************************/private STAFResult parseList(STAFServiceInterfaceLevel30.RequestInfo info){    STAFCommandParseResult pResult = listParser.parse(info.request);    if (pResult.rc != 0)    {        return new STAFResult(pResult.rc, pResult.errorBuffer);    }    // Verify the requester has at least trust level 2    STAFResult trustResult = STAFUtil.validateTrust(        2, fTimer.sServiceName, "LIST", fTimer.localMachine, info);    if (trustResult.rc != STAFResult.Ok) return trustResult;    boolean longFormat = false;    if (pResult.optionTimes(LONG) == 1)    {       longFormat = true;    }    if (pResult.optionTimes(TIMERS) == 1)    {        // Call List Timers request handler        return fTimer.reqHandler.listTimers(info, longFormat);    }    else if (pResult.optionTimes(WATCHES) == 1)    {        // Call List Watches request handler        return fTimer.reqHandler.listWatches(info);    }    else if (pResult.optionTimes("SETTINGS") == 1)    {        return fTimer.reqHandler.listSettings(info);    }    else    {        // Should not go here, but return InvalidRequestString        return new STAFResult(STAFResult.InvalidRequestString);    }}/****************************************************************************///// Method://   parseRegister//// Description://   This method parses parameters for the Register command.//// Input://   STAFServiceInterfaceLevel30 request information//   (including the submitting machine name, the submitting handle name.//    the submitting handle#, a string containing any command//    options & option values).//// Exceptions Thrown://   none//// Notes://   private method///****************************************************************************/private STAFResult parseRegister(STAFServiceInterfaceLevel30.RequestInfo info){    // Verify the requester has at least trust level 3    STAFResult trustResult = STAFUtil.validateTrust(        3, fTimer.sServiceName, "REGISTER", fTimer.localMachine, info);    if (trustResult.rc != STAFResult.Ok) return trustResult;    // Parse the request    STAFCommandParseResult pResult = registerParser.parse(info.request);    if (pResult.rc != 0)    {        return new STAFResult(pResult.rc, pResult.errorBuffer);    }    int unregOnNoPath = -1;    int unregOnNoHandle = -1;    boolean byname = false;    String key = "";    int priority = 5; // set default priority    STAFResult res = new STAFResult();    // Resolve the TYPE option        res = STAFUtil.resolveRequestVar(        pResult.optionValue(TYPE), fTimer.sHandle, info.requestNumber);    if (res.rc != 0) return res;

⌨️ 快捷键说明

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