a0c1f56ae3f61ad4feef1369b009e0b11ae64eb9
[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 \r
30 /**\r
31  * List of web services currently supported by JABAWS version 2\r
32  * \r
33  */\r
34 public enum Services {\r
35         MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS;\r
36 \r
37         public static Services getService(String servName) {\r
38                 servName = servName.trim().toLowerCase();\r
39                 if (servName.equalsIgnoreCase(MafftWS.toString())) {\r
40                         return MafftWS;\r
41                 }\r
42                 if (servName.equalsIgnoreCase(ClustalWS.toString())) {\r
43                         return ClustalWS;\r
44                 }\r
45                 if (servName.equalsIgnoreCase(TcoffeeWS.toString())) {\r
46                         return TcoffeeWS;\r
47                 }\r
48                 if (servName.equalsIgnoreCase(MuscleWS.toString())) {\r
49                         return MuscleWS;\r
50                 }\r
51                 if (servName.equalsIgnoreCase(ProbconsWS.toString())) {\r
52                         return ProbconsWS;\r
53                 }\r
54                 if (servName.equalsIgnoreCase(AAConWS.toString())) {\r
55                         return AAConWS;\r
56                 }\r
57                 if (servName.equalsIgnoreCase(JronnWS.toString())) {\r
58                         return JronnWS;\r
59                 }\r
60                 if (servName.equalsIgnoreCase(DisemblWS.toString())) {\r
61                         return DisemblWS;\r
62                 }\r
63                 if (servName.equalsIgnoreCase(GlobPlotWS.toString())) {\r
64                         return GlobPlotWS;\r
65                 }\r
66                 return null;\r
67         }\r
68 \r
69         Service getService(URL url, String sqname) {\r
70                 QName qname = new QName(sqname, this.toString());\r
71                 return Service.create(url, qname);\r
72         }\r
73 \r
74         Class<? extends JABAService> getServiceType() {\r
75                 switch (this) {\r
76                         // deliberate leaking\r
77                         case AAConWS :\r
78                         case JronnWS :\r
79                         case DisemblWS :\r
80                         case GlobPlotWS :\r
81 \r
82                                 return SequenceAnnotation.class;\r
83 \r
84                                 // deliberate leaking\r
85                         case ClustalWS :\r
86                         case MafftWS :\r
87                         case MuscleWS :\r
88                         case ProbconsWS :\r
89                         case TcoffeeWS :\r
90 \r
91                                 return MsaWS.class;\r
92                         default :\r
93                                 throw new RuntimeException("Unrecognised Web Service Type "\r
94                                                 + this + " - Should never happened!");\r
95                 }\r
96         }\r
97 \r
98         JABAService getInterface(Service service) {\r
99                 assert service != null;\r
100 \r
101                 QName portName = new QName(service.getServiceName().getNamespaceURI(),\r
102                                 this.toString() + "Port");\r
103                 return service.getPort(portName, this.getServiceType());\r
104         }\r
105 }