1 19 20 28 29 package org.netbeans.modules.xml.wsdl.model.visitor; 30 31 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 32 import org.w3c.dom.Document ; 33 import org.w3c.dom.Element ; 34 import org.w3c.dom.Node ; 35 36 40 public class FindWSDLComponent extends ChildVisitor { 41 42 43 public FindWSDLComponent() { 44 } 45 46 public static <T extends WSDLComponent> T findComponent(Class <T> type, WSDLComponent root, String xpath) { 47 WSDLComponent ret = new FindWSDLComponent().findComponent(root, xpath); 48 if (ret == null) { 49 return null; 50 } else { 51 return type.cast(ret); 52 } 53 } 54 55 public WSDLComponent findComponent(WSDLComponent root, Element xmlNode) { 56 assert xmlNode != null; 57 58 this.xmlNode = xmlNode; 59 result = null; 60 root.accept(this); 61 return result; 62 } 63 64 public WSDLComponent findComponent(WSDLComponent root, String xpath) { 65 Document doc = (Document ) root.getModel().getDocument(); 66 if (doc == null) { 67 return null; 68 } 69 70 Node result = root.getModel().getAccess().findNode(doc, xpath); 71 if (result instanceof Element ) { 72 return findComponent(root, (Element ) result); 73 } else { 74 return null; 75 } 76 } 77 78 protected void visitComponent(WSDLComponent component) { 79 if (result != null) return; 80 if (component.referencesSameNode(xmlNode)) { 81 result = component; 82 return; 83 } else { 84 super.visitComponent(component); 85 } 86 } 87 88 private WSDLComponent result; 89 private Element xmlNode; 90 } 91 | Popular Tags |