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

📄 stafutil.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2001, 2005                                        *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/package com.ibm.staf;import com.ibm.staf.service.*;// STAFUtil - This class provides STAF utility functionspublic class STAFUtil{    public static String privacyDelimiter1 = "!!@";    public static String privacyDelimiter2 = "@!!";    public static String escapedPrivacyDelimiter1 = "^!!@";    public static String escapedPrivacyDelimiter2 = "^@!!";    public static String privacyDelimiterEscape = "^";    /***********************************************************************/    /* Description:                                                        */    /*   This method returns length delimited representation of the string */    /*   (aka the colon length colon format).                              */    /*                                                                     */    /* Input:  A string.   For example:  "Hi there"                        */    /*                                                                     */    /* Returns:                                                            */    /*   String in the colon lengthh colon format.                         */    /*                     For example:  ":8:Hi there"                     */    /***********************************************************************/    public static String wrapData(String data)    {        return ":" + data.length() + ":" + data;    }    /***********************************************************************/    /* Description:                                                        */    /*   This method returns the string without the colon length colon     */    /*   prefix.                                                           */    /*                                                                     */    /* Input:  String which is in colon length colon format                */    /*                    For example:  ":8:Hi there"                      */    /*                                                                     */    /* Returns:                                                            */    /*   String without the colon length colon. For example: "Hi there"    */    /***********************************************************************/    public static String unwrapData(String data)    {        if (data != null)        {            int colon1Pos = data.indexOf(":");            if (colon1Pos == 0)            {                int colon2Pos = data.indexOf(":", 1);                if (colon2Pos > -1)                {                    try                    {                        // Verify that an integer was specified between the two                        // colons to make sure the value has a colonLengthColon                        // format, and just doesn't happen to contain two colons                        int length = (new Integer(                            data.substring(1, colon2Pos))).intValue();                        String newValue = data.substring(colon2Pos + 1);                        if (length == newValue.length())                            return newValue;                    }                    catch (NumberFormatException e)                    {                        // Not a CLC format                    }                }            }        }        return data;    }    /***********************************************************************/    /* Description:                                                        */    /*   This method returns the endpoint without the port (strips @nnnn   */    /*   from the end of the endpoint                                      */    /*                                                                     */    /* Input:  Endpoint   <Interface>://<System identifier>[@<Port>]       */    /*                    For example:  tcp://client1.company.com@6500     */    /*                                                                     */    /* Returns:                                                            */    /*   Endpoint without the port. For example: tcp://client1.company.com */    /***********************************************************************/    public static String stripPortFromEndpoint(String endpoint)    {        // Strip the port from the endpoint, if present.        String endpointNoPort = endpoint;        int portIndex = endpoint.lastIndexOf("@");        if (portIndex != -1)        {            // If the characters following the "@" are numeric, then assume            // it's a valid port and strip the @ and the port number from            // the endpoint.            try            {                int port = new Integer(endpoint.substring(portIndex + 1)).                    intValue();                endpointNoPort = endpoint.substring(0, portIndex);            }            catch (NumberFormatException e)            {                // Do nothing - Not valid port so don't remove from endpoint            }        }        return endpointNoPort;    }        /***********************************************************************/    /* Description:                                                        */    /*   This method validates that the requesting machine has the         */    /*   required trust to submit a service request.                       */    /*                                                                     */    /* Input:  Required trust level                                        */    /*         Service name                                                */    /*         Request string (submitted to the service)                   */    /*         Name of the service machine (it's machine identifier) which */    /*           is used in the error message if has insufficient trust    */    /*         Request information                                         */    /*                                                                     */    /* Returns:                                                            */    /*   STAFResult.rc = the return code (STAFResult.Ok if successful)     */    /*   STAFResult.result = blank if successful                           */    /*                       a detailed error message if not successful    */    /*                                                                     */    /* Note:  Each time a new service interface level is added, must add   */    /*        another validateTrust method overloaded to support the new   */    /*        service interface level.                                     */    /***********************************************************************/    public static STAFResult validateTrust(        int requiredTrustLevel, String service, String request,        String localMachine, STAFServiceInterfaceLevel30.RequestInfo info)    {        if (info.trustLevel < requiredTrustLevel)        {            // Strip the port from the machine's endpoint, if present.            String endpoint = stripPortFromEndpoint(info.endpoint);            return new STAFResult(                STAFResult.AccessDenied,                "Trust level " + requiredTrustLevel + " required for the " +                service + " service's " + request + " request\n" +                "Requester has trust level " + info.trustLevel +                " on machine " + localMachine + "\nRequesting machine: " +                 endpoint + " (" + info.physicalInterfaceID + ")" +                "\nRequesting user   : " + info.user);        }            return new STAFResult(STAFResult.Ok);    }        /***********************************************************************/    /* Description:                                                        */    /*   This method resolves any STAF variables that are contained within */    /*   the string passed in by submitting a                              */    /*       RESOLVE REQUEST <request#> STRING <value>                     */    /*   request to the VAR service on the local system.                   */    /*   The variables will be resolved using the originating handle's pool*/    /*   associated with the specified request number, the local system's  */    /*   shared pool, and the local system's system pool.                  */    /*                                                                     */    /* Input:  String that may contain STAF variables to be resolved       */    /*         STAF handle                                                 */    /*         Request number                                              */    /*                                                                     */    /* Returns:                                                            */    /*   STAFResult.rc = the return code (STAFResult.Ok if successful)     */    /*   STAFResult.result = the resolved value if successful              */    /*                       an error message if not successful            */    /***********************************************************************/    public static STAFResult resolveRequestVar(        String value, STAFHandle handle, int requestNumber)    {        if (value.indexOf("{") != -1)        {            // The string may contains STAF variables                        STAFResult resolvedResult = handle.submit2(                "local", "VAR", "RESOLVE REQUEST " + requestNumber +                " STRING " + STAFUtil.wrapData(value));            return resolvedResult;        }        return new STAFResult(STAFResult.Ok, value);    }        /***********************************************************************/    /* Description:                                                        */    /*   This method resolves any STAF variables that are contained within */    /*   the string passed in by submitting a                              */    /*       RESOLVE REQUEST <request#> STRING <value>                     */    /*   request to the VAR service on the local system.                   */    /*   The variables will be resolved using the originating handle's pool*/    /*   associated with the specified request number, the local system's  */    /*   shared pool, and the local system's system pool.                  */    /*   Then it checks if the resolved value is an integer and returns an */    /*   error if it's not an integer.                                     */    /*                                                                     */    /* Input:  Option name whose value is being resolved                   */    /*         Value that may contain STAF variables to be resolved        */    /*         STAF handle                                                 */    /*         Request number                                              */    /*                                                                     */    /* Returns:                                                            */    /*   STAFResult.rc = the return code (STAFResult.Ok if successful)     */    /*   STAFResult.result = the resolved option value if successful       */    /*                       an error message if not successful            */    /***********************************************************************/    public static STAFResult resolveRequestVarAndCheckInt(        String option, String value, STAFHandle handle, int requestNumber)    {        STAFResult resolvedValue = resolveRequestVar(            value, handle, requestNumber);        if (resolvedValue.rc != STAFResult.Ok) return resolvedValue;        try        {            Integer.parseInt(resolvedValue.result);        }        catch (NumberFormatException e)        {            return new STAFResult(                STAFResult.InvalidValue, option +                " value must be an Integer.  " +                option + "=" + resolvedValue.result);        }        return resolvedValue;    }    /***********************************************************************/    /* Description:                                                        */    /*   This method resolves any STAF variables that are contained within */    /*   the string passed in by submitting a                              */    /*       RESOLVE STRING <value>                                        */    /* request to the VAR service on the local system.                     */    /*                                                                     */    /* Input:  String that may contain STAF variables to be resolved       */    /*         STAF handle                                                 */    /*                                                                     */    /* Returns:                                                            */    /*   STAFResult.rc = the return code (STAFResult.Ok if successful)     */    /*   STAFResult.result = the resolved string if successful             */    /*                       an error message if not successful            */    /***********************************************************************/    public static STAFResult resolveInitVar(String value, STAFHandle handle)    {        if (value.indexOf("{") != -1)        {            // The string may contains STAF variables            STAFResult resolvedResult = handle.submit2(                "local", "VAR", "RESOLVE STRING " + STAFUtil.wrapData(value));

⌨️ 快捷键说明

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