01: package org.objectweb.celtix.tools.utils;
02:
03: import javax.xml.namespace.QName;
04:
05: import org.w3c.dom.Document;
06: import org.w3c.dom.NamedNodeMap;
07: import org.w3c.dom.Node;
08: import org.w3c.dom.NodeList;
09:
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,
18: String parentNameValue,
19:
20: String childNameValue) {
21: NodeList parentNodeList = doc.getElementsByTagNameNS(
22: wsdlParentNode.getNamespaceURI(), wsdlParentNode
23: .getLocalPart());
24:
25: for (int i = 0; i < parentNodeList.getLength(); i++) {
26: Node parentNode = parentNodeList.item(i);
27: NamedNodeMap parentNodeMap = parentNode.getAttributes();
28: Node parentAttrNode = parentNodeMap
29: .getNamedItem(WSDLConstants.ATTR_NAME);
30: if (parentAttrNode != null
31: && parentNameValue != null
32: && parentAttrNode.getNodeValue().equals(
33: parentNameValue) || parentAttrNode == null
34: || parentNameValue == null) {
35:
36: for (Node n = parentNode.getFirstChild(); n != null; n = n
37: .getNextSibling()) {
38: if (n.getNodeType() == Node.ELEMENT_NODE) {
39: NamedNodeMap map = n.getAttributes();
40: Node attrChildNode = map
41: .getNamedItem(WSDLConstants.ATTR_NAME);
42: if (attrChildNode != null
43: && attrChildNode.getNodeValue().equals(
44: childNameValue)) {
45: return n;
46: }
47: }
48: }
49:
50: }
51: }
52: return null;
53: }
54: }
|