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