Adding JABA web services usage statistics web application. Stat database is to follow
[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.net.URL;\r
22 \r
23 import javax.xml.namespace.QName;\r
24 import javax.xml.ws.Service;\r
25 \r
26 import compbio.data.msa.JABAService;\r
27 import compbio.data.msa.MsaWS;\r
28 import compbio.data.msa.SequenceAnnotation;\r
29 import compbio.engine.client.Executable;\r
30 \r
31 /**\r
32  * List of web services currently supported by JABAWS version 2\r
33  * \r
34  */\r
35 public enum Services {\r
36         MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS;\r
37 \r
38         public static Services getService(String servName) {\r
39                 servName = servName.trim().toLowerCase();\r
40                 for (Services service : Services.values()) {\r
41                         if (service.toString().equalsIgnoreCase(servName)) {\r
42                                 return service;\r
43                         }\r
44                 }\r
45                 return null;\r
46         }\r
47 \r
48         public static Services getService(Class<Executable<?>> runnerClassName) {\r
49                 assert runnerClassName != null;\r
50                 String sname = runnerClassName.getSimpleName().toLowerCase();\r
51                 for (Services service : Services.values()) {\r
52                         if (service.toString().toLowerCase().contains(sname)) {\r
53                                 return service;\r
54                         }\r
55                 }\r
56                 return null;\r
57         }\r
58 \r
59         Service getService(URL url, String sqname) {\r
60                 QName qname = new QName(sqname, this.toString());\r
61                 return Service.create(url, qname);\r
62         }\r
63 \r
64         Class<? extends JABAService> getServiceType() {\r
65                 switch (this) {\r
66                         // deliberate leaking\r
67                         case AAConWS :\r
68                         case JronnWS :\r
69                         case DisemblWS :\r
70                         case GlobPlotWS :\r
71 \r
72                                 return SequenceAnnotation.class;\r
73 \r
74                                 // deliberate leaking\r
75                         case ClustalWS :\r
76                         case MafftWS :\r
77                         case MuscleWS :\r
78                         case ProbconsWS :\r
79                         case TcoffeeWS :\r
80 \r
81                                 return MsaWS.class;\r
82                         default :\r
83                                 throw new RuntimeException("Unrecognised Web Service Type "\r
84                                                 + this + " - Should never happened!");\r
85                 }\r
86         }\r
87 \r
88         JABAService getInterface(Service service) {\r
89                 assert service != null;\r
90 \r
91                 QName portName = new QName(service.getServiceName().getNamespaceURI(),\r
92                                 this.toString() + "Port");\r
93                 return service.getPort(portName, this.getServiceType());\r
94         }\r
95 }