893117fab5aa29bf9d7114c9a739a2897bd5dabd
[jabaws.git] / webservices / compbio / ws / client / Services.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.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 import java.util.Set;\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 \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         /*\r
37          * Make sure this class has NO references to runners or engines as it is a\r
38          * part of minimal client package. Such things should go into ServicesUtil\r
39          */\r
40         MafftWS, MuscleWS, ClustalWS, ClustalOWS, TcoffeeWS, ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS, IUPredWS;\r
41 \r
42         public static Services getService(String servName) {\r
43                 servName = servName.trim().toLowerCase();\r
44                 for (Services service : Services.values()) {\r
45                         if (service.toString().equalsIgnoreCase(servName)) {\r
46                                 return service;\r
47                         }\r
48                 }\r
49                 return null;\r
50         }\r
51 \r
52         Service getService(URL url, String sqname) {\r
53                 QName qname = new QName(sqname, this.toString());\r
54                 return Service.create(url, qname);\r
55         }\r
56 \r
57         public static String toString(Set<Services> services) {\r
58                 if (services == null || services.isEmpty()) {\r
59                         return "";\r
60                 }\r
61                 String value = "";\r
62                 String delim = ", ";\r
63                 for (Services serv : services) {\r
64                         value += serv.toString() + delim;\r
65                 }\r
66                 value = value.substring(0, value.length() - delim.length());\r
67                 return value;\r
68         }\r
69 \r
70         Class<? extends JABAService> getServiceType() {\r
71                 switch (this) {\r
72                         // deliberate leaking\r
73                         case AAConWS :\r
74                         case JronnWS :\r
75                         case DisemblWS :\r
76                         case GlobPlotWS :\r
77                         case IUPredWS :\r
78                                 return SequenceAnnotation.class;\r
79 \r
80                                 // deliberate leaking\r
81                         case ClustalWS :\r
82                         case ClustalOWS :\r
83                         case MafftWS :\r
84                         case MuscleWS :\r
85                         case ProbconsWS :\r
86                         case TcoffeeWS :\r
87 \r
88                                 return MsaWS.class;\r
89                         default :\r
90                                 throw new RuntimeException("Unrecognised Web Service Type "\r
91                                                 + this + " - Should never happened!");\r
92                 }\r
93         }\r
94 \r
95         JABAService getInterface(Service service) {\r
96                 assert service != null;\r
97 \r
98                 QName portName = new QName(service.getServiceName().getNamespaceURI(),\r
99                                 this.toString() + "Port");\r
100                 return service.getPort(portName, this.getServiceType());\r
101         }\r
102 }