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

📄 stafcommandparser.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2001                                              *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/package com.ibm.staf.service;import java.text.*;import java.util.*;// STAFCommandParser - This class implements the standard STAF parser used by//                     all STAF services.public class STAFCommandParser{    public STAFCommandParser()    {        this(0, false);    }    public STAFCommandParser(int maxArgs)    {        this(maxArgs, false);    }    public STAFCommandParser(int maxArgs, boolean caseSensitive)    {        fMaxArgs = maxArgs;        fCaseSensitive = caseSensitive;        fOptions = new Vector();        fOptionGroups = new Vector();        fOptionNeeds = new Vector();    }    public static final int VALUEREQUIRED = 0;    public static final int VALUENOTALLOWED = 1;    public static final int VALUEALLOWED = 2;    public void addOption(String name, int maxAllowed, int valueRequirement)    {        fOptions.addElement(new Option(name, maxAllowed, valueRequirement));    }    public void addOptionGroup(String optionNames, int min, int max)    {        fOptionGroups.addElement(new OptionGroup(optionNames, min,max));    }    public void addOptionNeed(String needers, String needees)    {        fOptionNeeds.addElement(new OptionNeed(needers, needees));    }    public STAFCommandParseResult parse(String data)    {        STAFCommandParseResult result =                               new STAFCommandParseResult(fCaseSensitive);        Vector wordList = new Vector();        OptionValue optionValue = new OptionValue();        char currentChar;        boolean inQuotes = false;        boolean inEscape = false;        boolean isLiteral = false;        boolean inLengthField = false;        boolean inDataField = false;        int dataLength = 0;        for(int i = 0; i < data.length(); ++i)        {            currentChar = data.charAt(i);            if ((currentChar == ':') && !inQuotes && !inEscape &&               !inDataField && optionValue.data.length() == 0)            {                inLengthField = true;            }            else if (inLengthField)            {                if (currentChar == ':')                {                    inLengthField = false;                    inDataField = true;                    if (optionValue.data.length() == 0)                    {                        result.errorBuffer = "Invalid length delimited data " +                                             "specifier";                        result.rc = 1;                        return result;                    }                    dataLength = new Integer(                        optionValue.data.toString()).intValue();                    optionValue = new OptionValue();                }                else if (Character.isDigit(currentChar))                {                    optionValue.data.append(currentChar);                }                else                {                    result.errorBuffer = "Invalid length delimited data " +                                         "specifier";                    result.rc = 1;                    return result;                }            }            else if (inDataField)            {                // Need to check if length > 0 to handle :0: case                if (dataLength > 0)                {                    optionValue.data.append(currentChar);                }                if (--dataLength <= 0)                {                    wordList.addElement(optionValue);                    optionValue = new OptionValue();                    inDataField = false;                }            }            else if (Character.isWhitespace(currentChar))            {                inEscape = false;                if (inQuotes) optionValue.data.append(currentChar);                else if (optionValue.data.length() != 0)                {                    if (isLiteral)                        optionValue.optionOrValue = ISVALUE;                    else if (isOption(optionValue.data))                        optionValue.optionOrValue = ISOPTION;                    wordList.addElement(optionValue);                    optionValue = new OptionValue();                    isLiteral = false;                }                else continue;            }            else if (currentChar == '\\')            {                if (inQuotes && !inEscape)                {                    inEscape = true;                    continue;                }                else                {                    optionValue.data.append(currentChar);                    inEscape = false;                }            }            else if (currentChar == '"')            {                if (inEscape) optionValue.data.append(currentChar);                else if (inQuotes && optionValue.data.length() != 0)                {                    if (isLiteral)                        optionValue.optionOrValue = ISVALUE;                    else if (isOption(optionValue.data))                        optionValue.optionOrValue = ISOPTION;                    wordList.addElement(optionValue);                    optionValue = new OptionValue();                    inQuotes = false;                    isLiteral = false;                }                else                {                    inQuotes = true;                    isLiteral = true;                }                inEscape = false;            }  // end if quote character            else            {                inEscape = false;                optionValue.data.append(currentChar);            }        }  // for each character in parseString                // Handle case where last option's value is :0:        if (inDataField && dataLength == 0)        {            wordList.addElement(optionValue);            optionValue = new OptionValue();            inDataField = false;        }                if (inLengthField || inDataField)        {            result.errorBuffer = "Invalid length delimited data specifier";            result.rc = 1;            return result;        }        else if (optionValue.data.length() != 0)        {            if (isLiteral)                optionValue.optionOrValue = ISVALUE;            else if (isOption(optionValue.data))                optionValue.optionOrValue = ISOPTION;            wordList.addElement(optionValue);        }        // Now walk the word list looking for options, etc.        STAFCommandParseResult.OptionInstance optionInstance =            result.new OptionInstance();        int valueRequirement = VALUENOTALLOWED;        for(int i = 0; i < wordList.size(); ++i)        {            OptionValue currOptionValue = (OptionValue)wordList.elementAt(i);            StringBuffer currentWord = currOptionValue.data;            if (currOptionValue.optionOrValue == ISOPTION)            {                Option option = getOption(currentWord);                if (valueRequirement == VALUEREQUIRED)                {                    result.errorBuffer = "Option, " + optionInstance.name +                                         ", requires a value";                    result.rc = 1;                    return result;                }                else if (valueRequirement == VALUEALLOWED)                {                    result.addOptionInstance(optionInstance);                }                // Check once here for whether this new option instance will                // exceed the limit for this option                if ((result.optionTimes(option.name) == option.maxAllowed) &&                   (option.maxAllowed != 0))                {                    result.errorBuffer = "You may have no more than " +                                         option.maxAllowed +                                         " instances of option " + option.name;                    result.rc = 1;                    return result;                }                optionInstance = result.new OptionInstance();                optionInstance.name = currentWord.toString();                valueRequirement = option.valueRequirement;

⌨️ 快捷键说明

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