KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > dev > wizard > WsdlServiceHandler


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.dev.wizard;
21
22 import java.io.IOException JavaDoc;
23 import javax.xml.parsers.ParserConfigurationException JavaDoc;
24 import javax.xml.parsers.SAXParser JavaDoc;
25 import javax.xml.parsers.SAXParserFactory JavaDoc;
26 import org.xml.sax.SAXException JavaDoc;
27 import org.xml.sax.helpers.DefaultHandler JavaDoc;
28
29 /** ConteHandler that gives information of the first service and port
30  *
31  * @author mkuchtiak
32  */

33 public class WsdlServiceHandler extends DefaultHandler JavaDoc{
34     
35     public static final String JavaDoc WSDL_SOAP_URI = "http://schemas.xmlsoap.org/wsdl/"; //NOI18N
36

37     private boolean insideService;
38     private String JavaDoc serviceName, portName;
39     
40     public static WsdlServiceHandler parse(String JavaDoc wsdlUrl) throws ParserConfigurationException JavaDoc, SAXException JavaDoc, IOException JavaDoc {
41         WsdlServiceHandler handler = new WsdlServiceHandler();
42         SAXParserFactory JavaDoc factory = SAXParserFactory.newInstance();
43         factory.setNamespaceAware(true);
44         SAXParser JavaDoc saxParser = factory.newSAXParser();
45         saxParser.parse(wsdlUrl, handler);
46         return handler;
47     }
48     
49     /** Creates a new instance of WsdlWrapperHandler */
50     private WsdlServiceHandler() {
51     }
52     
53     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qname, org.xml.sax.Attributes JavaDoc attributes) throws org.xml.sax.SAXException JavaDoc {
54         if (WSDL_SOAP_URI.equals(uri) && "service".equals(localName)) { // NOI18N
55
insideService=true;
56             if (serviceName==null) {
57                 serviceName = attributes.getValue("name");// NOI18N
58
}
59         } else if("port".equals(localName) && insideService) { // NOI18N
60
if (portName==null) {
61                 portName = attributes.getValue("name"); // NOI18N
62
}
63         }
64     }
65
66     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
67         if (WSDL_SOAP_URI.equals(uri) && "service".equals(localName)) {
68             insideService=false;
69         }
70     }
71     
72     public String JavaDoc getServiceName() {
73         return serviceName;
74     }
75     
76     public String JavaDoc getPortName() {
77         return portName;
78     }
79 }
80
Popular Tags