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

📄 staxblockactionfactory.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    blocksRunningState += 1;                else if (block.getBlockState() ==                                             STAXBlockAction.BLOCK_HELD)                    blocksHeldState += 1;                else                    blocksUnknownState += 1;            }        }        // XXX: Change to pass in the marshalling context         STAFMarshallingContext mc = new STAFMarshallingContext();        Map blockOutputMap = new HashMap();        blockOutputMap.put("numBlocksRunning", "" + blocksRunningState);        blockOutputMap.put("numBlocksHeld", "" + blocksHeldState);        blockOutputMap.put("numBlocksUnknown", "" + blocksUnknownState);        mc.setRootObject(blockOutputMap);        return new STAFResult(STAFResult.Ok, mc.marshall());     }    public String getDTDInfo()    {        return fDTDInfo;    }    public String getDTDTaskName()    {        return "block";    }    public STAXAction parseAction(STAX staxService, STAXJob job,                                  org.w3c.dom.Node root) throws STAXException    {        String blockName = new String();        STAXAction blockAction = null;        NamedNodeMap attrs = root.getAttributes();        for (int i = 0; i < attrs.getLength(); ++i)        {            Node thisAttr = attrs.item(i);            String errorInfo = "\n  Element: " + root.getNodeName() +                               "  Attribute: " + thisAttr.getNodeName();            if (thisAttr.getNodeName().equals("name"))            {                blockName = 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 (blockAction != null)                {                    throw new STAXInvalidXMLElementCountException(                              thisChild.getNodeName());                }                STAXActionFactory factory =                    staxService.getActionFactory(thisChild.getNodeName());                if (factory == null)                {                    throw new STAXInvalidXMLElementException(                              thisChild.getNodeName());                }                blockAction = factory.parseAction(staxService, job, thisChild);            }            else            {                throw new STAXInvalidXMLNodeTypeException(                          Integer.toString(thisChild.getNodeType()));            }        }        return new STAXBlockAction(blockName, blockAction);    }    // STAXGenericRequestHandler Interface Methods    public STAFResult handleRequest(Object infoObject, STAX staxService)    {        STAFServiceInterfaceLevel30.RequestInfo info =            (STAFServiceInterfaceLevel30.RequestInfo)infoObject;        // Parse the request        STAFCommandParseResult parseResult= fHRTParser.parse(info.request);        if (parseResult.rc != STAFResult.Ok)        {            if ((parseResult.numInstances() >= 1) &&                ((parseResult.instanceName(1).equalsIgnoreCase("HOLD")) ||                 (parseResult.instanceName(1).equalsIgnoreCase("RELEASE")) ||                 (parseResult.instanceName(1).equalsIgnoreCase("TERMINATE"))))            {                return new STAFResult(STAFResult.InvalidRequestString,                                      parseResult.errorBuffer);            }            else            {   // Returning nothing in the result indicates that this parser                // does not support this request.                return new STAFResult(STAFResult.InvalidRequestString, "");            }        }        // Verify the requesting machine/user has at least trust level 4        String request = "";        if (parseResult.optionTimes("HOLD") != 0)            request = "HOLD";        else if (parseResult.optionTimes("RELEASE") != 0)            request = "RELEASE";        else if (parseResult.optionTimes("TERMINATE") != 0)            request = "TERMINATE";        STAFResult trustResult = STAFUtil.validateTrust(            4, staxService.getServiceName(), request,            staxService.getLocalMachineName(), info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        STAXJob job = null;        try        {            job = (STAXJob)staxService.getJobMap().get(                  new Integer(parseResult.optionValue("JOB")));            if (job == null)            {                return new STAFResult(STAFResult.DoesNotExist,                                      parseResult.optionValue("JOB"));            }        }        catch (NumberFormatException e)        {            return new STAFResult(STAFResult.InvalidValue,                                  parseResult.optionValue("JOB"));        }        String blockName = new String("main");        if (parseResult.optionTimes("BLOCK") != 0)            blockName = parseResult.optionValue("BLOCK");        TreeMap blockMap = (TreeMap)job.getData("blockMap");        if (!blockMap.containsKey(blockName))            return new STAFResult(STAFResult.DoesNotExist, blockName);        STAXBlockAction theBlock = (STAXBlockAction)blockMap.get(blockName);        if (parseResult.optionTimes("HOLD") != 0)        {            if (theBlock.getBlockState() == STAXBlockAction.BLOCK_HELD)                return new STAFResult(BlockAlreadyHeld,                                      "Block already held");            String msg = "Received HOLD BLOCK "  + blockName + " request";            job.log(STAXJob.JOB_LOG, "info", msg);            theBlock.holdBlock();        }        else if (parseResult.optionTimes("RELEASE") != 0)        {            if (theBlock.getBlockState() != STAXBlockAction.BLOCK_HELD)                return new STAFResult(BlockNotHeld, "Block not held");            String msg = "Received RELEASE BLOCK " + blockName + " request";            job.log(STAXJob.JOB_LOG, "info", msg);            theBlock.releaseBlock();        }        else        {            String msg = "Received TERMINATE BLOCK "  + blockName + " request";            job.log(STAXJob.JOB_LOG, "info", msg);            theBlock.terminateBlock();        }        return new STAFResult(STAFResult.Ok);    }    public String getHelpInfo(String lineSep)    {        return "HOLD      JOB <Job ID> [BLOCK <Block Name>]" +               lineSep + lineSep +               "RELEASE   JOB <Job ID> [BLOCK <Block Name>]" +               lineSep + lineSep +               "TERMINATE JOB <Job ID> [BLOCK <Block Name>]";    }    private STAFCommandParser fHRTParser = new STAFCommandParser();    private STAFMapClassDefinition fBlockInfoMapClass;    private STAFMapClassDefinition fQueryBlockMapClass;}

⌨️ 快捷键说明

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