1 22 package org.objectweb.petals.util; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import javax.xml.namespace.QName ; 28 29 import org.w3c.dom.Document ; 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.NodeList ; 32 33 38 public final class WSDLUtil { 39 40 public static List <QName > getInterfacesForService(Document document, 41 QName serviceName) { 42 List <QName > interfaces = new ArrayList <QName >(); 43 44 String targetNameSpace = document.getDocumentElement().getAttribute( 46 "targetNamespace"); 47 48 if (targetNameSpace != null 49 && serviceName.getNamespaceURI().equals(targetNameSpace)) { 50 51 Element rootElement = document.getDocumentElement(); 52 String prefix = ""; 53 String rootName = rootElement.getNodeName(); 54 if (rootName.indexOf(":") > -1) { 55 prefix = rootName.substring(0, rootName.indexOf(":")) + ":"; 56 } 57 58 List <String > bindingNames = new ArrayList <String >(); 59 NodeList services = rootElement.getElementsByTagName(prefix 61 + "service"); 62 for (int i = 0; i < services.getLength(); i++) { 63 Element service = (Element ) services.item(i); 64 if (service.getAttribute("name").equals( 65 serviceName.getLocalPart())) { 66 NodeList ports = service.getElementsByTagName(prefix 67 + "port"); 68 for (int j = 0; j < ports.getLength(); j++) { 69 Element port = (Element ) ports.item(j); 70 String name = port.getAttribute("binding"); 71 if (name.indexOf(":") > -1) { 72 name = name.substring(name.indexOf(":") + 1); 73 } 74 bindingNames.add(name); 75 } 76 } 77 } 78 79 List <String > portNames = new ArrayList <String >(); 80 NodeList bindings = rootElement.getElementsByTagName(prefix 82 + "binding"); 83 for (int i = 0; i < bindings.getLength(); i++) { 84 Element binding = (Element ) bindings.item(i); 85 String name = binding.getAttribute("name"); 86 if (bindingNames.contains(name)) { 87 String type = binding.getAttribute("type"); 88 if (type.indexOf(":") > -1) { 89 type = type.substring(type.indexOf(":") + 1); 90 } 91 portNames.add(type); 92 } 93 } 94 95 NodeList portTypes = rootElement.getElementsByTagName(prefix 97 + "portType"); 98 for (int i = 0; i < portTypes.getLength(); i++) { 99 Element portType = (Element ) portTypes.item(i); 100 String name = portType.getAttribute("name"); 101 if (portNames.contains(name)) { 102 interfaces.add(new QName (targetNameSpace, name)); 103 } 104 } 105 } 106 107 return interfaces; 108 } 109 110 } 111 | Popular Tags |