📄 staxthread.java
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2002, 2004 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/package com.ibm.staf.service.stax;import java.util.HashMap;import java.util.TreeMap;import java.util.TreeSet;import java.util.List;import java.util.LinkedList;import java.util.Iterator;import java.util.ArrayList;import java.util.Arrays;import java.util.Map;import java.util.Comparator;import org.python.util.PythonInterpreter;import org.python.core.*;import com.ibm.staf.STAFMarshallingContext;public class STAXThread implements STAXThreadCompleteListener{ // Thread states public static final int STATE_RUNNABLE = 0; public static final int STATE_RUNNING = 1; public static final int STATE_BLOCKED = 2; public static final int STATE_COMPLETE = 3; public static final String STATE_RUNNABLE_STRING = new String("Runnable"); public static final String STATE_RUNNING_STRING = new String("Running"); public static final String STATE_BLOCKED_STRING = new String("Blocked"); public static final String STATE_COMPLETE_STRING = new String("Complete"); public static final String STATE_UNKNOWN_STRING = new String("Unknown"); // Completion codes public static final int THREAD_END_OK = 0; public static final int THREAD_END_DUPLICATE_SIGNAL = 1; public static final int THREAD_END_STOPPED_BY_PARENT = 2; // How many non-blocking actions may a thread execute before blocking public static final int MAX_NON_BLOCKING_ACTIONS = 100; // Turn on/off thread debugging private static final boolean STAX_DEBUG_THREAD = false; private STAXThread() { /* Do Nothing */ } // This creates another first-level thread for the job public STAXThread(STAXJob job) { fJob = job; fThreadNumber = job.getNextThreadNumber(); fPythonInterpreter.set("STAXThreadID", new Integer(fThreadNumber)); fPythonInterpreter.exec("STAXTestcaseStack = []"); fPythonInterpreter.set("STAXCurrentTestcase", Py.None); fPythonInterpreter.exec("STAXBlockStack = []"); fPythonInterpreter.set("STAXCurrentBlock", Py.None); // Import Java and Jython modules and classes and define a // cloneLocals function fPythonInterpreter.exec( "from com.ibm.staf import STAFResult as STAFRC \n" + "import STAFMarshalling \n" + "from STAFMarshalling import STAFMapClassDefinition, STAFMarshallingContext \n" + "import copy \n" + "import types \n" + "import org.python.core.PyFunction \n" + // Save the Python built-in function named type in a variable // named STAXBuiltinFunction_type in case a STAX xml file sets // the type variable to something else. Instead of type, use // STAXBuiltinFunction_type in the STAXCloneGlobals function. "STAXBuiltinFunction_type = type \n" + // Import the copy, types, and PyFunction modules in the CloneGlobals // function so that if someone uses a variable named copy or types // within a STAX job it won't interfere with these module names. "def STAXPythonFunction_CloneGlobals(STAXGlobals): \n" + " import copy \n" + " import types \n" + " import org.python.core.PyFunction \n" + "\n" + " STAXclone = copy.copy(STAXGlobals) \n" + " STAXskipTypes = [types.ModuleType, types.FunctionType, \n" + " types.ClassType, \n" + " # since no StringMapType, use type(STAXclone) \n" + " STAXBuiltinFunction_type(STAXclone)] \n" + " for STAXkey in STAXclone.keys(): \n" + " if (STAXBuiltinFunction_type(STAXclone[STAXkey]) not in STAXskipTypes): \n" + " try: \n" + " STAXclone[STAXkey] = copy.deepcopy(STAXclone[STAXkey])\n" + " except: \n" + " pass # ignore types that cannot be deepcopied \n" + // This section checks to see if the variable is a function definition // that was defined at the "global" scope, i.e., not within some other // Python module. If so, then it replaces the function definition // with one that is identical except for the reference to the global // variable pool, which is redirected to look at the new global // variable pool being created. // // This was necessary, otherwise any variables created in the clone // are not accessable to functions defined before the clone. // Note, the "func_defaults or []" is necessary due to a bug in // Jython 2.1. The PyFunction constructor doesn't handle a Null // parameter for func_defaults. Note that it does handle func_closure // appropriately. " elif ((STAXBuiltinFunction_type(STAXclone[STAXkey]) is types.FunctionType) and \n" + " (STAXclone[STAXkey].func_globals is STAXGlobals)): \n" + " STAXclone[STAXkey] = org.python.core.PyFunction(\n" + " STAXclone,\n" + " STAXclone[STAXkey].func_defaults or [],\n" + " STAXclone[STAXkey].func_code,\n" + " STAXclone[STAXkey].func_doc,\n" + " STAXclone[STAXkey].func_closure)\n" + " return STAXclone \n" + "\n" + "def STAXPythonFunction_FunctionExists(STAXfunction): \n" + " return STAXJob.functionExists(STAXfunction) \n" + "\n" + "class STAXUnique: \n" + " def __init__(self, name): \n" + " self.name = name \n" + " def __str__(self): \n" + " return str(self.name) \n" + " def __repr__(self): \n" + " return 'STAXUnique(%s)' % self.name \n" + "\n" + "STAXFunctionError = STAXUnique('STAXFunctionError') \n" + "\n" + "STAXNoResponseFromMachine = " + "STAXUnique('STAXNoResponseFromMachine') \n" + "\n" + "STAXFileCopyError = STAXUnique('STAXFileCopyError') \n" + "\n" + "STAXXMLParseError = STAXUnique('STAXXMLParseError') \n" + "\n" + "STAXImportModeError = STAXUnique('STAXImportModeError') \n" + "\n" + "class STAXGlobal: \n" + "\n\n" + " # Basic customization \n" + "\n\n" + " # constructor, optional value \n" + " def __init__(self, value = None): \n" + " self.data = value \n" + "\n" + " def __del__(self): \n" + " del self \n" + "\n" + " # returns a string representation \n" + " def __repr__(self): \n" + " return repr(self.data) \n" + "\n" + " def __str__(self): \n" + " return str(self.data) \n" + "\n" + " def __lt__(self, other): \n" + " if self.data < other: \n" + " return true \n" + " else: \n" + " return false \n" + "\n" + " def __le__(self, other): \n" + " if self.data <= other: \n" + " return true \n" + " else: \n" + " return false \n" + "\n" + " def __eq__(self, other): \n" + " if self.data == other: \n" + " return true \n" + " else: \n" + " return false \n" + "\n" + " def __ne__(self, other): \n" + " if self.data != other: \n" + " return true \n" + " else: \n" + " return false \n" + "\n" + " def __gt__(self, other): \n" + " if self.data > other: \n" + " return true \n" + " else: \n" + " return false \n" + "\n" + " def __ge__(self, other): \n" + " if self.data >= other: \n" + " return true \n" + " else: \n" + " return false \n" + "\n" + " def __cmp__(self, other): \n" + " return self.data.cmp(other) \n" + "\n" + " def __hash__(self): \n" + " return hash(self.data) \n" + "\n" + " # Not implementing __nonzero__ \n" + "\n" + " # Customizing attribute access \n" + "\n" + " def __getattr__(self, name): \n" + " return getattr(self.data, name) \n" + "\n" + /* Not implementing __setattr__ and __delattr__ yet " # Not sure if these are the correct implementations " def __setattr__(self, name, value): \n" + " self.__dict__[name] = value \n" + "\n" + " def __delattr__(self, name): \n" + " del self.__dict__[name] \n" + "\n" + */ " # Emulating callable objects \n" + "\n" + " # Not implementing __call__ \n" + "\n" + " # Emulating container types \n" + "\n" + " def __len__(self): \n" + " return len(self.data) \n" + "\n" + " def __getitem__(self, key): \n" + " return self.data[key] \n" + "\n" + " def __setitem__(self, key, value): \n" + " self.data[key] = value \n" + "\n" + " def __delitem__(self, key): \n" + " del self.data[key] \n" + "\n" + " # XXX: iter() is new in Python 2.2 so not supported yet" + " # def __iter__(self): \n" + " # return iter(self.data) \n" + "\n" + " def __contains__(self, item): \n" + " return item in self.data \n" + "\n" + " # Additional methods for emulation of sequence types \n" + "\n" + " # Not implementing getslice, setslice, delslice - deprecated \n" + "\n" + " # Emulating numeric types \n" + " def __add__(self, other): \n" + " return self.data + other \n" + "\n" + " def __sub__(self, other): \n" + " return self.data - other \n" + "\n" + " def __mul__(self, other): \n" + " return self.data * other \n" + "\n" + " # Commented out - get SyntaxError when run \n" + " # def __floordiv__(self, other): \n" + " # return self.data // other \n" + "\n" + " def __mod__(self, other): \n" + " return self.data % other \n" + "\n" + " def __divmod__(self, other): \n" + " return self.data.divmod(other) \n" + "\n" + " def __pow__(self, other, modulo=None): \n" + " return self.data.pow(other) # ??? modulo \n" + "\n" + " def __lshift__(self, other): \n" + " return self.data << other \n" + "\n" + " def __rshift__(self, other): \n" + " return self.data >> other \n" + "\n" + " def __and__(self, other): \n" + " return self.data & other \n" + "\n" + " def __xor__(self, other): \n" + " return self.data ^ other \n" + "\n" + " def __or__(self, other): \n" + " return self.data | other \n" + "\n" + " def __div__(self, other): \n" + " return self.data / other \n" + "\n" + " def __truediv__(self, other): \n" + " return self.data / other \n" + "\n" + " def __radd__(self, other): \n" + " return other + self.data \n" + "\n" + " def __rsub__(self, other): \n" + " return other - self.data \n" + "\n" + " def __rmul__(self, other): \n" + " return other * self.data \n" + "\n" + " def __rdiv__(self, other): \n" + " return other / self.data \n" + "\n" + " def __rmod__(self, other): \n" + " return other % self.data \n" + "\n" + " def __rdivmod__(self, other): \n" + " return other.divmod(self.data) \n" + "\n" + " def __rpow__(self, other): \n" + " return other.pow(self.data) \n" + "\n" + " def __rlshift__(self, other): \n" + " return other << self.data \n" + "\n" + " def __rrshift__(self, other): \n" + " return other >> self.data \n" + "\n" + " def __rand__(self, other): \n" + " return other | self.data \n" + "\n" + " def __rxor__(self, other): \n" + " return other ^ self.data \n" + "\n" + " def __ror__(self, other): \n" + " return other | self.data \n" + "\n" + " def __iadd__(self, other): \n" + " self.data += other \n" + " return self \n" + "\n" + " def __isub__(self, other): \n" + " self.data -= other \n" + " return self \n" + "\n" + " def __imul__(self, other): \n" + " self.data *= other \n" + " return self \n" + "\n" + " def __idiv__(self, other): \n" + " self.data /= other \n" + " return self \n" + "\n" + " def __imod__(self, other): \n" + " self.data %= other \n" + " return self \n" + "\n" + " def __ipow__(self, other): \n" + " self.data **= other \n" + " return self \n" + "\n" + " def __ilshift__(self, other): \n" + " self.data <<= other \n" + " return self \n" + "\n" + " def __irshift__(self, other): \n" + " self.data >>= other \n" + " return self \n" + "\n" + " def __iand__(self, other): \n" + " self.data &= other \n" + " return self \n" + "\n" + " def __ixor__(self, other): \n" + " self.data ^= other \n" + " return self \n" + "\n" + " def __ior__(self, other): \n" + " self.data |= other \n" + " return self \n" + "\n" + " def __neg__(self): \n" + " self.data = -self.data \n" + " return self \n" + "\n" + " def __pos__(self): \n" + " self.data = +self.data \n" + " return self \n" + "\n" + " def __abs__(self): \n" + " self.data = abs(self.data) \n" + " return self \n" + "\n" + " def __invert__(self): \n" + " self.data = ~self.data \n" + " return self \n" + "\n" + " def __complex__(self): \n" + " return complex(self.data) \n" + "\n" + " def __int__(self): \n" + " return int(self.data) \n" + "\n" + " def __long__(self): \n" + " return long(self.data) \n" + "\n" + " def __float__(self): \n" + " return float(self.data) \n" + "\n" + " def __oct__(self): \n" + " return oct(self.data) \n" + "\n" + " def __hex__(self): \n" + " return hex(self.data) \n" + "\n" + " # XXX: Currently not defining __coerce__(self, other) \n" + "\n" + " # Providing set and get methods \n" + "\n" + " def set(self, value): \n" + " self.data = value \n" + "\n" + " def get(self): \n" + " return self.data \n" + "\n" + " # Implementing deepcopy so will be global \n" + " def __deepcopy__(self): \n" + " return self \n" + "\n" + " # Providing an append method \n" + " def append(self, other): \n" + " self.data.append(other) \n" + " return self \n" + "\n" + " # Provide a stafMarshall method \n" + " def stafMarshall(self, context): \n" + " import STAFMarshalling \n" + " return STAFMarshalling.marshall(self.data, context) \n" +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -