KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > util > WSDLUtil


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: WSDLUtil.java 14:50:31 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.util;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.xml.namespace.QName JavaDoc;
28
29 import org.w3c.dom.Document JavaDoc;
30 import org.w3c.dom.Element JavaDoc;
31 import org.w3c.dom.NodeList JavaDoc;
32
33 /**
34  * This is used to extract the interfaces name of a WSDL file
35  *
36  * @author ddesjardins - eBMWebsourcing
37  */

38 public final class WSDLUtil {
39
40     public static List JavaDoc<QName JavaDoc> getInterfacesForService(Document JavaDoc document,
41         QName JavaDoc serviceName) {
42         List JavaDoc<QName JavaDoc> interfaces = new ArrayList JavaDoc<QName JavaDoc>();
43
44         // Retreive the namespace
45
String JavaDoc targetNameSpace = document.getDocumentElement().getAttribute(
46             "targetNamespace");
47
48         if (targetNameSpace != null
49             && serviceName.getNamespaceURI().equals(targetNameSpace)) {
50
51             Element JavaDoc rootElement = document.getDocumentElement();
52             String JavaDoc prefix = "";
53             String JavaDoc rootName = rootElement.getNodeName();
54             if (rootName.indexOf(":") > -1) {
55                 prefix = rootName.substring(0, rootName.indexOf(":")) + ":";
56             }
57
58             List JavaDoc<String JavaDoc> bindingNames = new ArrayList JavaDoc<String JavaDoc>();
59             // Retreive the services
60
NodeList JavaDoc services = rootElement.getElementsByTagName(prefix
61                 + "service");
62             for (int i = 0; i < services.getLength(); i++) {
63                 Element JavaDoc service = (Element JavaDoc) services.item(i);
64                 if (service.getAttribute("name").equals(
65                     serviceName.getLocalPart())) {
66                     NodeList JavaDoc ports = service.getElementsByTagName(prefix
67                         + "port");
68                     for (int j = 0; j < ports.getLength(); j++) {
69                         Element JavaDoc port = (Element JavaDoc) ports.item(j);
70                         String JavaDoc 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 JavaDoc<String JavaDoc> portNames = new ArrayList JavaDoc<String JavaDoc>();
80             // Retreive the bindings
81
NodeList JavaDoc bindings = rootElement.getElementsByTagName(prefix
82                 + "binding");
83             for (int i = 0; i < bindings.getLength(); i++) {
84                 Element JavaDoc binding = (Element JavaDoc) bindings.item(i);
85                 String JavaDoc name = binding.getAttribute("name");
86                 if (bindingNames.contains(name)) {
87                     String JavaDoc 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             // Retreive the port types
96
NodeList JavaDoc portTypes = rootElement.getElementsByTagName(prefix
97                 + "portType");
98             for (int i = 0; i < portTypes.getLength(); i++) {
99                 Element JavaDoc portType = (Element JavaDoc) portTypes.item(i);
100                 String JavaDoc name = portType.getAttribute("name");
101                 if (portNames.contains(name)) {
102                     interfaces.add(new QName JavaDoc(targetNameSpace, name));
103                 }
104             }
105         }
106
107         return interfaces;
108     }
109
110 }
111
Popular Tags