JWS2 client
[jabaws.git] / webservices / compbio / ws / client / CmdHelper.java
1 package compbio.ws.client;\r
2 import static compbio.ws.client.Constraints.hostkey;\r
3 import static compbio.ws.client.Constraints.limitList;\r
4 import static compbio.ws.client.Constraints.paramList;\r
5 import static compbio.ws.client.Constraints.presetList;\r
6 import static compbio.ws.client.Constraints.presetkey;\r
7 import static compbio.ws.client.Constraints.pseparator;\r
8 import static compbio.ws.client.Constraints.servicekey;\r
9 \r
10 class CmdHelper {\r
11 \r
12         /**\r
13          * Check whether presetList is set in the command line\r
14          * \r
15          * @param cmd\r
16          *            command line options\r
17          * @return true if presetList is found, false otherwise\r
18          */\r
19         static boolean listPresets(String[] cmd) {\r
20                 return keyFound(cmd, presetList);\r
21         }\r
22 \r
23         /**\r
24          * Checks whether limitList parameter is in the command line\r
25          * \r
26          * @param cmd\r
27          *            - command line options\r
28          * @return true if it is, false otherwise\r
29          */\r
30         static boolean listLimits(String[] cmd) {\r
31                 return keyFound(cmd, limitList);\r
32         }\r
33 \r
34         /**\r
35          * Checks whether the key is in the command line\r
36          * \r
37          * @param cmd\r
38          * @param key\r
39          * @return true if it is, false otherwise\r
40          */\r
41         static boolean keyFound(String[] cmd, String key) {\r
42                 assert cmd != null && cmd.length > 0;\r
43                 assert key != null;\r
44                 for (int i = 0; i < cmd.length; i++) {\r
45                         String listPresets = cmd[i];\r
46                         if (listPresets.trim().equalsIgnoreCase(key)) {\r
47                                 return true;\r
48                         }\r
49                 }\r
50                 return false;\r
51         }\r
52 \r
53         /**\r
54          * Extracts preset name from the command line is any\r
55          * \r
56          * @param cmd\r
57          *            command line options\r
58          * @return presetName or null if no presets is defined\r
59          */\r
60         static String getPresetName(String[] cmd) {\r
61                 String preset = null;\r
62                 for (int i = 0; i < cmd.length; i++) {\r
63                         String presetPrm = cmd[i];\r
64                         if (presetPrm.trim().toLowerCase()\r
65                                         .startsWith(presetkey + pseparator)) {\r
66                                 preset = presetPrm.substring(presetPrm.indexOf(pseparator) + 1);\r
67                                 break;\r
68                         }\r
69                 }\r
70                 return preset;\r
71         }\r
72 \r
73         /**\r
74          * Extracts service name from the command line\r
75          * \r
76          * @param cmd\r
77          *            command line options\r
78          * @return service name or null if it is not defined\r
79          */\r
80         public static String getServiceName(String[] cmd) {\r
81                 for (int i = 0; i < cmd.length; i++) {\r
82                         String serv = cmd[i];\r
83                         if (serv.trim().toLowerCase().startsWith(servicekey + pseparator)) {\r
84                                 return serv.substring(serv.indexOf(pseparator) + 1);\r
85                         }\r
86                 }\r
87                 return null;\r
88         }\r
89 \r
90         /**\r
91          * Extracts host name from the command line\r
92          * \r
93          * @param cmd\r
94          *            command line options\r
95          * @return host name or null if it is not defined\r
96          */\r
97         public static String getHost(String[] cmd) {\r
98                 for (int i = 0; i < cmd.length; i++) {\r
99                         String host = cmd[i];\r
100                         if (host.trim().toLowerCase().startsWith(hostkey + pseparator)) {\r
101                                 return host.substring(host.indexOf(pseparator) + 1);\r
102                         }\r
103                 }\r
104                 return null;\r
105         }\r
106 \r
107         /**\r
108          * Searches the command line keys in the array of parameters\r
109          * \r
110          * @param cmd\r
111          *            command line options\r
112          * @return true is the list of Parameters is requested, false otherwise\r
113          */\r
114         static boolean listParameters(String[] cmd) {\r
115                 return keyFound(cmd, paramList);\r
116         }\r
117 \r
118 }\r