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

📄 staxtryaction.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002                                              *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/package com.ibm.staf.service.stax;import java.util.List;import java.util.LinkedList;import java.util.Iterator;public class STAXTryAction implements STAXAction{    static final int INIT = 0;    static final int CALLED_ACTION = 1;    static final int COMPLETE = 2;    static final String INIT_STRING = "INIT";    static final String CALLED_ACTION_STRING = "CALLED_ACTION";    static final String COMPLETE_STRING = "COMPLETE";    static final String STATE_UNKNOWN_STRING = "UNKNOWN";    public STAXTryAction(STAXAction action, List catchList)    {        fAction = action;        fCatchList = catchList;    }    public String getStateAsString()    {        switch (fState)        {            case INIT:                return INIT_STRING;            case CALLED_ACTION:                return CALLED_ACTION_STRING;            case COMPLETE:                return COMPLETE_STRING;            default:                return STATE_UNKNOWN_STRING;        }    }    public String getXMLInfo()    {        return "<try>";    }     public String getInfo()    {        return "";    }    public String getDetails()    {        return "State:" + getStateAsString() +                ";Action:" + fAction +               ";CatchList:" + fCatchList;    }    STAXCatchAction getCatchHandler(STAXExceptionCondition ex)    {        String exceptionName = ex.getName();        Iterator iter = fNamedCatchList.iterator();        while (iter.hasNext())        {            NamedCatch namedCatch = (NamedCatch)iter.next();            if (namedCatch.name.equals("...") ||                namedCatch.name.equals(exceptionName) ||                (exceptionName.startsWith(namedCatch.name) &&                 (exceptionName.charAt(namedCatch.name.length()) == '.')))            {                return namedCatch.catchAction;            }        }        return null;    }    public void execute(STAXThread thread)    {        if (fState == INIT)        {            fNamedCatchList = new LinkedList();            Iterator iter = fCatchList.iterator();            while (iter.hasNext())            {                STAXCatchAction catchAction = (STAXCatchAction)iter.next();                try                {                    fNamedCatchList.add(new NamedCatch(thread.pyStringEval(                        catchAction.getCatchableExceptionName()), catchAction));                }                catch (STAXPythonEvaluationException e)                {                    String msg = "<try> with <catch> with exception=" +                        catchAction.getCatchableExceptionName();                    thread.popAction();                    thread.setSignalMsgVar("STAXPythonEvalMsg", msg, e);                    thread.raiseSignal("STAXPythonEvaluationError");                    return;                }            }            thread.pushAction(fAction.cloneAction());            fState = CALLED_ACTION;        }         else if (fState == CALLED_ACTION)        {            fState = COMPLETE;            thread.popAction();        }    }    public void handleCondition(STAXThread thread, STAXCondition cond)    {        fState = COMPLETE;        thread.popAction();        if (cond instanceof STAXExceptionCondition)        {            STAXExceptionCondition ex = (STAXExceptionCondition)cond;            STAXCatchAction handler = getCatchHandler(ex);            if (handler != null)            {                // Push the catch block action                handler = (STAXCatchAction)handler.cloneAction();                handler.setException(ex);                thread.pushAction(handler);                // Remove any conditions we would handle                // Note: We only end up removing exceptions if we handle the                //       current exception                // XXX: Is the above note the correct way to handle things,                //      or should we always remove exceptions we could                //      handle?                thread.visitConditions(new STAXVisitor()                {                    public void visit(Object o, Iterator iter)                    {                        if (o instanceof STAXExceptionCondition)                        {                            STAXCatchAction handler =                                getCatchHandler((STAXExceptionCondition)o);                            if (handler != null) iter.remove();                        }                    }                });            }        }    }    public STAXAction cloneAction()    {        return new STAXTryAction(fAction, fCatchList);    }    class NamedCatch    {        public NamedCatch(String name, STAXCatchAction catchAction)        {            this.name = name;            this.catchAction = catchAction;        }        String name;        STAXCatchAction catchAction;    }    private int fState = INIT;    private STAXAction fAction = null;    private List fCatchList = null;    private LinkedList fNamedCatchList = null;}

⌨️ 快捷键说明

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