1 package org.objectweb.celtix.tools.utils; 2 3 import javax.xml.namespace.QName ; 4 5 import org.w3c.dom.Document ; 6 import org.w3c.dom.NamedNodeMap ; 7 import org.w3c.dom.Node ; 8 import org.w3c.dom.NodeList ; 9 10 import org.objectweb.celtix.tools.common.WSDLConstants; 11 12 public final class ErrNodeLocator { 13 private ErrNodeLocator() { 14 15 } 16 17 public static Node getNode(Document doc, QName wsdlParentNode, String parentNameValue, 18 19 String childNameValue) { 20 NodeList parentNodeList = doc.getElementsByTagNameNS(wsdlParentNode.getNamespaceURI(), wsdlParentNode 21 .getLocalPart()); 22 23 for (int i = 0; i < parentNodeList.getLength(); i++) { 24 Node parentNode = parentNodeList.item(i); 25 NamedNodeMap parentNodeMap = parentNode.getAttributes(); 26 Node parentAttrNode = parentNodeMap.getNamedItem(WSDLConstants.ATTR_NAME); 27 if (parentAttrNode != null && parentNameValue != null 28 && parentAttrNode.getNodeValue().equals(parentNameValue) || parentAttrNode == null 29 || parentNameValue == null) { 30 31 for (Node n = parentNode.getFirstChild(); n != null; n = n.getNextSibling()) { 32 if (n.getNodeType() == Node.ELEMENT_NODE) { 33 NamedNodeMap map = n.getAttributes(); 34 Node attrChildNode = map.getNamedItem(WSDLConstants.ATTR_NAME); 35 if (attrChildNode != null && attrChildNode.getNodeValue().equals(childNameValue)) { 36 return n; 37 } 38 } 39 } 40 41 } 42 } 43 return null; 44 } 45 } 46 | Popular Tags |