📄 stax.java
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2002, 2004, 2005 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/package com.ibm.staf.service.stax;import com.ibm.staf.*;import com.ibm.staf.service.*;import org.xml.sax.SAXNotRecognizedException;import org.xml.sax.SAXNotSupportedException;import org.xml.sax.InputSource;import java.util.HashMap;import java.util.TreeMap;import java.util.TreeSet;import java.util.List;import java.util.ArrayList;import java.util.Iterator;import java.util.LinkedList;import java.io.StringReader;import org.python.util.PythonInterpreter;import java.util.Properties;import java.util.jar.*;import java.io.IOException;import java.io.File;import java.util.Map;import java.io.BufferedReader;import java.util.StringTokenizer;import java.lang.reflect.Constructor;import java.lang.reflect.InvocationTargetException;public class STAX implements STAFServiceInterfaceLevel30, STAXJobCompleteListener{ static final String fVersion = "3.2.0"; // Version of STAF (or later) required for this service private final String kRequiredSTAFVersion = "3.1.0"; static boolean CACHE_PYTHON_CODE = true; static final String INLINE_DATA = "<inline data>"; static final String sNOT_PROVIDED = "<Not Provided>"; static final String sNONE = "<None>"; static final String sNA = "<N/A>"; static final String sQueueTypeJobWaitComplete = new String( "STAF/Service/STAX/JobWaitComplete/"); static final String sQueueTypeJobEnd = new String( "STAF/Service/STAX/Job/End"); static final String sJobResultMapClassName = new String( "STAF/Service/STAX/JobResult"); static final String sJobDetailsMapClassName = new String( "STAF/Service/STAX/JobDetails"); static final String sFunctionInfoMapClassName = new String( "STAF/Service/STAX/FunctionInfo"); static final String sArgInfoMapClassName = new String( "STAF/Service/STAX/ArgInfo"); static final String sArgPropertyInfoMapClassName = new String( "STAF/Service/STAX/ArgPropertyInfo"); static final String sArgPropertyDataInfoMapClassName = new String( "STAF/Service/STAX/ArgPropertyDataInfo"); static final String sJobInfoMapClassName = new String( "STAF/Service/STAX/JobInfo"); static final String sThreadInfoMapClassName = new String( "STAF/Service/STAX/ThreadInfo"); static final String sSettingsMapClassName = new String( "STAF/Service/STAX/Settings"); static final String sExtensionElementMapClassName = new String( "STAF/Service/STAX/ExtensionElement"); static final String sExtensionJarFileMapClassName = new String( "STAF/Service/STAX/ExtensionJarFile"); static final String sExtensionInfoMapClassName = new String( "STAF/Service/STAX/ExtensionInfo"); static final String sServiceExtensionMapClassName = new String( "STAF/Service/STAX/ServiceExtension"); static final String sMonitorExtensionMapClassName = new String( "STAF/Service/STAX/MonitorExtension"); static final String sQueryJobMapClassName = new String( "STAF/Service/STAX/QueryJob"); static final String sQueryThreadMapClassName = new String( "STAF/Service/STAX/QueryThread"); static final String sNotifieeMapClassName = new String( "STAF/Service/STAX/JobNotifiee"); static final String sAllNotifieeMapClassName = new String( "STAF/Service/STAX/Notifiee"); static final String PACKAGE_NAME = "com.ibm.staf.service.stax.STAX"; public static String lineSep; public static String fileSep; // STAF Service Interface Levels Supported for Generic Requests static final String INTERFACE_LEVEL_30 = "com.ibm.staf.service.STAFServiceInterfaceLevel30"; // STAX Service Error Code static final int ErrorSubmittingExecuteRequest = 4001; static final int BlockNotHeld = 4002; static final int BlockAlreadyHeld = 4003; static final String STAX_EXTENSION = new String("staf/stax/extension/"); static final String STAX_MONITOR_EXTENSION = new String("staf/staxmonitor/extension/"); static final String STAX_EXTENSION_INFO = new String("staf/staxinfo/extension"); public STAX() { /* Do Nothing */ } public STAFResult init(STAFServiceInterfaceLevel30.InitInfo info) { int rc = STAFResult.Ok; STAFResult res = new STAFResult(); try { fServiceName = info.name; // Get the services STAF handle fHandle = new STAFHandle("STAF/Service/" + info.name); // Resolve the line separator variable for the local machine res = STAFUtil.resolveInitVar("{STAF/Config/Sep/Line}", fHandle); if (res.rc != STAFResult.Ok) return res; lineSep = res.result; // Resolve the machine name variable for the local machine res = STAFUtil.resolveInitVar("{STAF/Config/Machine}", fHandle); if (res.rc != STAFResult.Ok) return res; fLocalMachineName = res.result; // Resolve the machine nickname variable for the local machine res = STAFUtil.resolveInitVar("{STAF/Config/MachineNickname}", fHandle); if (res.rc != STAFResult.Ok) return res; fLocalMachineNickname = res.result; // Resolve the file separator variable for the local machine res = STAFUtil.resolveInitVar("{STAF/Config/Sep/File}", fHandle); if (res.rc != STAFResult.Ok) return res; fileSep = res.result; // Get the STAF Instance UUID res = fHandle.submit2("local", "MISC", "WhoAreYou"); if (res.rc != 0) { System.out.println("Local MISC WhoAreYou request failed. " + "RC=" + res.rc + ", Result=" + res.result); return res; } STAFMarshallingContext mc = STAFMarshallingContext.unmarshall( res.result); Map resultsMap = (Map)mc.getRootObject(); fInstanceUUID = (String)resultsMap.get("instanceUUID"); // Verify that the required version of STAF is running on the // local service machine. // Note: Method compareSTAFVersion was added in STAF V3.1.0 try { res = STAFUtil.compareSTAFVersion( "local", fHandle, kRequiredSTAFVersion); if (res.rc != STAFResult.Ok) { if (res.rc == STAFResult.InvalidSTAFVersion) { return new STAFResult( STAFResult.ServiceConfigurationError, "Minimum required STAF version for this service " + "is not running." + lineSep + res.result); } else { return new STAFResult( STAFResult.ServiceConfigurationError, "Error verifying the STAF version. RC: " + res.rc + ", Additional info: " + res.result); } } } catch (Error err) { return new STAFResult( STAFResult.ServiceConfigurationError, "This service requires STAF Version " + kRequiredSTAFVersion + " or later."); } // Assign the location that the service can write data to, // <STAF Write Location>/service/<service name (lower-case)> // and create the directory if it doesn't exist. fDataDir = info.writeLocation + fileSep + "service" + fileSep + fServiceName.toLowerCase(); File dir = new File(fDataDir); if (!dir.exists()) { dir.mkdirs(); } if (info.serviceJar != null) { // Create the Jython Library directory if it doesn't exist yet // from the jython library data in the service's jarfile. // Set the classpath to point to the service's jar file and to // the jython.jar. res = STAFServiceSharedJython.setupJython( info.serviceJar, fHandle, info.writeLocation); if (res.rc != 0) { System.out.println(res.result); return res; } // Get the version of Jython distributed with the STAX service fJythonVersion = STAFServiceSharedJython.getJythonVersion(); // Initialize the PythonInterpreter's python.home to point to // the shared jython installation. Properties p = new Properties(); p.setProperty("python.home", STAFServiceSharedJython.getJythonDirName()); PythonInterpreter.initialize(System.getProperties(), p, null); } // Create a Xerces DOM parser to verify that Xerces is installed try { org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); } catch (NoClassDefFoundError e) { rc = STAFResult.ServiceConfigurationError; System.out.println( "ERROR: xercesImpl.jar is not in the classpath."); return new STAFResult( rc, "ERROR: xercesImpl.jar is not in the classpath."); } // Create a Python Interpreter to verify that Jython is installed try { STAXPythonInterpreter pyi = new STAXPythonInterpreter(); } catch (NoClassDefFoundError e) { rc = STAFResult.ServiceConfigurationError; System.out.println( "ERROR: jython.jar is not in the classpath."); return new STAFResult( rc, "ERROR: jython.jar is not in the classpath."); } // Verify that the version specified for the STAX service is valid try { STAFVersion serviceVersion = new STAFVersion(fVersion); } catch (NumberFormatException e) { rc = STAFResult.ServiceConfigurationError; System.out.println( "ERROR: " + fVersion + " is an invalid STAX service version." + lineSep + e.toString()); return new STAFResult( rc, "ERROR: " + fVersion + " is an invalid STAX service version." + lineSep + e.toString()); } // Assign the STAX service machine as the default EVENT service // machine and assign "Event" as the default EVENT service name. // These will be overridden if an EVENTSERVICEMACHINE or // EVENTSERVICENAME parameter is specified. fEventServiceMachine = "local"; fEventServiceName = "Event"; // Assign 5 as the default number of physical threads used by STAX fNumThreads = 5; // Parse PARMS if provided in the STAX configuration line if (info.parms != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -