private FieldConfig parseFieldConfig(Node fieldNode) throws ConfigException { NamedNodeMap attr = fieldNode.getAttributes(); Node nameNode = attr.getNamedItem(XMLConfigConstant.NAME); if (nameNode == null) { throw new ConfigException(ErrorMsg.NO_NAME_PROPERTY_FOR_FIELD); } FieldConfig fieldConfig = new FieldConfig(nameNode.getNodeValue()); NodeList validateRule = fieldNode.getChildNodes(); if (validateRule == null || validateRule.getLength() == 0) { return null; } for (int i = 0; i < validateRule.getLength(); i++) { Node node = validateRule.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } AbstractValidator validator = ValidatorRegistry.getInstance().getValidator(node.getNodeName()); if (validator == null) { throw new ConfigException(ErrorMsg.NO_SUCH_VALIDATOR_ERROR + node.getNodeName()); } else { fieldConfig.addRule(validator.parseRuleConfig(node)); } } return fieldConfig; }
// Parse the group config. private List<GroupConfig> parseGroupConfig(Element rootEle, List<FieldConfig> fieldConfigs) throws ConfigException { Map<String, FieldConfig> configMap = new HashMap<String, FieldConfig>(); for (FieldConfig config : fieldConfigs) { configMap.put(config.getFieldName(), config); } List<GroupConfig> groupConfigs = new ArrayList<GroupConfig>(); NodeList groupsNode = rootEle.getElementsByTagName(XMLConfigConstant.ACTIONS); if (groupsNode == null || groupsNode.getLength() == 0) { return null; } NodeList groupList = groupsNode.item(0).getChildNodes(); for (int i = 0; i < groupList.getLength(); i++) { Node groupNode = groupList.item(i); if (XMLConfigConstant.XCASE.equals(groupNode.getNodeName())) { GroupConfig groupConfig = parseGroup(configMap, groupNode); if (groupConfig != null) { groupConfigs.add(groupConfig); } } } return groupConfigs; }