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

📄 staxstafcommandactionfactory.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 org.w3c.dom.Node;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.NodeList;import com.ibm.staf.*;import java.util.TreeMap;import java.util.HashMap;import java.util.Map;import java.util.List;import java.util.ArrayList;import java.util.Iterator;/** * A factory class for creating STAXSTAFCommandAction objects based on * information obtained by parsing an XML node from a DOM tree for a * &lt;stafcmd&gt; element. * *@see STAXSTAFCommandAction */public class STAXSTAFCommandActionFactory implements STAXActionFactory,                                                     STAXListRequestHandler,                                                     STAXQueryRequestHandler,                                                     STAXJobManagementHandler{    static final String STAX_STAFCOMMAND_EVENT = new String("STAFCommand");    static final String sStafcmdInfoMapClassName = new String(        "STAF/Service/STAX/StafcmdInfo");    static final String sQueryStafcmdMapClassName = new String(        "STAF/Service/STAX/QueryStafcmd");    /**      * Creates a new STAXSTAFCommandActionFactory instance and registers     * with the STAX service to handle requests to LIST the active STAF     * commands in a job, to handle requests to QUERY a particular STAF     * command that running, and to manage a map of currently active     * STAF commands for a job.     */    public STAXSTAFCommandActionFactory(STAX staxService)    {        staxService.registerListHandler("STAFCMDS", this);        staxService.registerQueryHandler("STAFCMD", "Request#", this);        staxService.registerJobManagementHandler(this);        // Construct map-class for list stafcmd information        fStafcmdInfoMapClass = new STAFMapClassDefinition(            sStafcmdInfoMapClassName);        fStafcmdInfoMapClass.addKey("stafcmdName", "Stafcmd Name");        fStafcmdInfoMapClass.addKey("location",    "Location");        fStafcmdInfoMapClass.addKey("requestNum",  "Request#");        fStafcmdInfoMapClass.addKey("service",     "Service");        fStafcmdInfoMapClass.addKey("request",     "Request");        // Construct map-class for query stafcmd information        fQueryStafcmdMapClass = new STAFMapClassDefinition(            sQueryStafcmdMapClassName);        fQueryStafcmdMapClass.addKey("stafcmdName",    "Stafcmd Name");        fQueryStafcmdMapClass.addKey("location",       "Location");        fQueryStafcmdMapClass.addKey("requestNum",     "Request#");        fQueryStafcmdMapClass.addKey("service",        "Service");        fQueryStafcmdMapClass.addKey("request",        "Request");        fQueryStafcmdMapClass.addKey("blockName",      "Block Name");        fQueryStafcmdMapClass.addKey("threadID",       "Thread ID");        fQueryStafcmdMapClass.addKey("startTimestamp", "Start Date-Time");    }    public String getDTDInfo()    {        return fDTDInfo;    }    public String getDTDTaskName()    {        return "stafcmd";    }    public STAXAction parseAction(STAX staxService, STAXJob job,                                  org.w3c.dom.Node root) throws STAXException    {        STAXSTAFCommandAction command = new STAXSTAFCommandAction();        command.setActionFactory(this);        NamedNodeMap attrs = root.getAttributes();        for (int i = 0; i < attrs.getLength(); ++i)        {            Node thisAttr = attrs.item(i);                        if (thisAttr.getNodeName().equals("name"))            {                String errorInfo = "\n  Element: " + root.getNodeName() +                                   "  Attribute: " + thisAttr.getNodeName();                command.setName(                    STAXUtil.parseAndCompileForPython(                        thisAttr.getNodeValue(), errorInfo));            }            else            {                throw new STAXInvalidXMLAttributeException(                          root.getNodeName() + ": " + thisAttr.getNodeName());            }        }        NodeList children = root.getChildNodes();        for (int i = 0; i < children.getLength(); ++i)        {            Node thisChild = children.item(i);            if (thisChild.getNodeType() == Node.COMMENT_NODE)            {                /* Do nothing */            }            else if (thisChild.getNodeType() == Node.ELEMENT_NODE)            {                if (thisChild.getNodeName().equals("location"))                    command.setLocation(handleChild(thisChild));                else if (thisChild.getNodeName().equals("service"))                    command.setService(handleChild(thisChild));                else if (thisChild.getNodeName().equals("request"))                    command.setRequest(handleChild(thisChild));            }            else            {                throw new STAXInvalidXMLNodeTypeException(                          Integer.toString(thisChild.getNodeType()));            }        }        return command;    }    private String handleChild(Node root) throws STAXException    {        NamedNodeMap attrs = root.getAttributes();        for (int i = 0; i < attrs.getLength(); ++i)        {            Node thisAttr = attrs.item(i);            throw new STAXInvalidXMLAttributeException(                      root.getNodeName() + ": " + thisAttr.getNodeName());        }        NodeList children = root.getChildNodes();        for (int i = 0; i < children.getLength(); ++i)        {            Node thisChild = children.item(i);            // XXX: Should I be able to have a COMMENT_NODE here?            if (thisChild.getNodeType() == Node.COMMENT_NODE)            {                /* Do nothing */            }            else if (thisChild.getNodeType() == Node.TEXT_NODE)            {                String errorInfo = "\n  Element: stafcmd" +                                   "  Sub-element: " + root.getNodeName();                return STAXUtil.parseAndCompileForPython(                    thisChild.getNodeValue(), errorInfo);            }            else if (thisChild.getNodeType() == Node.CDATA_SECTION_NODE)            {                /* Do nothing */            }            else            {                throw new STAXInvalidXMLNodeTypeException(                          Integer.toString(thisChild.getNodeType()));            }        }        return new String();    }    // STAXJobManagement methods    public void initJob(STAXJob job)    {        boolean result = job.setData("stafcmdRequestMap", new TreeMap());         if (!result)        {            String msg = "STAXSTAFCommandActionFactory.initJob: setData for " +                         "stafcmdRequestMap failed.";            job.log(STAXJob.JOB_LOG, "error", msg);        }     }    public void terminateJob(STAXJob job)    { /* Do Nothing */ }    // STAXListRequestHandler method    public STAFResult handleListRequest(String type, STAXJob job,                                        STAXRequestSettings settings)    {        if (type.equalsIgnoreCase("stafcmds"))        {            // LIST JOB <Job ID> STAFCMDS            // Create the marshalling context and set its map class definitions            // and create an empty list to contain the block map entries            STAFMarshallingContext mc = new STAFMarshallingContext();            mc.setMapClassDefinition(fStafcmdInfoMapClass);            List stafcmdOutputList = new ArrayList();            // Iterate through the stafcmd map, generating the output list            TreeMap stafcmds = (TreeMap)job.getData("stafcmdRequestMap");            synchronized (stafcmds)            {                Iterator iter = stafcmds.values().iterator();                while (iter.hasNext())                {                    STAXSTAFCommandAction command =                        (STAXSTAFCommandAction)iter.next();                                        Map stafcmdMap = fStafcmdInfoMapClass.createInstance();                    stafcmdMap.put("stafcmdName", command.getName());                    stafcmdMap.put("location", command.getLocation());                    stafcmdMap.put("requestNum",                                   "" + command.getRequestNumber());                    stafcmdMap.put("service", command.getService());                    stafcmdMap.put("request",                                   STAFUtil.maskPrivateData(                                       command.getRequest()));                    stafcmdOutputList.add(stafcmdMap);                }            }            mc.setRootObject(stafcmdOutputList);            return new STAFResult(STAFResult.Ok, mc.marshall());        }        else            return new STAFResult(STAFResult.DoesNotExist, type);    }    // STAXQueryRequestHandler methods    public STAFResult handleQueryRequest(String type, String key, STAXJob job,                                        STAXRequestSettings settings)    {        if (type.equalsIgnoreCase("stafcmd"))        {            // QUERY JOB <Job ID> STAFCMD <Request#>            // Create the marshalling context and set its map class definition            STAFMarshallingContext mc = new STAFMarshallingContext();            mc.setMapClassDefinition(fQueryStafcmdMapClass);            TreeMap stafcmds = (TreeMap)job.getData("stafcmdRequestMap");            STAXSTAFCommandAction command;            synchronized (stafcmds)            {                if (!stafcmds.containsKey(key))                    return new STAFResult(STAFResult.DoesNotExist, key);                else                    command = (STAXSTAFCommandAction)stafcmds.get(key);            }             Map stafcmdMap = fQueryStafcmdMapClass.createInstance();            stafcmdMap.put("stafcmdName", command.getName());            stafcmdMap.put("location", command.getLocation());            stafcmdMap.put("requestNum", "" + command.getRequestNumber());            stafcmdMap.put("service", command.getService());            stafcmdMap.put("request",                           STAFUtil.maskPrivateData(command.getRequest()));            stafcmdMap.put("blockName", command.getCurrentBlockName());            stafcmdMap.put("threadID",                           "" + command.getThread().getThreadNumber());            stafcmdMap.put("startTimestamp", command.getStartTimestamp().                           getTimestampString());            mc.setRootObject(stafcmdMap);            return new STAFResult(STAFResult.Ok, mc.marshall());        }        else            return new STAFResult(STAFResult.DoesNotExist, type);    }    public STAFResult handleQueryJobRequest(STAXJob job,                                            STAXRequestSettings settings)    {        return new STAFResult(STAFResult.Ok, "");    }    private STAFMapClassDefinition fStafcmdInfoMapClass;    private STAFMapClassDefinition fQueryStafcmdMapClass;    private static String fDTDInfo ="\n" +"<!--================= The STAF Command Element ===================== -->\n" +"<!--\n" +"     Specifies a STAF command to be executed.\n" +"     Its name and all of its element values are evaluated via Python.\n" +"-->\n" +"<!ELEMENT stafcmd    (location, service, request)>\n" +"<!ATTLIST stafcmd\n" +"          name       CDATA   #IMPLIED\n" +">\n" +"<!ELEMENT service    (#PCDATA)>\n" +"<!ELEMENT request    (#PCDATA)>\n";}

⌨️ 快捷键说明

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