📄 staxloopaction.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.ArrayList;import java.util.Iterator;public class STAXLoopAction implements STAXAction{ static final int INIT = 0; static final int CALLING_ACTIONS = 1; static final int COMPLETE = 2; static final String INIT_STRING = "INIT"; static final String CALLING_ACTIONS_STRING = "CALLING_ACTIONS"; static final String COMPLETE_STRING = "COMPLETE"; static final String STATE_UNKNOWN_STRING = "UNKNOWN"; private STAXLoopAction() { /* Do Nothing */ } public STAXLoopAction(String indexvar, String from, String to, String by, String in_while, String until, STAXAction action) { fIndexvar = indexvar; fFrom = from; fTo = to; fBy = by; fWhile = in_while; fUntil = until; fAction = action; } public String getStateAsString() { switch (fState) { case INIT: return INIT_STRING; case CALLING_ACTIONS: return CALLING_ACTIONS_STRING; case COMPLETE: return COMPLETE_STRING; default: return STATE_UNKNOWN_STRING; } } public String getXMLInfo() { String optional_value1 = null; String optional_value2 = null; if (fIndexvar != null) optional_value1 = "var=\"" + fIndexvar + "\" "; if (fTo != null) optional_value2 = " to=\"" + fTo + "\""; if (fWhile != null) optional_value2 += " while=\"" + fWhile + "\""; if (fUntil != null) optional_value2 += " until=\"" + fUntil + "\""; return "<loop " + optional_value1 + "from=\"" + fFrom + "\" by=\"" + fBy + "\"" + optional_value2 + ">"; } public String getInfo() { StringBuffer result = new StringBuffer(); result.append("var=").append(fCurrLoopIndex - fByInt); if (fTo != null) result.append(" to ").append(fToInt); else if (fWhile == null && fUntil == null) result.append(" to forever"); if (fByInt != 1) result.append(" by ").append(fByInt); if (fWhile != null) result.append(" with while"); if (fUntil != null) result.append(" with until"); return result.toString(); } public String getDetails() { return "State:" + getStateAsString() + ";CurrLoopIndex:" + fCurrLoopIndex + ";Indexvar:" + fIndexvar + ";From:" + fFrom + ";FromInt:" + fFromInt + ";To:" + fTo + ";ToInt:" + fToInt + ";By:" + fBy + ";ByInt:" + fByInt + ";While:" + fWhile + ";Until:" + fUntil + ";To_Descending:" + fTo_Descending + ";ContinueLoop:" + fContinueLoop + ";Action:" + fAction; } public void execute(STAXThread thread) { try { if (fState == INIT) { // Evaluate integers fFrom, fTo, and fBy. fFromInt = thread.pyIntEval(fFrom); fCurrLoopIndex = fFromInt; if (fTo != null) fToInt = thread.pyIntEval(fTo); fByInt = thread.pyIntEval(fBy); if (fByInt < 0) fTo_Descending = true; else fTo_Descending = false; fState = CALLING_ACTIONS; } else if (fState == CALLING_ACTIONS) { if (fContinueLoop) { // Assign indexvar Jython variable, if provided if (fIndexvar != null) thread.pySetVar(fIndexvar, new Integer(fCurrLoopIndex)); if (fTo != null && ! fTo_Descending) fContinueLoop = fCurrLoopIndex <= fToInt; else if (fTo != null && fTo_Descending) fContinueLoop = fCurrLoopIndex >= fToInt; if (fContinueLoop && fWhile != null) fContinueLoop = thread.pyBoolEval(fWhile); if (fContinueLoop) { thread.pushAction(fAction.cloneAction()); if (fUntil != null) { fContinueLoop = ! thread.pyBoolEval(fUntil); } fCurrLoopIndex += fByInt; } else { fState = COMPLETE; thread.popAction(); } } else { fState = COMPLETE; thread.popAction(); } } } catch (STAXPythonEvaluationException e) { fState = COMPLETE; thread.popAction(); thread.setSignalMsgVar("STAXPythonEvalMsg", getXMLInfo(), e); thread.raiseSignal("STAXPythonEvaluationError"); } } public void handleCondition(STAXThread thread, STAXCondition cond) { // XXX: We need to "visit" all the conditions to remove any other // break or continue conditions if ((cond instanceof STAXBreakCondition) || (cond instanceof STAXContinueCondition)) { thread.visitConditions(new STAXVisitor() { public void visit(Object o, Iterator iter) { if ((o instanceof STAXBreakCondition) || (o instanceof STAXContinueCondition)) { iter.remove(); } } }); } if (!(cond instanceof STAXContinueCondition)) { fState = COMPLETE; thread.popAction(); } } public STAXAction cloneAction() { STAXLoopAction clone = new STAXLoopAction(); clone.fIndexvar = fIndexvar; clone.fFrom = fFrom; clone.fTo = fTo; clone.fBy = fBy; clone.fWhile = fWhile; clone.fUntil = fUntil; clone.fAction = fAction; return clone; } private int fState = INIT; private int fCurrLoopIndex = 0; private boolean fTo_Descending = false; private int fFromInt; private int fToInt; private int fByInt; private boolean fContinueLoop = true; private String fIndexvar; private String fFrom; private String fTo; private String fBy; private String fWhile; private String fUntil; private STAXAction fAction = null;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -