Mercurial > repos > ganjoo > webservice_toolsuite
comparison WebServiceToolWorkflow/WodenWSDLParser/src/lsdis/WSDLParserDriver.java @ 0:e7482c82796e default tip
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
author | ganjoo |
---|---|
date | Tue, 07 Jun 2011 17:34:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7482c82796e |
---|---|
1 package lsdis; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Iterator; | |
5 import java.util.List; | |
6 import java.util.Scanner; | |
7 | |
8 import org.apache.woden.WSDLException; | |
9 import org.apache.woden.WSDLFactory; | |
10 import org.apache.woden.WSDLReader; | |
11 import org.apache.woden.wsdl20.Description; | |
12 import org.apache.woden.wsdl20.ElementDeclaration; | |
13 import org.apache.woden.wsdl20.Endpoint; | |
14 import org.apache.woden.wsdl20.InterfaceMessageReference; | |
15 import org.apache.woden.wsdl20.InterfaceOperation; | |
16 import org.apache.woden.wsdl20.Service; | |
17 import org.apache.woden.wsdl20.Interface; | |
18 import org.apache.woden.wsdl20.extensions.rpc.Direction; | |
19 import org.apache.woden.wsdl20.xml.DescriptionElement; | |
20 import org.apache.ws.commons.schema.XmlSchemaAll; | |
21 import org.apache.ws.commons.schema.XmlSchemaComplexType; | |
22 import org.apache.ws.commons.schema.XmlSchemaElement; | |
23 import org.apache.ws.commons.schema.XmlSchemaGroupBase; | |
24 import org.apache.ws.commons.schema.XmlSchemaParticle; | |
25 import org.apache.ws.commons.schema.XmlSchemaSequence; | |
26 import org.apache.ws.commons.schema.XmlSchemaType; | |
27 import org.w3c.dom.NamedNodeMap; | |
28 | |
29 import java.net.URI; | |
30 | |
31 import javax.xml.namespace.QName; | |
32 | |
33 public class WSDLParserDriver { | |
34 | |
35 private List<InterfaceOperation> completeMethodList = new ArrayList<InterfaceOperation>(); | |
36 private List<String> url = new ArrayList<String>(); | |
37 private List<String> paramList = new ArrayList<String>(); | |
38 private List<String> paramTypeList = new ArrayList<String>(); | |
39 | |
40 | |
41 public List<InterfaceOperation> getCompleteMethodList() { | |
42 return completeMethodList; | |
43 } | |
44 | |
45 public List<String> getUrl() { | |
46 return url; | |
47 } | |
48 | |
49 public List<String> getParamList() { | |
50 return paramList; | |
51 } | |
52 public List<String> getParamTypeList() { | |
53 return paramTypeList; | |
54 } | |
55 | |
56 public static void main(String[] args) { | |
57 /*Scanner keyboard = new Scanner(System.in); | |
58 | |
59 System.out.println("Enter the wsdl url: "); | |
60 String wsdlurl = keyboard.next();*/ | |
61 WSDLParserDriver a = new WSDLParserDriver(); | |
62 a.parse("/home/ganjoo/parser/bookstore-sample/booklist.wsdl"); | |
63 for(InterfaceOperation oper:a.getCompleteMethodList()){ | |
64 a.getParameters(oper); | |
65 } | |
66 } | |
67 | |
68 public void parse(String wsdlurl){ | |
69 | |
70 try { | |
71 | |
72 WSDLFactory factory; | |
73 factory = WSDLFactory.newInstance(); | |
74 WSDLReader reader = factory.newWSDLReader(); | |
75 reader.setFeature(WSDLReader.FEATURE_VALIDATION, true); | |
76 Description desc = reader.readWSDL(wsdlurl); | |
77 Service[] services = desc.getServices(); | |
78 for(int i=0;i<services.length;i++){ | |
79 Endpoint[] endpoints = services[i].getEndpoints(); | |
80 boolean foundRestBinding = false; | |
81 int count=0; | |
82 while(count<endpoints.length){ | |
83 foundRestBinding = endpoints[count].getBinding().getType().equals(new URI("http://www.w3.org/ns/wsdl/http")); | |
84 count++; | |
85 | |
86 if(foundRestBinding){ | |
87 System.out.println("-----------------REST Web services--------------"); | |
88 URI address = endpoints[count-1].getAddress(); | |
89 String serviceName = services[i].getName().getLocalPart(); | |
90 System.out.println("Service Name : " + serviceName + "\t address : " + address); | |
91 Interface intrfce = services[i].getInterface(); | |
92 InterfaceOperation[] intrfceOpers = intrfce.getAllInterfaceOperations(); | |
93 for(int j=0;j<intrfceOpers.length;j++){ | |
94 InterfaceOperation oper = intrfceOpers[j]; | |
95 String operName = oper.getName().getLocalPart(); | |
96 System.out.println("\t operation name " + j + ": " + operName); | |
97 completeMethodList.add(oper); | |
98 url.add(address.toString()); | |
99 | |
100 | |
101 | |
102 } | |
103 } | |
104 } | |
105 } | |
106 | |
107 } catch (Exception e) { | |
108 // TODO Auto-generated catch block | |
109 e.printStackTrace(); | |
110 } | |
111 } | |
112 | |
113 public void getParameters(String operName){ | |
114 try{ | |
115 InterfaceOperation oper = null; | |
116 for(InterfaceOperation oper1 :getCompleteMethodList()){ | |
117 if(oper1.getName().getLocalPart().equals(operName)) | |
118 { | |
119 oper = oper1; | |
120 break; | |
121 } | |
122 | |
123 } | |
124 if(oper==null){ | |
125 System.out.println("Wrong method name passed in getParameters() method"); | |
126 System.exit(0); | |
127 } | |
128 | |
129 InterfaceMessageReference[] messageRefs = oper.getInterfaceMessageReferences(); | |
130 for(int k=0;k<messageRefs.length;k++){ | |
131 if(messageRefs[k].getDirection().toString().equals("in")){ | |
132 | |
133 ElementDeclaration ed = messageRefs[k].getElementDeclaration(); | |
134 String inputMessageName = ed.getName().getLocalPart(); | |
135 | |
136 if(ed.getContentModel().equalsIgnoreCase("org.w3c.dom")){ | |
137 org.w3c.dom.Element element = (org.w3c.dom.Element) ed.getContent(); | |
138 if(element.hasChildNodes()){ | |
139 System.out.println("Element has child nodes"); | |
140 org.w3c.dom.NodeList nl = element.getChildNodes(); | |
141 | |
142 } | |
143 if(element.hasAttributes()){ | |
144 System.out.println("Element has attributes"); | |
145 NamedNodeMap nodeMap = element.getAttributes(); | |
146 | |
147 } | |
148 } | |
149 else if(ed.getContentModel().equalsIgnoreCase("org.apache.ws.commons.schema")){ | |
150 org.apache.ws.commons.schema.XmlSchemaElement element = (org.apache.ws.commons.schema.XmlSchemaElement ) ed.getContent(); | |
151 System.out.println("element: " + element); | |
152 if(element != null){ | |
153 String targetNamespace = element.getQName().getNamespaceURI(); | |
154 QName bodyFirstChildQName; | |
155 if (targetNamespace != null && !"".equals(targetNamespace)) { | |
156 bodyFirstChildQName = new QName(targetNamespace, element.getName()); | |
157 } else { | |
158 bodyFirstChildQName = new QName(element.getName()); | |
159 } | |
160 if(oper.getStyle()[0].equals(new URI("http://www.w3.org/ns/wsdl/style/iri"))){ | |
161 XmlSchemaType schemaType = element.getSchemaType(); | |
162 if (schemaType instanceof XmlSchemaComplexType) { | |
163 XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType); | |
164 XmlSchemaParticle particle = complexType.getParticle(); | |
165 if (particle instanceof XmlSchemaSequence || particle instanceof XmlSchemaAll) { | |
166 XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) particle; | |
167 Iterator iterator = xmlSchemaGroupBase.getItems().getIterator(); | |
168 while (iterator.hasNext()) { | |
169 XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next(); | |
170 QName qName = innerElement.getQName(); | |
171 if (qName ==null && innerElement.getSchemaTypeName().equals(org.apache.ws.commons.schema.constants.Constants.XSD_ANYTYPE)) { | |
172 System.out.println("create soap message without schema and break"); | |
173 break; | |
174 } | |
175 long minOccurs = innerElement.getMinOccurs(); | |
176 boolean nillable = innerElement.isNillable(); | |
177 | |
178 String name = | |
179 qName != null ? qName.getLocalPart() : innerElement.getName(); | |
180 System.out.println("Name of parameter is :" + name); | |
181 paramList.add(name); | |
182 System.out.println("Type of Parameter is :"+innerElement.getSchemaTypeName().getLocalPart()+"\n"); | |
183 paramTypeList.add(innerElement.getSchemaTypeName().getLocalPart()); | |
184 } | |
185 | |
186 | |
187 } | |
188 | |
189 } | |
190 | |
191 } | |
192 | |
193 }else{ | |
194 System.out.println("element is null"); | |
195 } | |
196 | |
197 | |
198 } | |
199 } | |
200 } | |
201 } catch (Exception e) { | |
202 // TODO Auto-generated catch block | |
203 e.printStackTrace(); | |
204 } | |
205 } | |
206 | |
207 } |