private void handleWhenOtherwiseNodes( XNode chooseSqlNode, List<SqlNode> ifSqlNodes, List<SqlNode> defaultSqlNodes) { List<XNode> children = chooseSqlNode.getChildren(); for (XNode child : children) { String nodeName = child.getNode().getNodeName(); NodeHandler handler = nodeHandlers.get(nodeName); if (handler instanceof IfHandler) { handler.handleNode(child, ifSqlNodes); } else if (handler instanceof OtherwiseHandler) { handler.handleNode(child, defaultSqlNodes); } } }
private List<SqlNode> parseDynamicTags(XNode node) { List<SqlNode> contents = new ArrayList<SqlNode>(); NodeList children = node.getNode().getChildNodes(); // 直接通过w3c包获取NodeList int childrenLength = children.getLength(); for (int i = 0; i < childrenLength; i++) { XNode child = node.newXNode(children.item(i)); Node childNode = child.getNode(); short nodeType = childNode.getNodeType(); // <![CDATA[]]>中括着的纯文本,它没有子节点 if (nodeType == Node.CDATA_SECTION_NODE || nodeType == Node.TEXT_NODE) { String data = child.getStringBody(""); contents.add(new TextSqlNode(data)); } else if (nodeType == Node.ELEMENT_NODE) { String nodeName = childNode.getNodeName(); NodeHandler handler = nodeHandlers.get(nodeName); if (handler == null) { throw new BuilderException("Unknown element <" + nodeName + "> in SQL statement."); } handler.handleNode(child, contents); } } return contents; }