📄 staxiterateaction.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.Iterator;public class STAXIterateAction 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 STAXIterateAction() { /* Do Nothing */ } public STAXIterateAction(String itemvar, String in, String indexvar, STAXAction action) { fItemvar = itemvar; fIn = in; fIndexvar = indexvar; 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() { if (fIndexvar.equals("")) return "<iterate var=\"" + fItemvar + "\" in=\"" + fIn + "\">"; else return "<iterate var=\"" + fItemvar + "\" in=\"" + fIn + "\" indexvar=\"" + fIndexvar + "\">"; } public String getInfo() { int inLength = fIn.length(); if (inLength > 40) return fCurrListIndex + " " + fIn.substring(0, 40) + "..."; else return fCurrListIndex + " " + fIn; } public String getDetails() { return "State:" + getStateAsString() + ";CurrListIndex:" + fCurrListIndex + ";ListSize:" + fListSize + ";Itemvar:" + fItemvar + ";In:" + fIn + ";Indexvar:" + fIndexvar + ";Action:" + fAction + ";List:" + fList; } public void execute(STAXThread thread) { try { if (fState == INIT) { // Create a list/tuple in Jython from fIn and then extract // the Python tuple or array into a Java List. fList = thread.pyListEval(fIn); fListSize = fList.size(); if (fListSize == 0) { // Nothing in list, so done; raise a signal. fState = COMPLETE; thread.popAction(); thread.setSignalMsgVar("STAXEmptyListMsg", getXMLInfo()); thread.raiseSignal("STAXEmptyList"); } fState = CALLING_ACTIONS; } else if (fState == CALLING_ACTIONS) { if (fListSize > fCurrListIndex) { // Assign indexvar Jython variable, if provided if (fIndexvar != null) thread.pySetVar(fIndexvar, new Integer(fCurrListIndex)); // Assign itemvar Jython variable Object itemValue = (Object)fList.get(fCurrListIndex++); thread.pySetVar(fItemvar, itemValue); thread.pushAction(fAction.cloneAction()); } 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() { STAXIterateAction clone = new STAXIterateAction(); clone.fItemvar = fItemvar; clone.fIn = fIn; clone.fIndexvar = fIndexvar; clone.fAction = fAction; return clone; } private int fState = INIT; private int fCurrListIndex = 0; private List fList = null; private int fListSize = 0; private String fItemvar; private String fIn; private String fIndexvar; private STAXAction fAction = null;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -