Refactored client class to accomodate new WS interface and reduce the complexity
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Fri, 3 Dec 2010 19:03:59 +0000 (19:03 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Fri, 3 Dec 2010 19:03:59 +0000 (19:03 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@3428 e3abac25-378b-4346-85de-24260fe3988d

webservices/compbio/data/msa/Annotation.java
webservices/compbio/data/msa/JABAService.java [new file with mode: 0644]
webservices/compbio/data/msa/MsaWS.java
webservices/compbio/ws/client/CmdHelper.java [new file with mode: 0644]
webservices/compbio/ws/client/Constraints.java [new file with mode: 0644]
webservices/compbio/ws/client/IOHelper.java [new file with mode: 0644]
webservices/compbio/ws/client/Jws2Client.java
webservices/compbio/ws/client/MetadataHelper.java [new file with mode: 0644]
webservices/compbio/ws/client/Services.java
webservices/compbio/ws/client/WSTester.java
webservices/compbio/ws/server/AAConWS.java

index fb8436d..25e6ac1 100644 (file)
@@ -29,7 +29,7 @@ import compbio.metadata.WrongParameterException;
  *            executable type / web service type\r
  */\r
 @WebService(targetNamespace = "http://msa.data.compbio/01/12/2010/")\r
-public interface Annotation<T> extends JManagement, Metadata<T> {\r
+public interface Annotation<T> extends JABAService, JManagement, Metadata<T> {\r
 \r
        /**\r
         * \r
diff --git a/webservices/compbio/data/msa/JABAService.java b/webservices/compbio/data/msa/JABAService.java
new file mode 100644 (file)
index 0000000..69d53f7
--- /dev/null
@@ -0,0 +1,11 @@
+package compbio.data.msa;\r
+\r
+/**\r
+ * This is a marker interface, contains no methods\r
+ * \r
+ * @author pvtroshin\r
+ * \r
+ */\r
+public interface JABAService {\r
+\r
+}\r
index cea5cdf..43d1581 100644 (file)
@@ -45,7 +45,7 @@ import compbio.metadata.WrongParameterException;
  *            executable type / web service type\r
  */\r
 @WebService(targetNamespace = "http://msa.data.compbio/01/01/2010/")\r
-public interface MsaWS<T> extends JManagement, Metadata<T> {\r
+public interface MsaWS<T> extends JABAService, JManagement, Metadata<T> {\r
 \r
        /**\r
         * Align a list of sequences with default settings.\r
diff --git a/webservices/compbio/ws/client/CmdHelper.java b/webservices/compbio/ws/client/CmdHelper.java
new file mode 100644 (file)
index 0000000..1faf3dc
--- /dev/null
@@ -0,0 +1,118 @@
+package compbio.ws.client;\r
+import static compbio.ws.client.Constraints.hostkey;\r
+import static compbio.ws.client.Constraints.limitList;\r
+import static compbio.ws.client.Constraints.paramList;\r
+import static compbio.ws.client.Constraints.presetList;\r
+import static compbio.ws.client.Constraints.presetkey;\r
+import static compbio.ws.client.Constraints.pseparator;\r
+import static compbio.ws.client.Constraints.servicekey;\r
+\r
+class CmdHelper {\r
+\r
+       /**\r
+        * Check whether presetList is set in the command line\r
+        * \r
+        * @param cmd\r
+        *            command line options\r
+        * @return true if presetList is found, false otherwise\r
+        */\r
+       static boolean listPresets(String[] cmd) {\r
+               return keyFound(cmd, presetList);\r
+       }\r
+\r
+       /**\r
+        * Checks whether limitList parameter is in the command line\r
+        * \r
+        * @param cmd\r
+        *            - command line options\r
+        * @return true if it is, false otherwise\r
+        */\r
+       static boolean listLimits(String[] cmd) {\r
+               return keyFound(cmd, limitList);\r
+       }\r
+\r
+       /**\r
+        * Checks whether the key is in the command line\r
+        * \r
+        * @param cmd\r
+        * @param key\r
+        * @return true if it is, false otherwise\r
+        */\r
+       static boolean keyFound(String[] cmd, String key) {\r
+               assert cmd != null && cmd.length > 0;\r
+               assert key != null;\r
+               for (int i = 0; i < cmd.length; i++) {\r
+                       String listPresets = cmd[i];\r
+                       if (listPresets.trim().equalsIgnoreCase(key)) {\r
+                               return true;\r
+                       }\r
+               }\r
+               return false;\r
+       }\r
+\r
+       /**\r
+        * Extracts preset name from the command line is any\r
+        * \r
+        * @param cmd\r
+        *            command line options\r
+        * @return presetName or null if no presets is defined\r
+        */\r
+       static String getPresetName(String[] cmd) {\r
+               String preset = null;\r
+               for (int i = 0; i < cmd.length; i++) {\r
+                       String presetPrm = cmd[i];\r
+                       if (presetPrm.trim().toLowerCase()\r
+                                       .startsWith(presetkey + pseparator)) {\r
+                               preset = presetPrm.substring(presetPrm.indexOf(pseparator) + 1);\r
+                               break;\r
+                       }\r
+               }\r
+               return preset;\r
+       }\r
+\r
+       /**\r
+        * Extracts service name from the command line\r
+        * \r
+        * @param cmd\r
+        *            command line options\r
+        * @return service name or null if it is not defined\r
+        */\r
+       public static String getServiceName(String[] cmd) {\r
+               for (int i = 0; i < cmd.length; i++) {\r
+                       String serv = cmd[i];\r
+                       if (serv.trim().toLowerCase().startsWith(servicekey + pseparator)) {\r
+                               return serv.substring(serv.indexOf(pseparator) + 1);\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+\r
+       /**\r
+        * Extracts host name from the command line\r
+        * \r
+        * @param cmd\r
+        *            command line options\r
+        * @return host name or null if it is not defined\r
+        */\r
+       public static String getHost(String[] cmd) {\r
+               for (int i = 0; i < cmd.length; i++) {\r
+                       String host = cmd[i];\r
+                       if (host.trim().toLowerCase().startsWith(hostkey + pseparator)) {\r
+                               return host.substring(host.indexOf(pseparator) + 1);\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+\r
+       /**\r
+        * Searches the command line keys in the array of parameters\r
+        * \r
+        * @param cmd\r
+        *            command line options\r
+        * @return true is the list of Parameters is requested, false otherwise\r
+        */\r
+       static boolean listParameters(String[] cmd) {\r
+               return keyFound(cmd, paramList);\r
+       }\r
+\r
+}\r
diff --git a/webservices/compbio/ws/client/Constraints.java b/webservices/compbio/ws/client/Constraints.java
new file mode 100644 (file)
index 0000000..08b06ac
--- /dev/null
@@ -0,0 +1,24 @@
+package compbio.ws.client;\r
+\r
+class Constraints {\r
+\r
+       final static String pseparator = "=";\r
+\r
+       // Parameters for required command line options\r
+       final static String hostkey = "-h";\r
+       final static String servicekey = "-s";\r
+\r
+       // Actions\r
+       final static String inputkey = "-i";\r
+\r
+       final static String paramList = "-parameters";\r
+       final static String presetList = "-presets";\r
+       final static String limitList = "-limits";\r
+\r
+       // Options\r
+       final static String paramFile = "-f";\r
+       final static String outputkey = "-o";\r
+       final static String parameterkey = "-p";\r
+       final static String presetkey = "-r";\r
+\r
+}\r
diff --git a/webservices/compbio/ws/client/IOHelper.java b/webservices/compbio/ws/client/IOHelper.java
new file mode 100644 (file)
index 0000000..af9a52c
--- /dev/null
@@ -0,0 +1,112 @@
+package compbio.ws.client;\r
+\r
+import static compbio.ws.client.Constraints.pseparator;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import compbio.data.sequence.Alignment;\r
+import compbio.data.sequence.ClustalAlignmentUtil;\r
+\r
+public class IOHelper {\r
+\r
+       /**\r
+        * Checks -i options and return the File if one was provided, null otherwise\r
+        * \r
+        * @param cmd\r
+        * @param key\r
+        * @param mustExist\r
+        * @return\r
+        * @throws IOException\r
+        */\r
+       static File getFile(String[] cmd, String key, boolean mustExist)\r
+                       throws IOException {\r
+               assert key != null && key.trim().length() != 0;\r
+               for (int i = 0; i < cmd.length; i++) {\r
+                       String filename = cmd[i];\r
+                       filename = filename.trim();\r
+                       if (filename.toLowerCase().startsWith(key + pseparator)) {\r
+                               filename = filename.substring((key + pseparator).length());\r
+                               File file = new File(filename);\r
+                               if (mustExist && !file.exists()) {\r
+                                       System.out.println(key + " file " + file.getAbsolutePath()\r
+                                                       + " does not exist");\r
+                                       return null;\r
+                               }\r
+                               if (!mustExist && !file.exists()) {\r
+                                       file.createNewFile();\r
+                               }\r
+                               if (!file.canRead()) {\r
+                                       System.out.println("Cannot read " + key + " file "\r
+                                                       + file.getAbsolutePath());\r
+                                       return null;\r
+                               }\r
+                               return file;\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+\r
+       /**\r
+        * Load parameters from file\r
+        * \r
+        * @throws IOException\r
+        */\r
+       static List<String> loadParameters(File paramsfile) throws IOException {\r
+               assert paramsfile != null && paramsfile.exists();\r
+               BufferedReader reader = new BufferedReader(new FileReader(paramsfile));\r
+               String line = null;\r
+               ArrayList<String> params = new ArrayList<String>();\r
+               while ((line = reader.readLine()) != null) {\r
+                       line = line.trim();\r
+                       if (line.length() == 0)\r
+                               continue;\r
+                       params.add(line);\r
+               }\r
+               return params;\r
+       }\r
+\r
+       static OutputStream getOutStream(File file) {\r
+               assert file != null && file.exists();\r
+               try {\r
+                       return new FileOutputStream(file);\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               return null;\r
+       }\r
+\r
+       /**\r
+        * Outputs clustal formatted alignment into the file represented by the\r
+        * outStream\r
+        * \r
+        * @param outStream\r
+        * @param align\r
+        *            the alignment to output\r
+        */\r
+       static void writeOut(OutputStream outStream, Alignment align) {\r
+               try {\r
+                       ClustalAlignmentUtil.writeClustalAlignment(outStream, align);\r
+               } catch (IOException e) {\r
+                       System.err\r
+                                       .println("Problems writing output file! Stack trace is below: ");\r
+                       e.printStackTrace();\r
+               } finally {\r
+                       if (outStream != null) {\r
+                               try {\r
+                                       outStream.close();\r
+                               } catch (IOException ignored) {\r
+                                       // e.printStackTrace();\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
index 152646d..5c7a879 100644 (file)
 \r
 package compbio.ws.client;\r
 \r
-import java.io.BufferedReader;\r
+import static compbio.ws.client.Constraints.hostkey;\r
+import static compbio.ws.client.Constraints.inputkey;\r
+import static compbio.ws.client.Constraints.limitList;\r
+import static compbio.ws.client.Constraints.outputkey;\r
+import static compbio.ws.client.Constraints.paramFile;\r
+import static compbio.ws.client.Constraints.paramList;\r
+import static compbio.ws.client.Constraints.presetList;\r
+import static compbio.ws.client.Constraints.presetkey;\r
+import static compbio.ws.client.Constraints.pseparator;\r
+import static compbio.ws.client.Constraints.servicekey;\r
+\r
 import java.io.Closeable;\r
 import java.io.File;\r
 import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.FileReader;\r
 import java.io.IOException;\r
 import java.io.OutputStream;\r
 import java.net.MalformedURLException;\r
 import java.net.URL;\r
-import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.List;\r
 import java.util.logging.Level;\r
 import java.util.logging.Logger;\r
 \r
-import javax.xml.namespace.QName;\r
 import javax.xml.ws.Service;\r
 import javax.xml.ws.WebServiceException;\r
 \r
+import compbio.data.msa.JABAService;\r
+import compbio.data.msa.Metadata;\r
 import compbio.data.msa.MsaWS;\r
 import compbio.data.sequence.Alignment;\r
-import compbio.data.sequence.ClustalAlignmentUtil;\r
 import compbio.data.sequence.FastaSequence;\r
 import compbio.data.sequence.SequenceUtil;\r
 import compbio.metadata.JobSubmissionException;\r
-import compbio.metadata.Limit;\r
-import compbio.metadata.LimitsManager;\r
 import compbio.metadata.Option;\r
 import compbio.metadata.Preset;\r
-import compbio.metadata.PresetManager;\r
 import compbio.metadata.ResultNotAvailableException;\r
-import compbio.metadata.RunnerConfig;\r
 import compbio.metadata.WrongParameterException;\r
 \r
 /**\r
@@ -62,659 +64,344 @@ import compbio.metadata.WrongParameterException;
  */\r
 public class Jws2Client {\r
 \r
-    /*\r
-     * Use java.util.Logger instead of log4j logger to reduce the size of the\r
-     * client package\r
-     */\r
-    private static final Logger log = Logger.getLogger(Jws2Client.class\r
-           .getCanonicalName());\r
-\r
-    final static String pseparator = "=";\r
-\r
-    // Parameters for required command line options\r
-    final static String hostkey = "-h";\r
-    final static String servicekey = "-s";\r
-\r
-    // Actions\r
-    final static String inputkey = "-i";\r
-\r
-    final static String paramList = "-parameters";\r
-    final static String presetList = "-presets";\r
-    final static String limitList = "-limits";\r
-\r
-    // Options\r
-    final static String paramFile = "-f";\r
-    final static String outputkey = "-o";\r
-    final static String parameterkey = "-p";\r
-    final static String presetkey = "-r";\r
-\r
-    //JABAWS version 1.0 service name\r
-    static final String qualifiedServiceName = "http://msa.data.compbio/01/01/2010/";\r
-\r
-    /**\r
-     * Searches the command line keys in the array of parameters\r
-     * \r
-     * @param cmd\r
-     *            command line options\r
-     * @return true is the list of Parameters is requested, false otherwise\r
-     */\r
-    private boolean listParameters(String[] cmd) {\r
-       return keyFound(cmd, paramList);\r
-    }\r
-\r
-    /**\r
-     * Check whether presetList is set in the command line\r
-     * \r
-     * @param cmd\r
-     *            command line options\r
-     * @return true if presetList is found, false otherwise\r
-     */\r
-    boolean listPresets(String[] cmd) {\r
-       return keyFound(cmd, presetList);\r
-    }\r
-\r
-    /**\r
-     * Returns {@code Preset} by its name\r
-     * \r
-     * @see Preset\r
-     * @param <T>\r
-     * @param msaws\r
-     * @param presetName\r
-     * @return Return a Preset by its optionName\r
-     */\r
-    <T> Preset<T> getPreset(MsaWS<T> msaws, String presetName) {\r
-       assert presetName != null;\r
-       PresetManager<T> presets = getPresetList(msaws);\r
-       if (presets == null) {\r
-           System.out\r
-                   .println("No presets are supported by the service! Ignoring -r directive!");\r
-           return null;\r
-       }\r
-       Preset<T> pre = presets.getPresetByName(presetName);\r
-       if (pre == null) {\r
-           System.out.println("Cannot find preset: " + presetName\r
-                   + " WARN: ignoring -r directive!");\r
-       }\r
-       return pre;\r
-    }\r
-\r
-    /**\r
-     * Extracts preset name from the command line is any\r
-     * \r
-     * @param cmd\r
-     *            command line options\r
-     * @return presetName or null if no presets is defined\r
-     */\r
-    String getPresetName(String[] cmd) {\r
-       String preset = null;\r
-       for (int i = 0; i < cmd.length; i++) {\r
-           String presetPrm = cmd[i];\r
-           if (presetPrm.trim().toLowerCase().startsWith(\r
-                   presetkey + pseparator)) {\r
-               preset = presetPrm.substring(presetPrm.indexOf(pseparator) + 1);\r
-               break;\r
-           }\r
-       }\r
-       return preset;\r
-    }\r
-\r
-    /**\r
-     * Checks whether limitList parameter is in the command line\r
-     * \r
-     * @param cmd\r
-     *            - command line options\r
-     * @return true if it is, false otherwise\r
-     */\r
-    boolean listLimits(String[] cmd) {\r
-       return keyFound(cmd, limitList);\r
-    }\r
-\r
-    /**\r
-     * Checks whether the key is in the command line\r
-     * \r
-     * @param cmd\r
-     * @param key\r
-     * @return true if it is, false otherwise\r
-     */\r
-    boolean keyFound(String[] cmd, String key) {\r
-       assert cmd != null && cmd.length > 0;\r
-       assert key != null;\r
-       for (int i = 0; i < cmd.length; i++) {\r
-           String listPresets = cmd[i];\r
-           if (listPresets.trim().equalsIgnoreCase(key)) {\r
+       /*\r
+        * Use java.util.Logger instead of log4j logger to reduce the size of the\r
+        * client package\r
+        */\r
+       private static final Logger log = Logger.getLogger(Jws2Client.class\r
+                       .getCanonicalName());\r
+\r
+       // JABAWS version 1.0 service name\r
+       static final String QUALIFIED_SERVICE_NAME = "http://msa.data.compbio/01/01/2010/";\r
+\r
+       // JABAWS version 2.0 service name\r
+       static final String V2_QUALIFIED_SERVICE_NAME = "http://msa.data.compbio/01/12/2010/";\r
+\r
+       /**\r
+        * Attempt to construct the URL object from the string\r
+        * \r
+        * @param urlstr\r
+        * @return true if it succeed false otherwise\r
+        */\r
+       public static boolean validURL(String urlstr) {\r
+               try {\r
+                       if (urlstr == null || urlstr.trim().length() == 0) {\r
+                               return false;\r
+                       }\r
+                       new URL(urlstr);\r
+               } catch (MalformedURLException e) {\r
+                       return false;\r
+               }\r
                return true;\r
-           }\r
-       }\r
-       return false;\r
-    }\r
-\r
-    /**\r
-     * Attempt to construct the URL object from the string\r
-     * \r
-     * @param urlstr\r
-     * @return true if it succeed false otherwise\r
-     */\r
-    public static boolean validURL(String urlstr) {\r
-       try {\r
-           if (urlstr == null || urlstr.trim().length() == 0) {\r
-               return false;\r
-           }\r
-           new URL(urlstr);\r
-       } catch (MalformedURLException e) {\r
-           return false;\r
        }\r
-       return true;\r
-    }\r
 \r
-    /**\r
-     * Extracts service name from the command line\r
-     * \r
-     * @param cmd\r
-     *            command line options\r
-     * @return service name or null if it is not defined\r
-     */\r
-    public static String getServiceName(String[] cmd) {\r
-       for (int i = 0; i < cmd.length; i++) {\r
-           String serv = cmd[i];\r
-           if (serv.trim().toLowerCase().startsWith(servicekey + pseparator)) {\r
-               return serv.substring(serv.indexOf(pseparator) + 1);\r
-           }\r
-       }\r
-       return null;\r
-    }\r
-\r
-    /**\r
-     * Extracts host name from the command line\r
-     * \r
-     * @param cmd\r
-     *            command line options\r
-     * @return host name or null if it is not defined\r
-     */\r
-    public static String getHost(String[] cmd) {\r
-       for (int i = 0; i < cmd.length; i++) {\r
-           String host = cmd[i];\r
-           if (host.trim().toLowerCase().startsWith(hostkey + pseparator)) {\r
-               return host.substring(host.indexOf(pseparator) + 1);\r
-           }\r
-       }\r
-       return null;\r
-    }\r
+       /**\r
+        * Connects to the service and do the job as requested, if something goes\r
+        * wrong reports or/and prints usage help.\r
+        * \r
+        * @param <T>\r
+        *            web service type\r
+        * @param cmd\r
+        *            command line options\r
+        * @throws IOException\r
+        */\r
+       <T> Jws2Client(String[] cmd) throws IOException {\r
+\r
+               String hostname = CmdHelper.getHost(cmd);\r
+               if (hostname == null) {\r
+                       System.out.println("Host name is not provided!");\r
+                       printUsage(1);\r
+               }\r
 \r
-    /**\r
-     * Checks -i options and return the File if one was provided, null otherwise\r
-     * \r
-     * @param cmd\r
-     * @param key\r
-     * @param mustExist\r
-     * @return\r
-     * @throws IOException\r
-     */\r
-    File getFile(String[] cmd, String key, boolean mustExist)\r
-           throws IOException {\r
-       assert key != null && key.trim().length() != 0;\r
-       for (int i = 0; i < cmd.length; i++) {\r
-           String filename = cmd[i];\r
-           filename = filename.trim();\r
-           if (filename.toLowerCase().startsWith(key + pseparator)) {\r
-               filename = filename.substring((key + pseparator).length());\r
-               File file = new File(filename);\r
-               if (mustExist && !file.exists()) {\r
-                   System.out.println(key + " file " + file.getAbsolutePath()\r
-                           + " does not exist");\r
-                   return null;\r
+               if (!validURL(hostname)) {\r
+                       System.out.println("Host name is not valid!");\r
+                       printUsage(1);\r
                }\r
-               if (!mustExist && !file.exists()) {\r
-                   file.createNewFile();\r
+               String serviceName = CmdHelper.getServiceName(cmd);\r
+               if (serviceName == null) {\r
+                       System.out.println("Service name is no provided!");\r
+                       printUsage(1);\r
                }\r
-               if (!file.canRead()) {\r
-                   System.out.println("Cannot read " + key + " file "\r
-                           + file.getAbsolutePath());\r
-                   return null;\r
+               Services service = Services.getService(serviceName);\r
+               if (service == null) {\r
+                       System.out.println("Service " + serviceName\r
+                                       + " is no supported! Valid values are: "\r
+                                       + Arrays.toString(Services.values()));\r
+                       printUsage(1);\r
+               }\r
+               File inputFile = IOHelper.getFile(cmd, inputkey, true);\r
+               File outFile = IOHelper.getFile(cmd, outputkey, false);\r
+               File parametersFile = IOHelper.getFile(cmd, paramFile, true);\r
+               String presetName = CmdHelper.getPresetName(cmd);\r
+\r
+               Metadata<T> msaws = (Metadata<T>) connect(hostname, service);\r
+               Preset<T> preset = null;\r
+               if (presetName != null) {\r
+                       preset = MetadataHelper.getPreset(msaws, presetName);\r
+               }\r
+               List<Option<T>> customOptions = null;\r
+               if (parametersFile != null) {\r
+                       List<String> prms = IOHelper.loadParameters(parametersFile);\r
+                       customOptions = MetadataHelper.processParameters(prms,\r
+                                       msaws.getRunnerOptions());\r
+               }\r
+               Alignment alignment = null;\r
+               if (inputFile != null) {\r
+                       if (service == Services.AAConWS) {\r
+                               System.out.println("calc conserv!");\r
+                       } else {\r
+\r
+                               alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
+                                               customOptions);\r
+                               OutputStream outStream = null;\r
+                               if (outFile != null) {\r
+                                       outStream = IOHelper.getOutStream(outFile);\r
+                               } else {\r
+                                       // this stream is going to be closed later which is fine as\r
+                                       // std.out will not be\r
+                                       outStream = System.out;\r
+                               }\r
+                               IOHelper.writeOut(outStream, alignment);\r
+                               // stream is closed in the method no need to close it here\r
+                       }\r
                }\r
-               return file;\r
-           }\r
-       }\r
-       return null;\r
-    }\r
-\r
-    /**\r
-     * Connects to the service and do the job as requested, if something goes\r
-     * wrong reports or/and prints usage help.\r
-     * \r
-     * @param <T>\r
-     *            web service type\r
-     * @param cmd\r
-     *            command line options\r
-     * @throws IOException\r
-     */\r
-    <T> Jws2Client(String[] cmd) throws IOException {\r
-\r
-       String hostname = getHost(cmd);\r
-       if (hostname == null) {\r
-           System.out.println("Host name is not provided!");\r
-           printUsage(1);\r
-       }\r
 \r
-       if (!validURL(hostname)) {\r
-           System.out.println("Host name is not valid!");\r
-           printUsage(1);\r
-       }\r
-       String serviceName = getServiceName(cmd);\r
-       if (serviceName == null) {\r
-           System.out.println("Service name is no provided!");\r
-           printUsage(1);\r
-       }\r
-       Services service = Services.getService(serviceName);\r
-       if (service == null) {\r
-           System.out.println("Service " + serviceName\r
-                   + " is no supported! Valid values are: "\r
-                   + Arrays.toString(Services.values()));\r
-           printUsage(1);\r
+               boolean listParameters = CmdHelper.listParameters(cmd);\r
+               if (listParameters) {\r
+                       System.out.println(MetadataHelper.getParametersList(msaws));\r
+               }\r
+               boolean listPreset = CmdHelper.listPresets(cmd);\r
+               if (listPreset) {\r
+                       System.out.println(MetadataHelper.getPresetList(msaws));\r
+               }\r
+               boolean listLimits = CmdHelper.listLimits(cmd);\r
+               if (listLimits) {\r
+                       System.out.println(MetadataHelper.getLimits(msaws));\r
+               }\r
+               log.fine("Disconnecting...");\r
+               ((Closeable) msaws).close();\r
+               log.fine("Disconnected successfully!");\r
        }\r
-       File inputFile = getFile(cmd, inputkey, true);\r
-       File outFile = getFile(cmd, outputkey, false);\r
-       File parametersFile = getFile(cmd, paramFile, true);\r
-       String presetName = getPresetName(cmd);\r
 \r
-       MsaWS<T> msaws = connect(hostname, service);\r
-       Preset<T> preset = null;\r
-       if (presetName != null) {\r
-           preset = getPreset(msaws, presetName);\r
-       }\r
-       List<Option<T>> customOptions = null;\r
-       if (parametersFile != null) {\r
-           List<String> prms = loadParameters(parametersFile);\r
-           customOptions = processParameters(prms, msaws.getRunnerOptions());\r
-       }\r
-       Alignment alignment = null;\r
-       if (inputFile != null) {\r
-           alignment = align(inputFile, msaws, preset, customOptions);\r
-           OutputStream outStream = null;\r
-           if (outFile != null) {\r
-               outStream = getOutStream(outFile);\r
-           } else {\r
-               // this stream is going to be closed later which is fine as\r
-               // std.out will not be\r
-               outStream = System.out;\r
-           }\r
-           writeOut(outStream, alignment);\r
-           // stream is closed in the method no need to close it here\r
-       }\r
+       /**\r
+        * Connects to a web service by the host and the service name\r
+        * \r
+        * @param <T>\r
+        *            web service type\r
+        * @param host\r
+        * @param service\r
+        * @return MsaWS<T>\r
+        * @throws WebServiceException\r
+        */\r
+       public static JABAService connect(String host, Services service)\r
+                       throws WebServiceException {\r
+               URL url = null;\r
+               log.log(Level.FINE, "Attempting to connect...");\r
+               try {\r
+                       url = new URL(host + "/" + service.toString() + "?wsdl");\r
+               } catch (MalformedURLException e) {\r
+                       e.printStackTrace();\r
+                       // ignore as the host name is already verified\r
+               }\r
+               Service serv = null;\r
+               try {\r
+                       serv = service.getService(url, QUALIFIED_SERVICE_NAME);\r
+               } catch (WebServiceException wse) {\r
+                       System.out.println("Conecting to JABAWS version 2 service");\r
+                       if (isV2service(wse)) {\r
+                               serv = service.getService(url, V2_QUALIFIED_SERVICE_NAME);\r
+                       }\r
+               }\r
+               JABAService serviceIF = service.getInterface(serv);\r
+               log.log(Level.FINE, "Connected successfully!");\r
 \r
-       boolean listParameters = listParameters(cmd);\r
-       if (listParameters) {\r
-           System.out.println(getParametersList(msaws));\r
-       }\r
-       boolean listPreset = listPresets(cmd);\r
-       if (listPreset) {\r
-           System.out.println(getPresetList(msaws));\r
-       }\r
-       boolean listLimits = listLimits(cmd);\r
-       if (listLimits) {\r
-           System.out.println(getLimits(msaws));\r
+               return serviceIF;\r
        }\r
-       log.fine("Disconnecting...");\r
-       ((Closeable) msaws).close();\r
-       log.fine("Disconnected successfully!");\r
-    }\r
 \r
-    /**\r
-     * Load parameters from file\r
-     * \r
-     * @throws IOException\r
-     */\r
-    List<String> loadParameters(File paramsfile) throws IOException {\r
-       assert paramsfile != null && paramsfile.exists();\r
-       BufferedReader reader = new BufferedReader(new FileReader(paramsfile));\r
-       String line = null;\r
-       ArrayList<String> params = new ArrayList<String>();\r
-       while ((line = reader.readLine()) != null) {\r
-           line = line.trim();\r
-           if (line.length() == 0)\r
-               continue;\r
-           params.add(line);\r
+       static boolean isV2service(WebServiceException wse) {\r
+               String message = wse.getMessage();\r
+               int idx = message.indexOf("not a valid service");\r
+               if (idx > 0) {\r
+                       if (message.substring(idx).contains(V2_QUALIFIED_SERVICE_NAME)) {\r
+                               return true;\r
+                       }\r
+               }\r
+               return false;\r
        }\r
-       return params;\r
-    }\r
 \r
-    /**\r
-     * Converts options supplied via parameters file into {@code Option} objects\r
-     * \r
-     * @param <T>\r
-     *            web service type\r
-     * @param params\r
-     * @param options\r
-     * @return List of Options of type T\r
-     */\r
-    <T> List<Option<T>> processParameters(List<String> params,\r
-           RunnerConfig<T> options) {\r
-       List<Option<T>> chosenOptions = new ArrayList<Option<T>>();\r
-       for (String param : params) {\r
-           String oname = null;\r
-           if (isParameter(param)) {\r
-               oname = this.getParamName(param);\r
-           } else {\r
-               oname = param;\r
-           }\r
-           Option<T> o = options.getArgumentByOptionName(oname);\r
-           if (o == null) {\r
-               System.out.println("WARN ignoring unsuppoted parameter: "\r
-                       + oname);\r
-               continue;\r
-           }\r
-           if (isParameter(param)) {\r
+       /**\r
+        * Align sequences from the file using MsaWS\r
+        * \r
+        * @param <T>\r
+        *            web service type e.g. Clustal\r
+        * @param file\r
+        *            to write the resulting alignment to\r
+        * @param msaws\r
+        *            MsaWS required\r
+        * @param preset\r
+        *            Preset to use optional\r
+        * @param customOptions\r
+        *            file which contains new line separated list of options\r
+        * @return Alignment\r
+        */\r
+       static <T> Alignment align(File file, MsaWS<T> msaws, Preset<T> preset,\r
+                       List<Option<T>> customOptions) {\r
+               FileInputStream instream = null;\r
+               List<FastaSequence> fastalist = null;\r
+               Alignment alignment = null;\r
                try {\r
-                   o.setValue(getParamValue(param));\r
+                       instream = new FileInputStream(file);\r
+                       fastalist = SequenceUtil.readFasta(instream);\r
+                       instream.close();\r
+                       String jobId = null;\r
+                       if (customOptions != null && preset != null) {\r
+                               System.out\r
+                                               .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
+                       }\r
+                       if (customOptions != null) {\r
+                               jobId = msaws.customAlign(fastalist, customOptions);\r
+                       } else if (preset != null) {\r
+                               jobId = msaws.presetAlign(fastalist, preset);\r
+                       } else {\r
+                               jobId = msaws.align(fastalist);\r
+                       }\r
+                       Thread.sleep(1000);\r
+                       alignment = msaws.getResult(jobId);\r
+\r
+               } catch (IOException e) {\r
+                       System.err\r
+                                       .println("Exception while reading the input file. "\r
+                                                       + "Check that the input file contains a list of fasta formatted sequences! "\r
+                                                       + "Exception details are below:");\r
+                       e.printStackTrace();\r
+               } catch (JobSubmissionException e) {\r
+                       System.err\r
+                                       .println("Exception while submitting job to a web server. "\r
+                                                       + "Exception details are below:");\r
+                       e.printStackTrace();\r
+               } catch (ResultNotAvailableException e) {\r
+                       System.err.println("Exception while waiting for results. "\r
+                                       + "Exception details are below:");\r
+                       e.printStackTrace();\r
+               } catch (InterruptedException ignored) {\r
+                       // ignore and propagate an interruption\r
+                       Thread.currentThread().interrupt();\r
                } catch (WrongParameterException e) {\r
-                   System.out\r
-                           .println("Problem setting value for the parameter: "\r
-                                   + param);\r
-                   e.printStackTrace();\r
+                       e.printStackTrace();\r
+               } finally {\r
+                       if (instream != null) {\r
+                               try {\r
+                                       instream.close();\r
+                               } catch (IOException ignored) {\r
+                                       // ignore\r
+                               }\r
+                       }\r
                }\r
-           }\r
-           chosenOptions.add(o);\r
+               return alignment;\r
        }\r
-       return chosenOptions;\r
-    }\r
 \r
-    String getParamName(String fullName) {\r
-       assert isParameter(fullName);\r
-       return fullName.substring(0, fullName.indexOf(pseparator));\r
-    }\r
+       /**\r
+        * Prints Jws2Client usage information to standard out\r
+        * \r
+        * @param exitStatus\r
+        */\r
+       static void printUsage(int exitStatus) {\r
+               System.out.println();\r
+               System.out.println("Usage: <Class or Jar file name> " + hostkey\r
+                               + pseparator + "host_and_context " + servicekey + pseparator\r
+                               + "serviceName ACTION [OPTIONS] ");\r
+               System.out.println();\r
+               System.out\r
+                               .println(hostkey\r
+                                               + pseparator\r
+                                               + "<host_and_context> - a full URL to the JWS2 web server including context path e.g. http://10.31.1.159:8080/ws");\r
+               System.out.println(servicekey + pseparator + "<ServiceName> - one of "\r
+                               + Arrays.toString(Services.values()));\r
+               System.out.println();\r
+               System.out.println("ACTIONS: ");\r
+               System.out\r
+                               .println(inputkey\r
+                                               + pseparator\r
+                                               + "<inputFile> - full path to fasta formatted sequence file, from which to align sequences");\r
+               System.out.println(paramList\r
+                               + " - lists parameters supported by web service");\r
+               System.out.println(presetList\r
+                               + " - lists presets supported by web service");\r
+               System.out.println(limitList + " - lists web services limits");\r
+               System.out\r
+                               .println("Please note that if input file is specified other actions are ignored");\r
 \r
-    String getParamValue(String fullName) {\r
-       assert isParameter(fullName);\r
-       return fullName.substring(fullName.indexOf(pseparator) + 1);\r
-    }\r
+               System.out.println();\r
+               System.out.println("OPTIONS (only for use with -i action):");\r
 \r
-    boolean isParameter(String param) {\r
-       return param.contains(pseparator);\r
-    }\r
+               System.out.println(presetkey + pseparator\r
+                               + "<presetName> - name of the preset to use");\r
+               System.out\r
+                               .println(outputkey\r
+                                               + pseparator\r
+                                               + "<outputFile> - full path to the file where to write an alignment");\r
+               System.out\r
+                               .println("-f=<parameterInputFile> - the name of the file with the list of parameters to use.");\r
+               System.out\r
+                               .println("Please note that -r and -f options cannot be used together. "\r
+                                               + "Alignment is done with either preset or a parameters from the file, but not both!");\r
 \r
-    OutputStream getOutStream(File file) {\r
-       assert file != null && file.exists();\r
-       try {\r
-           return new FileOutputStream(file);\r
-       } catch (FileNotFoundException e) {\r
-           e.printStackTrace();\r
+               System.exit(exitStatus);\r
        }\r
-       return null;\r
-    }\r
 \r
-    /**\r
-     * Outputs clustal formatted alignment into the file represented by the\r
-     * outStream\r
-     * \r
-     * @param outStream\r
-     * @param align\r
-     *            the alignment to output\r
-     */\r
-    void writeOut(OutputStream outStream, Alignment align) {\r
-       try {\r
-           ClustalAlignmentUtil.writeClustalAlignment(outStream, align);\r
-       } catch (IOException e) {\r
-           System.err\r
-                   .println("Problems writing output file! Stack trace is below: ");\r
-           e.printStackTrace();\r
-       } finally {\r
-           if (outStream != null) {\r
-               try {\r
-                   outStream.close();\r
-               } catch (IOException ignored) {\r
-                   // e.printStackTrace();\r
+       /**\r
+        * Starts command line client, if no parameter are supported print help. Two\r
+        * parameters are required for successfull call the JWS2 host name and a\r
+        * service name.\r
+        * \r
+        * @param args\r
+        *            Usage: <Class or Jar file name> -h=host_and_context\r
+        *            -s=serviceName ACTION [OPTIONS]\r
+        * \r
+        *            -h=<host_and_context> - a full URL to the JWS2 web server\r
+        *            including context path e.g. http://10.31.1.159:8080/ws\r
+        * \r
+        *            -s=<ServiceName> - one of [MafftWS, MuscleWS, ClustalWS,\r
+        *            TcoffeeWS, ProbconsWS] ACTIONS:\r
+        * \r
+        *            -i=<inputFile> - full path to fasta formatted sequence file,\r
+        *            from which to align sequences\r
+        * \r
+        *            -parameters - lists parameters supported by web service\r
+        * \r
+        *            -presets - lists presets supported by web service\r
+        * \r
+        *            -limits - lists web services limits Please note that if input\r
+        *            file is specified other actions are ignored\r
+        * \r
+        *            OPTIONS: (only for use with -i action):\r
+        * \r
+        *            -r=<presetName> - name of the preset to use\r
+        * \r
+        *            -o=<outputFile> - full path to the file where to write an\r
+        *            alignment -f=<parameterInputFile> - the name of the file with\r
+        *            the list of parameters to use. Please note that -r and -f\r
+        *            options cannot be used together. Alignment is done with either\r
+        *            preset or a parameters from the file, but not both!\r
+        * \r
+        */\r
+       public static void main(String[] args) {\r
+\r
+               if (args == null) {\r
+                       printUsage(1);\r
+               }\r
+               if (args.length < 2) {\r
+                       System.out.println("Host and service names are required!");\r
+                       printUsage(1);\r
                }\r
-           }\r
-       }\r
-    }\r
-\r
-    /**\r
-     * Connects to a web service by the host and the service name\r
-     * \r
-     * @param <T>\r
-     *            web service type\r
-     * @param host\r
-     * @param service\r
-     * @return MsaWS<T>\r
-     * @throws WebServiceException\r
-     */\r
-    public static <T> MsaWS<T> connect(String host, Services service)\r
-           throws WebServiceException {\r
-       URL url = null;\r
-       log.log(Level.FINE, "Attempt to connect...");\r
-       try {\r
-           url = new URL(host + "/" + service.toString() + "?wsdl");\r
-       } catch (MalformedURLException e) {\r
-           e.printStackTrace();\r
-           // ignore as the host name is already verified\r
-       }\r
-       QName qname = new QName(qualifiedServiceName, service.toString());\r
-       Service serv = Service.create(url, qname);\r
-       MsaWS<T> msaws = serv.getPort(new QName(qualifiedServiceName, service\r
-               + "Port"), MsaWS.class);\r
-       log.log(Level.FINE, "Connected successfully!");\r
-       return msaws;\r
-    }\r
-\r
-    /**\r
-     * Align sequences from the file using MsaWS\r
-     * \r
-     * @param <T>\r
-     *            web service type e.g. Clustal\r
-     * @param file\r
-     *            to write the resulting alignment to\r
-     * @param msaws\r
-     *            MsaWS required\r
-     * @param preset\r
-     *            Preset to use optional\r
-     * @param customOptions\r
-     *            file which contains new line separated list of options\r
-     * @return Alignment\r
-     */\r
-    static <T> Alignment align(File file, MsaWS<T> msaws, Preset<T> preset,\r
-           List<Option<T>> customOptions) {\r
-       FileInputStream instream = null;\r
-       List<FastaSequence> fastalist = null;\r
-       Alignment alignment = null;\r
-       try {\r
-           instream = new FileInputStream(file);\r
-           fastalist = SequenceUtil.readFasta(instream);\r
-           instream.close();\r
-           String jobId = null;\r
-           if (customOptions != null && preset != null) {\r
-               System.out\r
-                       .println("WARN: Parameters (-f) are defined together with a preset (-r) ignoring preset!");\r
-           }\r
-           if (customOptions != null) {\r
-               jobId = msaws.customAlign(fastalist, customOptions);\r
-           } else if (preset != null) {\r
-               jobId = msaws.presetAlign(fastalist, preset);\r
-           } else {\r
-               jobId = msaws.align(fastalist);\r
-           }\r
-           Thread.sleep(1000);\r
-           alignment = msaws.getResult(jobId);\r
 \r
-       } catch (IOException e) {\r
-           System.err\r
-                   .println("Exception while reading the input file. "\r
-                           + "Check that the input file contains a list of fasta formatted sequences! "\r
-                           + "Exception details are below:");\r
-           e.printStackTrace();\r
-       } catch (JobSubmissionException e) {\r
-           System.err\r
-                   .println("Exception while submitting job to a web server. "\r
-                           + "Exception details are below:");\r
-           e.printStackTrace();\r
-       } catch (ResultNotAvailableException e) {\r
-           System.err.println("Exception while waiting for results. "\r
-                   + "Exception details are below:");\r
-           e.printStackTrace();\r
-       } catch (InterruptedException ignored) {\r
-           // ignore and propagate an interruption\r
-           Thread.currentThread().interrupt();\r
-       } catch (WrongParameterException e) {\r
-           e.printStackTrace();\r
-       } finally {\r
-           if (instream != null) {\r
                try {\r
-                   instream.close();\r
-               } catch (IOException ignored) {\r
-                   // ignore\r
+                       new Jws2Client(args);\r
+               } catch (IOException e) {\r
+                       log.log(Level.SEVERE, "IOException in client! " + e.getMessage(),\r
+                                       e.getCause());\r
+                       System.err.println("Cannot write output file! Stack trace: ");\r
+                       e.printStackTrace();\r
                }\r
-           }\r
-       }\r
-       return alignment;\r
-    }\r
-\r
-    /**\r
-     * Returns a list of options supported by web service\r
-     * \r
-     * @param <T>\r
-     *            web service type\r
-     * @param msaws\r
-     *            web service proxy\r
-     * @return List of options supported by a web service\r
-     */\r
-    <T> List<Option<T>> getParametersList(MsaWS<T> msaws) {\r
-       assert msaws != null;\r
-       return msaws.getRunnerOptions().getArguments();\r
-    }\r
-\r
-    /**\r
-     * Returns an objects from which the list of presets supported by web\r
-     * service <T> can be obtained\r
-     * \r
-     * @param <T>\r
-     *            web service type\r
-     * @param msaws\r
-     *            web service proxy\r
-     * @return PresetManager, object which operates on presets\r
-     */\r
-    <T> PresetManager<T> getPresetList(MsaWS<T> msaws) {\r
-       assert msaws != null;\r
-       PresetManager<T> presetman = msaws.getPresets();\r
-       return presetman;\r
-    }\r
-\r
-    /**\r
-     * Returns a list of limits supported by web service Each limit correspond\r
-     * to a particular preset.\r
-     * \r
-     * @param <T>\r
-     *            web service type\r
-     * @param msaws\r
-     *            web service proxy\r
-     * @return List of limits supported by a web service\r
-     */\r
-    <T> List<Limit<T>> getLimits(MsaWS<T> msaws) {\r
-       assert msaws != null;\r
-       LimitsManager<T> lmanger = msaws.getLimits();\r
-\r
-       return lmanger != null ? lmanger.getLimits() : null;\r
-    }\r
-\r
-    /**\r
-     * Prints Jws2Client usage information to standard out\r
-     * \r
-     * @param exitStatus\r
-     */\r
-    static void printUsage(int exitStatus) {\r
-       System.out.println();\r
-       System.out.println("Usage: <Class or Jar file name> " + hostkey\r
-               + pseparator + "host_and_context " + servicekey + pseparator\r
-               + "serviceName ACTION [OPTIONS] ");\r
-       System.out.println();\r
-       System.out\r
-               .println(hostkey\r
-                       + pseparator\r
-                       + "<host_and_context> - a full URL to the JWS2 web server including context path e.g. http://10.31.1.159:8080/ws");\r
-       System.out.println(servicekey + pseparator + "<ServiceName> - one of "\r
-               + Arrays.toString(Services.values()));\r
-       System.out.println();\r
-       System.out.println("ACTIONS: ");\r
-       System.out\r
-               .println(inputkey\r
-                       + pseparator\r
-                       + "<inputFile> - full path to fasta formatted sequence file, from which to align sequences");\r
-       System.out.println(paramList\r
-               + " - lists parameters supported by web service");\r
-       System.out.println(presetList\r
-               + " - lists presets supported by web service");\r
-       System.out.println(limitList + " - lists web services limits");\r
-       System.out\r
-               .println("Please note that if input file is specified other actions are ignored");\r
-\r
-       System.out.println();\r
-       System.out.println("OPTIONS (only for use with -i action):");\r
-\r
-       System.out.println(presetkey + pseparator\r
-               + "<presetName> - name of the preset to use");\r
-       System.out\r
-               .println(outputkey\r
-                       + pseparator\r
-                       + "<outputFile> - full path to the file where to write an alignment");\r
-       System.out\r
-               .println("-f=<parameterInputFile> - the name of the file with the list of parameters to use.");\r
-       System.out\r
-               .println("Please note that -r and -f options cannot be used together. "\r
-                       + "Alignment is done with either preset or a parameters from the file, but not both!");\r
-\r
-       System.exit(exitStatus);\r
-    }\r
-\r
-    /**\r
-     * Starts command line client, if no parameter are supported print help. Two\r
-     * parameters are required for successfull call the JWS2 host name and a\r
-     * service name.\r
-     * \r
-     * @param args\r
-     *            Usage: <Class or Jar file name> -h=host_and_context\r
-     *            -s=serviceName ACTION [OPTIONS]\r
-     * \r
-     *            -h=<host_and_context> - a full URL to the JWS2 web server\r
-     *            including context path e.g. http://10.31.1.159:8080/ws\r
-     * \r
-     *            -s=<ServiceName> - one of [MafftWS, MuscleWS, ClustalWS,\r
-     *            TcoffeeWS, ProbconsWS] ACTIONS:\r
-     * \r
-     *            -i=<inputFile> - full path to fasta formatted sequence file,\r
-     *            from which to align sequences\r
-     * \r
-     *            -parameters - lists parameters supported by web service\r
-     * \r
-     *            -presets - lists presets supported by web service\r
-     * \r
-     *            -limits - lists web services limits Please note that if input\r
-     *            file is specified other actions are ignored\r
-     * \r
-     *            OPTIONS: (only for use with -i action):\r
-     * \r
-     *            -r=<presetName> - name of the preset to use\r
-     * \r
-     *            -o=<outputFile> - full path to the file where to write an\r
-     *            alignment -f=<parameterInputFile> - the name of the file with\r
-     *            the list of parameters to use. Please note that -r and -f\r
-     *            options cannot be used together. Alignment is done with either\r
-     *            preset or a parameters from the file, but not both!\r
-     * \r
-     */\r
-    public static void main(String[] args) {\r
-\r
-       if (args == null) {\r
-           printUsage(1);\r
-       }\r
-       if (args.length < 2) {\r
-           System.out.println("Host and service names are required!");\r
-           printUsage(1);\r
-       }\r
-\r
-       try {\r
-           new Jws2Client(args);\r
-       } catch (IOException e) {\r
-           log.log(Level.SEVERE, "IOException in client! " + e.getMessage(), e\r
-                   .getCause());\r
-           System.err.println("Cannot write output file! Stack trace: ");\r
-           e.printStackTrace();\r
        }\r
-    }\r
 }\r
diff --git a/webservices/compbio/ws/client/MetadataHelper.java b/webservices/compbio/ws/client/MetadataHelper.java
new file mode 100644 (file)
index 0000000..d69c3c1
--- /dev/null
@@ -0,0 +1,145 @@
+package compbio.ws.client;\r
+\r
+import static compbio.ws.client.Constraints.pseparator;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import compbio.data.msa.Metadata;\r
+import compbio.metadata.Limit;\r
+import compbio.metadata.LimitsManager;\r
+import compbio.metadata.Option;\r
+import compbio.metadata.Preset;\r
+import compbio.metadata.PresetManager;\r
+import compbio.metadata.RunnerConfig;\r
+import compbio.metadata.WrongParameterException;\r
+\r
+public class MetadataHelper {\r
+\r
+       /**\r
+        * Returns a list of options supported by web service\r
+        * \r
+        * @param <T>\r
+        *            web service type\r
+        * @param msaws\r
+        *            web service proxy\r
+        * @return List of options supported by a web service\r
+        */\r
+       static <T> List<Option<T>> getParametersList(Metadata<T> msaws) {\r
+               assert msaws != null;\r
+               return msaws.getRunnerOptions().getArguments();\r
+       }\r
+\r
+       /**\r
+        * Returns an objects from which the list of presets supported by web\r
+        * service <T> can be obtained\r
+        * \r
+        * @param <T>\r
+        *            web service type\r
+        * @param msaws\r
+        *            web service proxy\r
+        * @return PresetManager, object which operates on presets\r
+        */\r
+       static <T> PresetManager<T> getPresetList(Metadata<T> msaws) {\r
+               assert msaws != null;\r
+               PresetManager<T> presetman = msaws.getPresets();\r
+               return presetman;\r
+       }\r
+\r
+       /**\r
+        * Returns a list of limits supported by web service Each limit correspond\r
+        * to a particular preset.\r
+        * \r
+        * @param <T>\r
+        *            web service type\r
+        * @param msaws\r
+        *            web service proxy\r
+        * @return List of limits supported by a web service\r
+        */\r
+       static <T> List<Limit<T>> getLimits(Metadata<T> msaws) {\r
+               assert msaws != null;\r
+               LimitsManager<T> lmanger = msaws.getLimits();\r
+\r
+               return lmanger != null ? lmanger.getLimits() : null;\r
+       }\r
+\r
+       /**\r
+        * Returns {@code Preset} by its name\r
+        * \r
+        * @see Preset\r
+        * @param <T>\r
+        * @param msaws\r
+        * @param presetName\r
+        * @return Return a Preset by its optionName\r
+        */\r
+       static <T> Preset<T> getPreset(Metadata<T> msaws, String presetName) {\r
+               assert presetName != null;\r
+               PresetManager<T> presets = MetadataHelper.getPresetList(msaws);\r
+               if (presets == null) {\r
+                       System.out\r
+                                       .println("No presets are supported by the service! Ignoring -r directive!");\r
+                       return null;\r
+               }\r
+               Preset<T> pre = presets.getPresetByName(presetName);\r
+               if (pre == null) {\r
+                       System.out.println("Cannot find preset: " + presetName\r
+                                       + " WARN: ignoring -r directive!");\r
+               }\r
+               return pre;\r
+       }\r
+\r
+       /**\r
+        * Converts options supplied via parameters file into {@code Option} objects\r
+        * \r
+        * @param <T>\r
+        *            web service type\r
+        * @param params\r
+        * @param options\r
+        * @return List of Options of type T\r
+        */\r
+       static <T> List<Option<T>> processParameters(List<String> params,\r
+                       RunnerConfig<T> options) {\r
+               List<Option<T>> chosenOptions = new ArrayList<Option<T>>();\r
+               for (String param : params) {\r
+                       String oname = null;\r
+                       if (isParameter(param)) {\r
+                               oname = getParamName(param);\r
+                       } else {\r
+                               oname = param;\r
+                       }\r
+                       Option<T> o = options.getArgumentByOptionName(oname);\r
+                       if (o == null) {\r
+                               System.out.println("WARN ignoring unsuppoted parameter: "\r
+                                               + oname);\r
+                               continue;\r
+                       }\r
+                       if (isParameter(param)) {\r
+                               try {\r
+                                       o.setValue(getParamValue(param));\r
+                               } catch (WrongParameterException e) {\r
+                                       System.out\r
+                                                       .println("Problem setting value for the parameter: "\r
+                                                                       + param);\r
+                                       e.printStackTrace();\r
+                               }\r
+                       }\r
+                       chosenOptions.add(o);\r
+               }\r
+               return chosenOptions;\r
+       }\r
+\r
+       static String getParamName(String fullName) {\r
+               assert isParameter(fullName);\r
+               return fullName.substring(0, fullName.indexOf(pseparator));\r
+       }\r
+\r
+       static String getParamValue(String fullName) {\r
+               assert isParameter(fullName);\r
+               return fullName.substring(fullName.indexOf(pseparator) + 1);\r
+       }\r
+\r
+       static boolean isParameter(String param) {\r
+               return param.contains(pseparator);\r
+       }\r
+\r
+}\r
index 21b8bbc..95a0a89 100644 (file)
 \r
 package compbio.ws.client;\r
 \r
+import java.net.URL;\r
+\r
+import javax.xml.namespace.QName;\r
+import javax.xml.ws.Service;\r
+\r
+import compbio.data.msa.Annotation;\r
+import compbio.data.msa.JABAService;\r
+import compbio.data.msa.MsaWS;\r
+\r
 /**\r
- * List of web services currently supported by JABAWS version 1\r
+ * List of web services currently supported by JABAWS version 2\r
  * \r
  */\r
 public enum Services {\r
-    MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS;\r
+       MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, AAConWS;\r
 \r
-    public static Services getService(String servName) {\r
-       servName = servName.trim().toLowerCase();\r
-       if (servName.equalsIgnoreCase(MafftWS.toString())) {\r
-           return MafftWS;\r
-       }\r
-       if (servName.equalsIgnoreCase(ClustalWS.toString())) {\r
-           return ClustalWS;\r
+       public static Services getService(String servName) {\r
+               servName = servName.trim().toLowerCase();\r
+               if (servName.equalsIgnoreCase(MafftWS.toString())) {\r
+                       return MafftWS;\r
+               }\r
+               if (servName.equalsIgnoreCase(ClustalWS.toString())) {\r
+                       return ClustalWS;\r
+               }\r
+               if (servName.equalsIgnoreCase(TcoffeeWS.toString())) {\r
+                       return TcoffeeWS;\r
+               }\r
+               if (servName.equalsIgnoreCase(MuscleWS.toString())) {\r
+                       return MuscleWS;\r
+               }\r
+               if (servName.equalsIgnoreCase(ProbconsWS.toString())) {\r
+                       return ProbconsWS;\r
+               }\r
+               if (servName.equalsIgnoreCase(AAConWS.toString())) {\r
+                       return AAConWS;\r
+               }\r
+               return null;\r
        }\r
-       if (servName.equalsIgnoreCase(TcoffeeWS.toString())) {\r
-           return TcoffeeWS;\r
-       }\r
-       if (servName.equalsIgnoreCase(MuscleWS.toString())) {\r
-           return MuscleWS;\r
-       }\r
-       if (servName.equalsIgnoreCase(ProbconsWS.toString())) {\r
-           return ProbconsWS;\r
+\r
+       Service getService(URL url, String sqname) {\r
+               QName qname = new QName(sqname, this.toString());\r
+               return Service.create(url, qname);\r
        }\r
-       return null;\r
-    }\r
 \r
-    public static Services getService(Class wsImplClass) {\r
-       return getService(wsImplClass.getSimpleName());\r
-    }\r
+       JABAService getInterface(Service service) {\r
+               assert service != null;\r
 \r
+               QName portName = new QName(service.getServiceName().getNamespaceURI(),\r
+                               this.toString() + "Port");\r
+\r
+               switch (this) {\r
+                       case AAConWS :\r
+\r
+                               return service.getPort(portName, Annotation.class);\r
+\r
+                               // deliberate leaking\r
+                       case ClustalWS :\r
+                       case MafftWS :\r
+                       case MuscleWS :\r
+                       case ProbconsWS :\r
+                       case TcoffeeWS :\r
+                               // TODO remove\r
+                               System.out.println("Qname from serv: " + portName);\r
+\r
+                               return service.getPort(portName, MsaWS.class);\r
+\r
+                       default :\r
+                               throw new RuntimeException("Should never happened!");\r
+               }\r
+       }\r
 }
\ No newline at end of file
index ddd6742..544ecad 100644 (file)
 \r
 package compbio.ws.client;\r
 \r
+import static compbio.ws.client.Constraints.hostkey;\r
+import static compbio.ws.client.Constraints.pseparator;\r
+import static compbio.ws.client.Constraints.servicekey;\r
+\r
 import java.io.ByteArrayInputStream;\r
 import java.io.Closeable;\r
 import java.io.IOException;\r
@@ -85,18 +89,17 @@ public class WSTester {
         * Prints usage\r
         */\r
        static void printUsage() {\r
-               System.out.println("Usage: <Class or Jar file name> "\r
-                               + Jws2Client.hostkey + Jws2Client.pseparator\r
-                               + "host_and_context " + "<" + Jws2Client.servicekey\r
-                               + Jws2Client.pseparator + "serviceName>");\r
+               System.out.println("Usage: <Class or Jar file name> " + hostkey\r
+                               + pseparator + "host_and_context " + "<" + servicekey\r
+                               + pseparator + "serviceName>");\r
                System.out.println();\r
                System.out\r
-                               .println(Jws2Client.hostkey\r
-                                               + Jws2Client.pseparator\r
+                               .println(hostkey\r
+                                               + pseparator\r
                                                + "<host_and_context> - a full URL to the JABAWS web server including context path e.g. http://10.31.1.159:8080/ws");\r
                System.out\r
-                               .println(Jws2Client.servicekey\r
-                                               + Jws2Client.pseparator\r
+                               .println(servicekey\r
+                                               + pseparator\r
                                                + "<ServiceName> - optional if unspecified all services are tested otherwise one of "\r
                                                + Arrays.toString(Services.values()));\r
                System.out.println();\r
@@ -270,7 +273,7 @@ public class WSTester {
                try {\r
                        System.out.print("Connecting to service " + service + " on " + host\r
                                        + " ... ");\r
-                       msaws = Jws2Client.connect(host, service);\r
+                       msaws = (MsaWS<T>) Jws2Client.connect(host, service);\r
                        System.out.println(OK);\r
                } catch (WebServiceException e) {\r
                        System.out.println(FAILED);\r
@@ -297,8 +300,8 @@ public class WSTester {
                        printUsage();\r
                        System.exit(0);\r
                }\r
-               String host = Jws2Client.getHost(args);\r
-               String serviceName = Jws2Client.getServiceName(args);\r
+               String host = CmdHelper.getHost(args);\r
+               String serviceName = CmdHelper.getServiceName(args);\r
                if (!Jws2Client.validURL(host)) {\r
                        System.out\r
                                        .println("<host_and_context> parameter is not provided or is incorrect!");\r
index 27b85f3..e77c878 100644 (file)
@@ -65,7 +65,7 @@ public class AAConWS implements Annotation<AACon> {
                ConfiguredExecutable<AACon> aacon = (ConfiguredExecutable<AACon>) asyncEngine\r
                                .getResults(jobId);\r
                HashSet<Score> mas = aacon.getResults();\r
-               log.info(jobId + " getConservation : " + mas);\r
+               log.trace(jobId + " getConservation : " + mas);\r
                return mas;\r
        }\r
        /*\r