1 19 20 package org.netbeans.modules.websvc.dev.wizard; 21 22 import java.io.IOException ; 23 import javax.xml.parsers.ParserConfigurationException ; 24 import javax.xml.parsers.SAXParser ; 25 import javax.xml.parsers.SAXParserFactory ; 26 import org.xml.sax.SAXException ; 27 import org.xml.sax.helpers.DefaultHandler ; 28 29 33 public class WsdlServiceHandler extends DefaultHandler { 34 35 public static final String WSDL_SOAP_URI = "http://schemas.xmlsoap.org/wsdl/"; 37 private boolean insideService; 38 private String serviceName, portName; 39 40 public static WsdlServiceHandler parse(String wsdlUrl) throws ParserConfigurationException , SAXException , IOException { 41 WsdlServiceHandler handler = new WsdlServiceHandler(); 42 SAXParserFactory factory = SAXParserFactory.newInstance(); 43 factory.setNamespaceAware(true); 44 SAXParser saxParser = factory.newSAXParser(); 45 saxParser.parse(wsdlUrl, handler); 46 return handler; 47 } 48 49 50 private WsdlServiceHandler() { 51 } 52 53 public void startElement(String uri, String localName, String qname, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException { 54 if (WSDL_SOAP_URI.equals(uri) && "service".equals(localName)) { insideService=true; 56 if (serviceName==null) { 57 serviceName = attributes.getValue("name"); } 59 } else if("port".equals(localName) && insideService) { if (portName==null) { 61 portName = attributes.getValue("name"); } 63 } 64 } 65 66 public void endElement(String uri, String localName, String qName) throws SAXException { 67 if (WSDL_SOAP_URI.equals(uri) && "service".equals(localName)) { 68 insideService=false; 69 } 70 } 71 72 public String getServiceName() { 73 return serviceName; 74 } 75 76 public String getPortName() { 77 return portName; 78 } 79 } 80 | Popular Tags |