📄 staxfunctionactionfactory.java
字号:
String name = new String(); String defaultValue = new String(); NamedNodeMap attrs = thisChild.getAttributes(); for (int j = 0; j < attrs.getLength(); ++j) { Node thisAttr = attrs.item(j); if (thisAttr.getNodeName().equals("name")) { name = thisAttr.getNodeValue(); } else { throw new STAXInvalidXMLAttributeException( thisChild.getNodeName() + ": " + thisAttr.getNodeName()); } } if (name.equals("")) { throw new STAXInvalidFunctionArgumentException( "The name attribute for the <" + thisChild.getNodeName() + "> element cannot be " + "null.\n" + function.getXMLInfo()); } else if (!argNameSet.add(name)) { throw new STAXInvalidFunctionArgumentException( "The <" + thisChild.getNodeName() + " name=\"" + name + "\"> element's name is a duplicate. The " + "name for each argument defined for a function " + "must be unique.\n" + function.getXMLInfo()); } function.addArg(new STAXFunctionArgument(name, STAXFunctionAction.ARG_REQUIRED, handleChild(thisChild))); } else if (thisChild.getNodeName().equals( "function-optional-arg")) { String name = new String(); String defaultValue = new String(); 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 = thisAttr.getNodeValue(); } else if (thisAttr.getNodeName().equals("default")) { defaultValue = STAXUtil.parseAndCompileForPython( thisAttr.getNodeValue(), errorInfo); } else { throw new STAXInvalidXMLAttributeException( thisChild.getNodeName() + ": " + thisAttr.getNodeName()); } } if (name.equals("")) { throw new STAXInvalidFunctionArgumentException( "The name attribute for the <" + thisChild.getNodeName() + "> element cannot be " + "null.\n" + function.getXMLInfo()); } else if (!argNameSet.add(name)) { throw new STAXInvalidFunctionArgumentException( "The <" + thisChild.getNodeName() + " name=\"" + name + "\"> element's name is a duplicate. The " + "name for each argument defined for a function " + "must be unique.\n" + function.getXMLInfo()); } function.addArg(new STAXFunctionArgument(name, STAXFunctionAction.ARG_OPTIONAL, defaultValue, handleChild(thisChild))); } else if (thisChild.getNodeName().equals("function-other-args")) { String name = new String(); String defaultValue = new String(); NamedNodeMap attrs = thisChild.getAttributes(); for (int j = 0; j < attrs.getLength(); ++j) { Node thisAttr = attrs.item(j); if (thisAttr.getNodeName().equals("name")) { name = thisAttr.getNodeValue(); } else { throw new STAXInvalidXMLAttributeException( thisChild.getNodeName() + ": " + thisAttr.getNodeName()); } } if (name.equals("")) { throw new STAXInvalidFunctionArgumentException( "The name attribute for the <" + thisChild.getNodeName() + "> element cannot be " + "null.\n" + function.getXMLInfo()); } else if (!argNameSet.add(name)) { throw new STAXInvalidFunctionArgumentException( "The <" + thisChild.getNodeName() + " name=\"" + name + "\"> element's name is a duplicate. The " + "name for each argument defined for a function " + "must be unique.\n" + function.getXMLInfo()); } function.addArg(new STAXFunctionArgument(name, STAXFunctionAction.ARG_OTHER, defaultValue, handleChild(thisChild))); } else if (thisChild.getNodeName().equals("function-arg-def")) { String name = new String(); String type = new String(); String defaultValue = new String(); String description = new String(); int functionType = 0; NamedNodeMap attrs = thisChild.getAttributes(); for (int j = 0; j < attrs.getLength(); ++j) { Node thisAttr = attrs.item(j); if (thisAttr.getNodeName().equals("name")) { name = thisAttr.getNodeValue(); } else if (thisAttr.getNodeName().equals("type")) { type = thisAttr.getNodeValue(); if (type.equals("required")) functionType = STAXFunctionAction.ARG_REQUIRED; else if (type.equals("optional")) functionType = STAXFunctionAction.ARG_OPTIONAL; else if (type.equals("other")) functionType = STAXFunctionAction.ARG_OTHER; } else if (thisAttr.getNodeName().equals("default")) { defaultValue = thisAttr.getNodeValue(); } else { throw new STAXInvalidXMLAttributeException( thisChild.getNodeName() + ": " + thisAttr.getNodeName()); } } if (name.equals("")) { throw new STAXInvalidFunctionArgumentException( "The name attribute for the <" + thisChild.getNodeName() + "> element cannot be " + "null.\n" + function.getXMLInfo()); } else if (!argNameSet.add(name)) { throw new STAXInvalidFunctionArgumentException( "The <" + thisChild.getNodeName() + " name=\"" + name + "\"> element's name is a duplicate. The " + "name for each argument defined for a function " + "must be unique.\n" + function.getXMLInfo()); } // Iterate child elements to get the arg-def sub-elements STAXFunctionArgument arg = handleArgDef(thisChild, function, argNameSet); arg.setName(name); arg.setType(functionType); arg.setDefaultValue(defaultValue); function.addArg(arg); } else { throw new STAXInvalidXMLElementException( thisChild.getNodeName()); } } else { throw new STAXInvalidXMLNodeTypeException( Integer.toString(thisChild.getNodeType())); } } } STAXFunctionArgument handleArgDef(Node root, STAXFunctionAction function, HashSet argNameSet) throws STAXException { STAXFunctionArgument arg = new STAXFunctionArgument(); 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("function-arg-description")) { arg.setDescription(handleChild(thisChild)); } if (thisChild.getNodeName().equals("function-arg-private")) { arg.setPrivate(true); } if (thisChild.getNodeName().equals("function-arg-property")) { STAXFunctionArgumentProperty argProperty = new STAXFunctionArgumentProperty(); NamedNodeMap attrs = thisChild.getAttributes(); for (int j = 0; j < attrs.getLength(); ++j) { Node thisAttr = attrs.item(j); if (thisAttr.getNodeName().equals("name")) { argProperty.setName(thisAttr.getNodeValue()); } else if (thisAttr.getNodeName().equals("value")) { argProperty.setValue(thisAttr.getNodeValue()); } else { throw new STAXInvalidXMLAttributeException( thisChild.getNodeName() + ": " + thisAttr.getNodeName()); } } NodeList propertyChildren = thisChild.getChildNodes(); for (int k = 0; k < propertyChildren.getLength(); ++k) { Node thisPropertyChild = propertyChildren.item(k); if (thisPropertyChild.getNodeType() == Node.COMMENT_NODE) { /* Do nothing */ } else if (thisPropertyChild.getNodeType() == Node.ELEMENT_NODE) { if (thisPropertyChild.getNodeName().equals( "function-arg-property-description")) { argProperty.setDescription( handleChild(thisPropertyChild)); } else if (thisPropertyChild.getNodeName().equals( "function-arg-property-data")) { STAXFunctionArgumentPropertyData argPropData = handleArgPropertyData(thisPropertyChild); argProperty.addData(argPropData); } } } arg.addProperty(argProperty); } } } return arg; } STAXFunctionArgumentPropertyData handleArgPropertyData(Node root) throws STAXException { STAXFunctionArgumentPropertyData propData = new STAXFunctionArgumentPropertyData(); NamedNodeMap attrs = root.getAttributes(); for (int j = 0; j < attrs.getLength(); ++j) { Node thisAttr = attrs.item(j); if (thisAttr.getNodeName().equals("type")) { propData.setType(thisAttr.getNodeValue()); } else if (thisAttr.getNodeName().equals("value")) { propData.setValue(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 (thisChild.getNodeName().equals( "function-arg-property-data")) { propData.addData(handleArgPropertyData(thisChild)); } } } return propData; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -