Adding registry web service and changes to WStester and JWS2Client code. Bugs in...
[jabaws.git] / webservices / compbio / ws / client / Services.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.ws.client;\r
20 \r
21 import java.io.File;\r
22 import java.net.URL;\r
23 \r
24 import javax.xml.namespace.QName;\r
25 import javax.xml.ws.Service;\r
26 \r
27 import compbio.data.msa.JABAService;\r
28 import compbio.data.msa.MsaWS;\r
29 import compbio.data.msa.SequenceAnnotation;\r
30 import compbio.engine.client.ConfExecutable;\r
31 import compbio.engine.client.Executable;\r
32 import compbio.runner.conservation.AACon;\r
33 import compbio.runner.disorder.Disembl;\r
34 import compbio.runner.disorder.GlobPlot;\r
35 import compbio.runner.disorder.Jronn;\r
36 import compbio.runner.msa.ClustalW;\r
37 import compbio.runner.msa.Mafft;\r
38 import compbio.runner.msa.Muscle;\r
39 import compbio.runner.msa.Probcons;\r
40 import compbio.runner.msa.Tcoffee;\r
41 \r
42 /**\r
43  * List of web services currently supported by JABAWS version 2\r
44  * \r
45  */\r
46 public enum Services {\r
47         MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS;\r
48 \r
49         public static Services getService(String servName) {\r
50                 servName = servName.trim().toLowerCase();\r
51                 for (Services service : Services.values()) {\r
52                         if (service.toString().equalsIgnoreCase(servName)) {\r
53                                 return service;\r
54                         }\r
55                 }\r
56                 return null;\r
57         }\r
58 \r
59         public static Services getServiceByRunner(\r
60                         Class<Executable<?>> runnerClassName) {\r
61                 assert runnerClassName != null;\r
62                 String sname = runnerClassName.getSimpleName().toLowerCase();\r
63                 for (Services service : Services.values()) {\r
64                         if (service.toString().toLowerCase().contains(sname)) {\r
65                                 return service;\r
66                         }\r
67                 }\r
68                 return null;\r
69         }\r
70 \r
71         public Class<? extends Executable<?>> getServiceImpl() {\r
72                 switch (this) {\r
73                         case AAConWS :\r
74                                 return AACon.class;\r
75                         case ClustalWS :\r
76                                 return ClustalW.class;\r
77                         case MafftWS :\r
78                                 return Mafft.class;\r
79                         case MuscleWS :\r
80                                 return Muscle.class;\r
81                         case TcoffeeWS :\r
82                                 return Tcoffee.class;\r
83                         case ProbconsWS :\r
84                                 return Probcons.class;\r
85                         case DisemblWS :\r
86                                 return Disembl.class;\r
87                         case GlobPlotWS :\r
88                                 return GlobPlot.class;\r
89                         case JronnWS :\r
90                                 return Jronn.class;\r
91                         default :\r
92                                 throw new RuntimeException(\r
93                                                 "Unknown web service implementation class for service: "\r
94                                                                 + this);\r
95                 }\r
96         }\r
97 \r
98         public static Class<? extends Executable<?>> getRunnerByJobDirectory(\r
99                         File jobdir) {\r
100                 Services service = getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir));\r
101                 return service.getServiceImpl();\r
102         }\r
103 \r
104         private static String getRunnerNameByJobDirectory(File jobdir) {\r
105                 String name = jobdir.getName().split("#")[0];\r
106 \r
107                 if (name.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX)) {\r
108                         assert ConfExecutable.CLUSTER_TASK_ID_PREFIX.length() == 1;\r
109                         name = name.substring(1);\r
110                 }\r
111                 return name;\r
112         }\r
113 \r
114         public static Services getServiceByJobDirectory(File jobdir) {\r
115                 return getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir));\r
116         }\r
117 \r
118         private static Services getServiceByRunnerName(String name) {\r
119                 for (Services service : Services.values()) {\r
120                         String runnerName = service.getServiceImpl().getSimpleName()\r
121                                         .toLowerCase();\r
122                         name = name.trim().toLowerCase();\r
123                         if (name.startsWith(runnerName)) {\r
124                                 return service;\r
125                         }\r
126                 }\r
127                 return null;\r
128         }\r
129 \r
130         Service getService(URL url, String sqname) {\r
131                 QName qname = new QName(sqname, this.toString());\r
132                 return Service.create(url, qname);\r
133         }\r
134 \r
135         Class<? extends JABAService> getServiceType() {\r
136                 switch (this) {\r
137                         // deliberate leaking\r
138                         case AAConWS :\r
139                         case JronnWS :\r
140                         case DisemblWS :\r
141                         case GlobPlotWS :\r
142 \r
143                                 return SequenceAnnotation.class;\r
144 \r
145                                 // deliberate leaking\r
146                         case ClustalWS :\r
147                         case MafftWS :\r
148                         case MuscleWS :\r
149                         case ProbconsWS :\r
150                         case TcoffeeWS :\r
151 \r
152                                 return MsaWS.class;\r
153                         default :\r
154                                 throw new RuntimeException("Unrecognised Web Service Type "\r
155                                                 + this + " - Should never happened!");\r
156                 }\r
157         }\r
158 \r
159         JABAService getInterface(Service service) {\r
160                 assert service != null;\r
161 \r
162                 QName portName = new QName(service.getServiceName().getNamespaceURI(),\r
163                                 this.toString() + "Port");\r
164                 return service.getPort(portName, this.getServiceType());\r
165         }\r
166 }