JWS-17: fix problem with undefined URL for the furtherDetails tag
[jabaws.git] / webservices / compbio / ws / client / MetadataHelper.java
index d69c3c1..d5d8b06 100644 (file)
@@ -1,9 +1,29 @@
+/* Copyright (c) 2011 Peter Troshin\r
+ *  \r
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
+ * \r
+ *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ *  Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ *  License for more details.\r
+ * \r
+ *  A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
 package compbio.ws.client;\r
 \r
 import static compbio.ws.client.Constraints.pseparator;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Collections;\r
 import java.util.List;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
 \r
 import compbio.data.msa.Metadata;\r
 import compbio.metadata.Limit;\r
@@ -24,12 +44,26 @@ public class MetadataHelper {
         * @param msaws\r
         *            web service proxy\r
         * @return List of options supported by a web service\r
+        * @throws MalformedURLException \r
         */\r
-       static <T> List<Option<T>> getParametersList(Metadata<T> msaws) {\r
+       static <T> List<Option<T>> getParametersList(Metadata<T> msaws, String host) throws MalformedURLException {\r
                assert msaws != null;\r
-               return msaws.getRunnerOptions().getArguments();\r
+               RunnerConfig<T> config = msaws.getRunnerOptions();\r
+               if (config == null) {\r
+                       return Collections.emptyList();\r
+               }\r
+               List<Option<T>> opts = config.getArguments();\r
+               for (Option<T> o : opts) {\r
+                       o.setBasicURL(new URL(host + "/"));\r
+               }\r
+               return opts;\r
        }\r
 \r
+       static <T> List<Option<T>> getParametersList(Metadata<T> msaws) throws MalformedURLException {\r
+               return getParametersList (msaws, "http://unknown.jabaws.server.ac.uk");\r
+       }\r
+       \r
+       \r
        /**\r
         * Returns an objects from which the list of presets supported by web\r
         * service <T> can be obtained\r
@@ -76,14 +110,12 @@ public class MetadataHelper {
                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
+                       System.out.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
+                       System.out.println("Cannot find preset: " + presetName + " WARN: ignoring -r directive!");\r
                }\r
                return pre;\r
        }\r
@@ -109,17 +141,14 @@ public class MetadataHelper {
                        }\r
                        Option<T> o = options.getArgumentByOptionName(oname);\r
                        if (o == null) {\r
-                               System.out.println("WARN ignoring unsuppoted parameter: "\r
-                                               + oname);\r
+                               System.out.println("WARN ignoring unsuppoted parameter: " + 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
+                                       System.out.println("Problem setting value for the parameter: " + param);\r
                                        e.printStackTrace();\r
                                }\r
                        }\r