📄 staxtryactionfactory.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 java.util.List;import java.util.ArrayList;public class STAXTryActionFactory implements STAXActionFactory{ private static String fDTDInfo ="\n" +"<!--================= The Try / Catch Block Elements =============== -->\n" +"<!--\n" +" The try element allows you to perform an action and to catch\n" +" exceptions that are thrown.\n" +"-->\n" +"<!ELEMENT try ((%task;), catch+)>\n" +"<!--\n" +" The catch element performs a task when the specified exception is\n" +" caught. The var attribute specifies the name of the variable to\n" +" receive the data specified within the throw element. The typevar\n" +" attribute specifies the name of the variable to receive the type\n" +" of the exception.\n" +"\n" +"-->\n" +"<!ELEMENT catch (%task;)>\n" +"<!ATTLIST catch\n" +" exception CDATA #REQUIRED\n" +" var CDATA #IMPLIED\n" +" typevar CDATA #IMPLIED\n" +">\n"; public String getDTDInfo() { return fDTDInfo; } public String getDTDTaskName() { return "try"; } public STAXAction parseAction(STAX staxService, STAXJob job, org.w3c.dom.Node root) throws STAXException { STAXAction tryAction = null; List catchList = new ArrayList(); 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); if (thisChild.getNodeType() == Node.COMMENT_NODE) { /* Do nothing */ } else if (thisChild.getNodeType() == Node.ELEMENT_NODE) { if (thisChild.getNodeName().equals("catch")) { catchList.add(handleCatch(staxService, job, thisChild)); } else { if (tryAction != null) { throw new STAXInvalidXMLElementCountException( thisChild.getNodeName()); } STAXActionFactory factory = staxService.getActionFactory(thisChild.getNodeName()); if (factory == null) { throw new STAXInvalidXMLElementException( thisChild.getNodeName()); } tryAction = factory.parseAction(staxService, job, thisChild); } } else { throw new STAXInvalidXMLNodeTypeException( Integer.toString(thisChild.getNodeType())); } } return new STAXTryAction(tryAction, catchList); } private STAXCatchAction handleCatch(STAX staxService, STAXJob job, Node root) throws STAXException { String exceptionName = null; String varName = null; String typeVarName = null; STAXAction catchAction = 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("exception")) { exceptionName = STAXUtil.parseAndCompileForPython( thisAttr.getNodeValue(), errorInfo); } else if (thisAttr.getNodeName().equals("var")) { varName = thisAttr.getNodeValue(); } else if (thisAttr.getNodeName().equals("typevar")) { typeVarName = thisAttr.getNodeValue(); } 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 (catchAction != null) { throw new STAXInvalidXMLElementCountException( thisChild.getNodeName()); } STAXActionFactory factory = staxService.getActionFactory(thisChild.getNodeName()); if (factory == null) { throw new STAXInvalidXMLElementException( thisChild.getNodeName()); } catchAction = factory.parseAction(staxService, job, thisChild); } else { throw new STAXInvalidXMLNodeTypeException( Integer.toString(thisChild.getNodeType())); } } return new STAXCatchAction(exceptionName, varName, typeVarName, catchAction); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -