Changing of input type
[jabaws.git] / webservices / compbio / ws / client / ServicesUtil.java
1 package compbio.ws.client;\r
2 \r
3 import java.io.File;\r
4 \r
5 import compbio.engine.client.ConfExecutable;\r
6 import compbio.engine.client.Executable;\r
7 import compbio.runner.conservation.AACon;\r
8 import compbio.runner.disorder.Disembl;\r
9 import compbio.runner.disorder.GlobPlot;\r
10 import compbio.runner.disorder.IUPred;\r
11 import compbio.runner.disorder.Jronn;\r
12 import compbio.runner.msa.ClustalO;\r
13 import compbio.runner.msa.ClustalW;\r
14 import compbio.runner.msa.Mafft;\r
15 import compbio.runner.msa.Muscle;\r
16 import compbio.runner.msa.Probcons;\r
17 import compbio.runner.msa.Tcoffee;\r
18 \r
19 public class ServicesUtil {\r
20 \r
21         public static Services getServiceByRunner(Class<? extends Executable> class1) {\r
22                 assert class1 != null;\r
23                 String sname = class1.getSimpleName().toLowerCase();\r
24                 for (Services service : Services.values()) {\r
25                         if (service.toString().toLowerCase().contains(sname)) {\r
26                                 return service;\r
27                         }\r
28                 }\r
29                 return null;\r
30         }\r
31 \r
32         public static Class<? extends Executable<?>> getServiceImpl(Services service) {\r
33                 switch (service) {\r
34                         case AAConWS :\r
35                                 return AACon.class;\r
36                         case ClustalOWS :\r
37                                 return ClustalO.class;\r
38                         case ClustalWS :\r
39                                 return ClustalW.class;\r
40                         case MafftWS :\r
41                                 return Mafft.class;\r
42                         case MuscleWS :\r
43                                 return Muscle.class;\r
44                         case TcoffeeWS :\r
45                                 return Tcoffee.class;\r
46                         case ProbconsWS :\r
47                                 return Probcons.class;\r
48                         case DisemblWS :\r
49                                 return Disembl.class;\r
50                         case GlobPlotWS :\r
51                                 return GlobPlot.class;\r
52                         case JronnWS :\r
53                                 return Jronn.class;\r
54                         case IUPredWS :\r
55                                 return IUPred.class;\r
56                         default :\r
57                                 throw new RuntimeException(\r
58                                                 "Unknown web service implementation class for service: "\r
59                                                                 + service);\r
60                 }\r
61         }\r
62 \r
63         public static Class<? extends Executable<?>> getRunnerByJobDirectory(\r
64                         File jobdir) {\r
65                 Services service = getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir));\r
66                 return getServiceImpl(service);\r
67         }\r
68 \r
69         private static String getRunnerNameByJobDirectory(File jobdir) {\r
70                 String name = jobdir.getName().split("#")[0];\r
71 \r
72                 if (name.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX)) {\r
73                         assert ConfExecutable.CLUSTER_TASK_ID_PREFIX.length() == 1;\r
74                         name = name.substring(1);\r
75                 }\r
76                 return name;\r
77         }\r
78 \r
79         public static Services getServiceByJobDirectory(File jobdir) {\r
80                 return getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir));\r
81         }\r
82 \r
83         private static Services getServiceByRunnerName(String name) {\r
84                 for (Services service : Services.values()) {\r
85                         String runnerName = getServiceImpl(service).getSimpleName()\r
86                                         .toLowerCase();\r
87                         name = name.trim().toLowerCase();\r
88                         if (name.startsWith(runnerName)) {\r
89                                 return service;\r
90                         }\r
91                 }\r
92                 return null;\r
93         }\r
94 \r
95 }\r