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

📄 staxfunctionaction.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            argPropertyDataOutputList.add(propertyDataMap);        }                return argPropertyDataOutputList;    }    public String getInfo()    {        return fName;    }    public String getXMLInfo()    {        String xmlInfo = "<function=\"" + fName + "\"";        if (!fScope.equals("global"))            xmlInfo += " scope=\"" + fScope + "\"";        if (!fRequires.equals(""))            xmlInfo += " requires=\"" + fRequires + "\"";        xmlInfo += "/>";        return xmlInfo;    }    public String getDetails()    {        return "Name:" + fName +               ";Scope:" + fScope +               ";Requires:" + fRequires +               ";State:" + getStateAsString() +                ";Action:" + fAction;    }    public void execute(STAXThread thread)    {        if (fState == INIT)        {            try            {                fParentFunctionName = thread.pyStringEval("STAXCurrentFunction");            }            catch (STAXPythonEvaluationException e)            {                fParentFunctionName = "None";            }            // If local scope, save PythonInterpreter and clone it            if (fScope.equals("local"))            {                fSavePythonInterpreter = thread.getPythonInterpreter();                thread.setPythonInterpreter(fSavePythonInterpreter.clonePyi());            }            // Verify call arguments before putting function's action on the             // thread's action stack.            STAXSignalData signalData = new STAXSignalData();                        if (verifyArguments(thread, signalData) == 0)            {                // Set the STAXFunctionName variable to contain the name of                // the function currently being executed                thread.pySetVar("STAXCurrentFunction", fName);                thread.pushAction(fAction.cloneAction());                fState = FUNCTION_CALLED;            }            else // Verification of arguments failed            {                fState = COMPLETE;                thread.popAction();                // If local scope, reset PythonInterpreter before set STAXResult                if (fScope.equals("local") && (fSavePythonInterpreter != null))                {                    thread.setPythonInterpreter(fSavePythonInterpreter);                }                // Set STAXResult to STAXFunctionError                try                {                    thread.pyExec("STAXResult = STAXFunctionError");                }                catch (STAXPythonEvaluationException e)                {   // This should never happen                    String msg = "Error executing " +                        "STAXResult = STAXFunctionError after call to " +                        "function " + fName + "\n\n" + fCallXMLInfo;                    thread.setSignalMsgVar("STAXPythonEvalMsg", msg, e);                    thread.raiseSignal("STAXPythonEvaluationError");                    return;                }                // Check if a signal should be raised due to invalid arguments                if (!signalData.fSignalName.equals(""))                {                    thread.setSignalMsgVar(signalData.fMessageName,                                           signalData.fMessage,                                           signalData.fPythonException);                    thread.raiseSignal(signalData.fSignalName);                }            }            return;        }        else if (fState == FUNCTION_CALLED)        {            exitFunction(thread);                        thread.pySetVar("STAXResult", Py.None);        }    }    public void exitFunction(STAXThread thread)    {        fState = COMPLETE;        thread.popAction();        // If local scope, reset PythonInterpreter before set STAXResult        if (fScope.equals("local") && (fSavePythonInterpreter != null))        {            thread.setPythonInterpreter(fSavePythonInterpreter);        }        thread.pySetVar("STAXCurrentFunction", fParentFunctionName);    }    public void handleCondition(STAXThread thread, STAXCondition cond)    {        exitFunction(thread);        if (cond instanceof STAXReturnCondition)        {            STAXReturnCondition returnCondition = (STAXReturnCondition)cond;            thread.pySetVar("STAXResult", returnCondition.getData());            thread.removeCondition(returnCondition);        }        else        {            thread.pySetVar("STAXResult", Py.None);        }    }    public STAXAction cloneAction()    {        STAXFunctionAction clone = new STAXFunctionAction();        clone.fName = fName;        clone.fProlog = fProlog;        clone.fEpilog = fEpilog;        clone.fScope = fScope;        clone.fRequires = fRequires;        clone.fAction = fAction;        clone.fSavePythonInterpreter = fSavePythonInterpreter;        clone.fArgDefinition = fArgDefinition;        clone.fArgList = (ArrayList)fArgList.clone();        clone.fCallArgPyObject = fCallArgPyObject;        clone.fCallXMLInfo = fCallXMLInfo;        clone.fParentFunctionName = fParentFunctionName;        return clone;    }    // Verify valid arguments are passed to the function    // Returns:  0 if valid arguments; non-zero if invalid arguments    // Sets signalData values to indicate if a signal should be raised.    public int verifyArguments(STAXThread thread, STAXSignalData signalData)    {        if (fArgDefinition == FUNCTION_DEFINES_NO_ARGS)        {            // No verification can be done - assign arguments to STAXArg            thread.pySetVar("STAXArg", fCallArgPyObject);        }        else if (fArgDefinition == FUNCTION_ALLOWS_NO_ARGS)        {            if (fCallArgPyObject != null &&                !(fCallArgPyObject.toString().equals("None")))            {                // Error - no arguments can be passed on the call                signalData.fSignalName ="STAXFunctionArgValidate";                signalData.fMessageName = "STAXFunctionArgValidateMsg";                signalData.fMessage = fCallXMLInfo +                    "\n\nFunction " + fName + " does not allow arguments to " +                    "be passed to it";                return 1;            }        }        else if (fArgDefinition == FUNCTION_DEFINES_ONE_ARG)        {            STAXFunctionArgument arg = (STAXFunctionArgument)fArgList.get(0);            int argType = arg.getType();            String argName = arg.getName();            if (argType == ARG_REQUIRED)            {                if (fCallArgPyObject == null)                {                    // Error - must provide required arguments                    signalData.fSignalName ="STAXFunctionArgValidate";                    signalData.fMessageName = "STAXFunctionArgValidateMsg";                    signalData.fMessage = fCallXMLInfo +                        "\n\nRequired argument '" + argName +                        "' not provided in call to function " + fName;                    return 1;                }                else                {                       thread.pySetVar(argName, fCallArgPyObject);                }            }             else if (argType ==  ARG_OPTIONAL)            {                if (fCallArgPyObject == null)                {                    // Evaluate the default value                    try                    {                        thread.pyExec(argName + " = " + arg.getDefaultValue());                    }                    catch (STAXPythonEvaluationException e)                    {                        signalData.fSignalName = "STAXPythonEvaluationError";                        signalData.fMessageName = "STAXPythonEvalMsg";                        signalData.fMessage = getXMLInfo() +                            "\n\nArgument " + argName + " has an " +                            "invalid default value=" + arg.getDefaultValue();                        signalData.fPythonException = e;                        return 2;                    }                }                else                {                    thread.pySetVar(argName, fCallArgPyObject);                }            }            else                  {   // Should never happen                System.out.println("Invalid function argType=" + argType);                return 2;            }        }        else if (fArgDefinition == FUNCTION_DEFINES_LIST_ARGS)        {            // Extract a Python tuple or list (call arguments) into a Java List            ArrayList callArgList = new ArrayList();             if (fCallArgPyObject != null)            {                 if ((fCallArgPyObject instanceof PySequence) &&                    !(fCallArgPyObject instanceof PyString))                {                     thread.pySetVar("STAXTempList", fCallArgPyObject);                    callArgList =  new ArrayList(Arrays.asList(                        (PyObject[])thread.getPythonInterpreter().                              get("STAXTempList", PyObject[].class)));                }                else                {                    callArgList.add(fCallArgPyObject);                }            }            ListIterator callArgIter = callArgList.listIterator();            // Walk function's argument definition list            for (int i = 0; i < fArgList.size(); i++)            {                STAXFunctionArgument arg =                     (STAXFunctionArgument)fArgList.get(i);                int argType = arg.getType();

⌨️ 快捷键说明

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