JAL-3066 JAL-3070 pull up non-jabaws specific service descriptor components for annot...
[jalview.git] / src / jalview / ws / jws2 / jabaws2 / Jws2Instance.java
index 85ac238..9f2d4ae 100644 (file)
@@ -23,13 +23,16 @@ package jalview.ws.jws2.jabaws2;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.util.MessageManager;
-import jalview.ws.api.UIinfo;
+import jalview.ws.api.JalviewServiceEndpointProviderI;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jws2.JabaParamStore;
 import jalview.ws.jws2.MsaWSClient;
 import jalview.ws.jws2.SequenceAnnotationWSClient;
 import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.ParamManager;
 
 import java.io.Closeable;
+import java.net.URL;
 
 import javax.swing.JMenu;
 
@@ -39,13 +42,12 @@ import compbio.data.msa.SequenceAnnotation;
 import compbio.metadata.PresetManager;
 import compbio.metadata.RunnerConfig;
 
-public class Jws2Instance extends UIinfo
+public class Jws2Instance extends ServiceWithParameters
+        implements JalviewServiceEndpointProviderI, AutoCloseable
 {
 
   public JABAService service;
 
-  public String docUrl;
-
   /**
    * 
    * @param hosturl
@@ -68,11 +70,26 @@ public class Jws2Instance extends UIinfo
     int p = description.indexOf("MORE INFORMATION:");
     if (p > -1)
     {
-      docUrl = description.substring(description.indexOf("http", p)).trim();
+      String docUrl = description.substring(description.indexOf("http", p))
+              .trim();
       if (docUrl.indexOf('\n') > -1)
       {
         docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
       }
+      if (docUrl.length() > 0)
+      {
+        try
+        {
+          URL url = new URL(docUrl);
+          if (url != null)
+          {
+            setDocumentationUrl(docUrl);
+          }
+        } catch (Exception x)
+        {
+
+        }
+      }
 
     }
   }
@@ -134,7 +151,7 @@ public class Jws2Instance extends UIinfo
   }
 
   @Override
-  protected void finalize() throws Throwable
+  public void close()
   {
     if (service != null)
     {
@@ -146,9 +163,10 @@ public class Jws2Instance extends UIinfo
         // ignore
       }
     }
-    super.finalize();
+    // super.finalize();
   }
 
+  @Override
   public ParamDatastoreI getParamStore()
   {
     if (paramStore == null)
@@ -168,20 +186,9 @@ public class Jws2Instance extends UIinfo
     return paramStore;
   }
 
-  public String getUri()
-  {
-    // TODO verify that service parameter sets in projects are consistent with
-    // Jalview 2.10.4
-    // this is only valid for Jaba 1.0 - this formula might have to change!
-    return getHostURL()
-            + (getHostURL().lastIndexOf("/") == (getHostURL().length() - 1)
-                    ? ""
-                    : "/")
-            + getName();
-  }
-
   private boolean hasParams = false, lookedForParams = false;
 
+  @Override
   public boolean hasParameters()
   {
     if (!lookedForParams)
@@ -211,15 +218,62 @@ public class Jws2Instance extends UIinfo
     }
   }
 
-  public String getNameURI()
+  /**
+   * initialise a parameter store for this service
+   * 
+   * @param userParameterStore
+   *          - the user ParamManager (e.g. Desktop.getUserParameterStore() )
+   */
+  @Override
+  public void initParamStore(ParamManager userParameterStore)
   {
-    return "java:" + getName();
+    if (paramStore == null)
+    {
+      paramStore = new JabaParamStore(this, userParameterStore);
+    }
   }
 
-  jalview.ws.uimodel.AlignAnalysisUIText aaui;
-
-  public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()
+  /**
+   * an object that implements one or more interfaces in jalview.ws.api
+   * 
+   * @return
+   */
+  @Override
+  public Object getEndpoint()
   {
-    return aaui;
+    if (service instanceof MsaWS<?>)
+    {
+      if (aaui != null)
+      {
+        throw new Error(
+                "JABAWS MsaWS based instant calculation not implemented.");
+
+      }
+      else
+      {
+        return new JabawsMsaInstance(this);
+      }
+    }
+    else
+    {
+      if (service instanceof compbio.data.msa.SequenceAnnotation)
+      {
+        if (aaui != null)
+        {
+          try
+          {
+            // probably a factory would be nicer but..
+            return aaui.getClient().getConstructor(getClass())
+                    .newInstance(this);
+          } catch (Throwable t)
+          {
+            throw new Error("Implementation Error in web service framework",
+                    t);
+          }
+        }
+        return new AADisorderClient(this);
+      }
+      return null;
+    }
   }
 }