comparison WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/ParserForWADL/src/lsdis/WADLParserDriver.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 import java.net.MalformedURLException;
3 import java.net.URL;
4
5 import lsdis.*;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10
11 /*
12 * generate url's and param names
13 */
14
15 public class WADLParserDriver {
16
17
18 // private List<List<String>> paramNames = new ArrayList<List<String>>();
19 private List<Method> definedMethods = new ArrayList<Method>();
20
21 private int count = 0;
22 private List<Method> crossReferencedMethods = new ArrayList<Method>();
23 private List<String> crossReferencedMethodURLS = new ArrayList<String>();
24
25 private List<Method> completeMethodList = new ArrayList<Method>();
26 private List<String> url = new ArrayList<String>();
27
28
29 public List<Method> getCompleteMethodList() {
30 return completeMethodList;
31 }
32
33 public List<String> getUrl() {
34 return url;
35 }
36
37
38
39 public static void main(String[] args) throws Exception {
40
41 WADLParserDriver mpw = new WADLParserDriver();
42 //mpw.parse(new URL("http://cs.uga.edu/~ganjoo/galaxy/DDBJNCBIGenomeAnnotationGetGeneList.wadl"));
43 mpw.parse(new URL("http://eupathdb.org/webservices/GeneQuestions/GenesByMolecularWeight.wadl"));
44 mpw.displayInfo();
45
46 }
47
48 public void parse(URL fileURL) throws Exception {
49 int i=0;
50
51
52
53 //URL fileURL = new URL("http://www.eupathdb.org/webservices/GeneQuestions/GenesByMolecularWeight.wadl");
54
55 WADLParser wadlP = new WADLParser(fileURL);
56
57 Application app= new Application();
58 app=wadlP.getApplicationOfWADL();
59
60 String temp = "";
61 String tempHref="";
62
63 for(Resources resources : app.getResources()){
64 temp = resources.getBase().toString();
65 //traverseSubResources(temp, resources);
66 System.out.println(temp);
67 for(Resource resource : resources.getResources()){
68
69 temp = temp + resource.getPath();
70 traverseResource(temp, resource);
71 //traverseSubResources(temp, resource);
72 System.out.println("resource path"+resource.getPath());
73 if(resource.getParams()!=null && resource.getParams().size()!=0){
74 for(Param param: resource.getParams()){
75 System.out.println("params "+ param);
76 }
77 }
78
79
80 }
81
82 }
83
84 traverseCrossReferencedMethods();
85 displayInfo();
86
87 }//end main
88
89
90 public void traverseSubResources(String passedString,Resource resource){
91
92
93
94
95 for(Resource subResource : resource.getResources()){
96
97 String temp = passedString;
98
99 if(temp.charAt(temp.length()-1) != '/')
100 temp += "/";
101 temp += subResource.getPath();
102
103 // if(subResource.getParams()!=null && subResource.getParams().size()!=0){
104 // for(Param param: subResource.getParams()){
105 // if(param.getStyle().equalsIgnoreCase("template")){
106 // System.out.println("params "+ param.getName());
107 // temp=temp+"/{"+param.getName()+"}";
108 // }
109 // }
110 // }
111
112 //start
113
114
115 for(Method method : subResource.getMethods()){
116 if(method.getId() != null){
117 url.add(count, temp);
118 definedMethods.add(method);
119
120 completeMethodList.add(count,method);
121
122 count++;
123 }
124 else if(method.getHref()!=null){ //will work only for intra-document cross-reference currently
125
126 crossReferencedMethods.add(method);
127 crossReferencedMethodURLS.add(temp);
128
129 }
130 else{
131
132 System.out.println("ERROR : Method " + method.getName() + " does not have an id or a href !!" );
133 }
134 }
135
136
137 traverseSubResources(temp, subResource);
138
139 }//end for
140
141 }//end method
142
143 public void traverseResource(String passedString,Resource resource){
144
145
146
147 String temp = passedString ;
148
149 //start
150
151
152 for(Method method : resource.getMethods()){
153 if(method.getId() != null){
154 url.add(count, temp);
155 definedMethods.add(method);
156
157 completeMethodList.add(count,method);
158
159 count++;
160 }
161 else if(method.getHref()!=null){ //will work only for intra-document cross-reference currently
162
163 crossReferencedMethods.add(method);
164 crossReferencedMethodURLS.add(temp);
165
166 }
167 else{
168
169 System.out.println("ERROR : Method " + method.getName() + " does not have an id or a href !!" );
170 }
171 }
172
173
174 traverseSubResources(temp, resource);
175
176 }//end method
177
178 public void traverseCrossReferencedMethods(){
179 int i =0;
180 String tempHref = "";
181
182 for(Method method : crossReferencedMethods){
183
184 url.add(count, crossReferencedMethodURLS.get(i));
185
186
187
188 tempHref = method.getHref().toString();
189 if(tempHref.startsWith("#")){
190 tempHref = tempHref.substring(1);
191 }
192
193 for(Method m : definedMethods){
194 if(m.getId().equals(tempHref)){
195
196 Method tempMethod = new Method(m.getDocs(),m.getRequest(),m.getResponse(),m.getId(),m.getName(),method.getHref());
197 completeMethodList.add(count,tempMethod);
198
199 break;
200
201 }
202
203 }
204
205 count++;
206 i++;
207 }
208
209
210
211 }//end of method
212
213 // public void displayInfo(){
214 // if(url.size()!=paramNames.size()){
215 // System.out.println("Debug the code !!!! :( ");
216 // System.exit(0);
217 // }
218 // for(int i=0;i<url.size();i++){
219 // System.out.println(url.get(i));
220 //
221 // for(String p : paramNames.get(i)){
222 // System.out.print(p + ", ");
223 // }
224 //
225 // System.out.println();
226 // System.out.println();
227 // }
228 //
229 // }
230
231 public void displayInfo(){
232
233 if(url.size()!=completeMethodList.size()){
234 System.out.println("Debug the code !!!! :( ");
235 System.exit(0);
236 }
237 for(int i=0;i<url.size();i++){
238 System.out.println(url.get(i));
239
240 for(Method m : completeMethodList){
241 System.out.println(m.getName());
242 for(Param param : m.getRequest().getParams()){
243 System.out.println("\t"+param.getName());
244 System.out.println("\t"+param.isRequired());
245 for(Doc doc : param.getDocs()){
246 if(doc.getTitle().equalsIgnoreCase("prompt")){
247 System.out.println("Prompt: " + doc.getInnerText());
248 }
249
250 }
251 List<Option> ops = param.getOptions();
252
253 // if(ops.size()==0){
254 // System.out.println("No options available");
255 // }
256 // else{
257 // System.out.println("\t options:");
258 //
259 // for(Option option:param.getOptions()){
260 // System.out.println("\t "+option.getName());
261 // }
262 // }
263 }
264 }
265
266 System.out.println();
267 System.out.println();
268 }
269 }
270 }
271
272
273
274