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

📄 staxcallwithmapactionfactory.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;public class STAXCallWithMapActionFactory implements STAXActionFactory{    private static String fDTDInfo ="\n" +"<!--================= The Call-With-Map Element ==================== -->\n" +"<!--\n" +"     Perform a function with the referenced name with any number of\n" +"     arguments in the form of a map of named arguments.  The function\n" +"     and name attribute values as well as the argument value are\n" +"     evaluated via Python.\n" +"-->\n" +"<!ELEMENT call-with-map       (call-map-arg*)>\n" +"<!ATTLIST call-with-map\n" +"          function   CDATA    #REQUIRED\n" +">\n" +"\n" +"<!ELEMENT call-map-arg        (#PCDATA)>\n" +"<!ATTLIST call-map-arg\n" +"          name       CDATA    #REQUIRED\n" +">\n";    public String getDTDInfo()    {        return fDTDInfo;    }    public String getDTDTaskName()    {        return "call-with-map";    }    public STAXAction parseAction(STAX staxService, STAXJob job,                                  org.w3c.dom.Node root) throws STAXException    {        String functionName = new String();        STAXCallAction action = new STAXCallAction();                    NamedNodeMap rootAttrs = root.getAttributes();        for (int i = 0; i < rootAttrs.getLength(); ++i)        {            Node thisAttr = rootAttrs.item(i);            String errorInfo = "\n  Element: " + root.getNodeName() +                               "  Attribute: " + thisAttr.getNodeName();            if (thisAttr.getNodeName().equals("function"))            {                action.setFunction(STAXUtil.parseAndCompileForPython(                    thisAttr.getNodeValue(), errorInfo));            }            else            {                throw new STAXInvalidXMLAttributeException(                    root.getNodeName() + ": " + thisAttr.getNodeName());            }        }        // Determine which call element is being processed                action.setCallType(STAXCallAction.CALL_MAP_ARGS);        // Iterate its children nodes to get arguments passed in (if any)        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)            {                String name = "None";                if (thisChild.getNodeName().equals("call-map-arg"))                {                    NamedNodeMap attrs = thisChild.getAttributes();                    for (int j = 0; j < attrs.getLength(); ++j)                    {                        Node thisAttr = attrs.item(j);                        String errorInfo = "\n  Element: " +                             thisChild.getNodeName() + "  Attribute: " +                             thisAttr.getNodeName();                                                if (thisAttr.getNodeName().equals("name"))                        {                            name = (STAXUtil.parseAndCompileForPython(                                thisAttr.getNodeValue(), errorInfo));                        }                        else                        {                            throw new STAXInvalidXMLAttributeException(                                thisChild.getNodeName() + ": " +                                thisAttr.getNodeName());                        }                    }                    // Add named argument to argument map                    action.addMapArg(name, handleChild(thisChild));                }                else                 {                    throw new STAXInvalidXMLElementCountException(                        thisChild.getNodeName());                }            }            else            {                throw new STAXInvalidXMLNodeTypeException(                    Integer.toString(thisChild.getNodeType()));            }        }        return action;    }    String handleChild(Node root) throws STAXException    {        String errorInfo = "\n  Element: " + root.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)            {                throw new STAXInvalidXMLElementException(                    thisChild.getNodeName());            }            else if (thisChild.getNodeType() == Node.TEXT_NODE)            {                return STAXUtil.parseAndCompileForPython(                    thisChild.getNodeValue(), errorInfo);            }        }        return null;    }}

⌨️ 快捷键说明

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