comparison WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/lib/SAWADLParser/src/edu/uga/cs/lsdis/meteors/wadls/SAWADLParserDriver.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 edu.uga.cs.lsdis.meteors.wadls;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5 import java.util.ArrayList;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9 import java.util.Vector;
10
11 import javax.wadls.Application;
12 import javax.wadls.Method;
13 import javax.wadls.Param;
14 import javax.wadls.Request;
15 import javax.wadls.Resource;
16 import javax.wadls.WADLSException;
17 import javax.wadls.factory.WADLFactory;
18 import javax.wadls.xml.WADLReader;
19 import javax.xml.namespace.QName;
20
21
22 public class SAWADLParserDriver {
23
24
25 private List<Method> completeMethodList = new ArrayList<Method>();
26 private List<String> url = new ArrayList<String>();
27 private List<String> paramList = new ArrayList<String>();
28 private List<String> paramTypeList = new ArrayList<String>();
29 private List<String> paramModelRef = new ArrayList<String>();
30 private Application application;
31
32
33 public List<Method> getCompleteMethodList() {
34 return completeMethodList;
35 }
36
37 public List<String> getUrl() {
38 return url;
39 }
40
41 public List<String> getParamList() {
42 return paramList;
43 }
44 public List<String> getParamTypeList() {
45 return paramTypeList;
46 }
47
48
49
50
51 public static void main(String[] args) throws Exception {
52
53 //WADLParserDriver mpw = new WADLParserDriver();
54 //mpw.parse(new URL(args[0]));
55 SAWADLParserDriver spd = new SAWADLParserDriver();
56 //String fileURL = "/home/ganjoo/parser/SAWADLParser/Files/sample.wadl";
57 String fileURL = "/home/ganjoo/parser/SAWADLParser/euPathWADL/GenesByTextSearch.sawadl";
58 //String fileURL = "http://cs.uga.edu/~ganjoo/galaxy/GenesByTextSearch.sawadl";
59 spd.parse(fileURL);
60 }
61
62 public void parse(String fileURL) throws Exception {
63 int i=0;
64 Map resources = new HashMap();
65 List methods = new Vector();
66 List<ParamImpl> paramList = new Vector();
67
68 //URL fileURL = new URL("http://www.eupathdb.org/webservices/GeneQuestions/GenesByMolecularWeight.wadl");
69 WADLReader wadlReader;
70 try {
71 wadlReader = WADLFactory.newInstance().newWADLReader();
72 wadlReader.setFeature(Constants.FEATURE_PARSE_SAWADL,true);
73 //wadlReader.setExtensionRegistry(new PopulatedExtensionRegistry());
74 Application app = wadlReader.readWADL(fileURL);
75 this.application = app;
76
77
78 String temp = "";
79 String tempHref="";
80 int count =0;
81 Map<QName, Resource> resourceMap = app.getResources();
82 for(Map.Entry entry : resourceMap.entrySet() ){
83 count++;
84 Resource resource = (Resource) entry.getValue();
85 // System.out.println("Resource " + count + "is " + resource.getQName().getNamespaceURI());
86
87 methods = resource.getMethods();
88
89 for(int j =0;j<methods.size();j++){
90
91 Method method = (Method) methods.get(j);
92 completeMethodList.add(method);
93 url.add(app.getResourcesPath()+resource.getQName().getLocalPart());
94
95 System.out.println("-------------------------------\n");
96 System.out.println("Resources path : " + app.getResourcesPath());
97 System.out.println("Method name is : " + method.getName());
98 System.out.println("Qname uri : " + resource.getQName().getNamespaceURI());
99 System.out.println("Qname local part : " + resource.getQName().getLocalPart());
100 System.out.println("Qname prefix : " + resource.getQName().getPrefix());
101 System.out.println("\n-------------------------------\n");
102
103 Request request = method.getRequest();
104 paramList = request.getParamList();
105
106 // Map namespaces = new HashMap();
107 // namespaces = app.getNamespaces();
108 // System.out.println( namespaces.get("euPathOntology"));
109
110 for(Param param : paramList){
111 System.out.println("Parameter : ");
112 System.out.println("\t name: "+ param.getName());
113 System.out.println("\t type: "+param.getType());
114 System.out.println("\t ontology reference: "+ param.getModelreference());
115 System.out.println("\t required: " + param.getRequired());
116 System.out.println("\t option size: "+param.getOptionvalue().size());
117
118
119 }
120
121
122 }
123
124
125
126 }
127
128
129
130
131
132
133
134 } catch (WADLSException e) {
135 // TODO Auto-generated catch block
136 e.printStackTrace();
137
138 }
139 }
140
141 public String getCompleteModelReference(Param param){
142 String prefix = null;
143 String namespace = null;
144 if(param.getModelreference() != null){
145 prefix = param.getModelreference().split("#")[0];
146 namespace = application.getNamespace(prefix);
147 }
148
149 return namespace+"#"+param.getModelreference().split("#")[1];
150 }
151
152
153 }