implemented embl validation properly
[jalview.git] / src / jalview / ws / SeqSearchWSClient.java
index 6da2ebb..9b6023c 100644 (file)
@@ -34,66 +34,72 @@ import jalview.gui.*;
 \r
 /**\r
  * DOCUMENT ME!\r
- *\r
+ * \r
  * @author $author$\r
  * @version $Revision$\r
  */\r
-public class SeqSearchWSClient\r
-    extends WSClient\r
+public class SeqSearchWSClient extends WSClient\r
 {\r
   /**\r
    * server is a WSDL2Java generated stub for an archetypal MsaWSI service.\r
    */\r
   ext.vamsas.SeqSearchI server;\r
+\r
   AlignFrame alignFrame;\r
 \r
   /**\r
-   * Creates a new MsaWSClient object that uses a service\r
-   * given by an externally retrieved ServiceHandle\r
-   *\r
-   * @param sh service handle of type AbstractName(MsaWS)\r
-   * @param altitle DOCUMENT ME!\r
-   * @param msa DOCUMENT ME!\r
-   * @param submitGaps DOCUMENT ME!\r
-   * @param preserveOrder DOCUMENT ME!\r
+   * Creates a new MsaWSClient object that uses a service given by an externally\r
+   * retrieved ServiceHandle\r
+   * \r
+   * @param sh\r
+   *                service handle of type AbstractName(MsaWS)\r
+   * @param altitle\r
+   *                DOCUMENT ME!\r
+   * @param msa\r
+   *                DOCUMENT ME!\r
+   * @param submitGaps\r
+   *                DOCUMENT ME!\r
+   * @param preserveOrder\r
+   *                DOCUMENT ME!\r
    */\r
 \r
   public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,\r
-                     jalview.datamodel.AlignmentView msa, String db,\r
-                     Alignment seqdataset,\r
-                     AlignFrame _alignFrame)\r
+          jalview.datamodel.AlignmentView msa, String db,\r
+          Alignment seqdataset, AlignFrame _alignFrame)\r
   {\r
     super();\r
     alignFrame = _alignFrame;\r
-    // can generalise the two errors below for metadata mapping from interface name to service client name\r
+    // can generalise the two errors below for metadata mapping from interface\r
+    // name to service client name\r
     if (!sh.getAbstractName().equals(this.getServiceActionKey()))\r
     {\r
       JOptionPane.showMessageDialog(Desktop.desktop,\r
-                                    "The Service called \n" + sh.getName() +\r
-                                    "\nis not a \nSequence Search Service !",\r
-                                    "Internal Jalview Error",\r
-                                    JOptionPane.WARNING_MESSAGE);\r
+              "The Service called \n" + sh.getName()\r
+                      + "\nis not a \nSequence Search Service !",\r
+              "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);\r
 \r
       return;\r
     }\r
 \r
-    if ( (wsInfo = setWebService(sh)) == null)\r
+    if ((wsInfo = setWebService(sh)) == null)\r
     {\r
       JOptionPane.showMessageDialog(Desktop.desktop,\r
-                                    "The Sequence Search Service named " +\r
-                                    sh.getName() +\r
-                                    " is unknown", "Internal Jalview Error",\r
-                                    JOptionPane.WARNING_MESSAGE);\r
+              "The Sequence Search Service named " + sh.getName()\r
+                      + " is unknown", "Internal Jalview Error",\r
+              JOptionPane.WARNING_MESSAGE);\r
 \r
       return;\r
     }\r
     startSeqSearchClient(altitle, msa, db, seqdataset);\r
 \r
   }\r
+\r
   /**\r
- * non-process web service interaction - use this for calling HEADLESS synchronous service methods\r
- * @param sh\r
- */\r
+   * non-process web service interaction - use this for calling HEADLESS\r
+   * synchronous service methods\r
+   * \r
+   * @param sh\r
+   */\r
   public SeqSearchWSClient(ServiceHandle sh)\r
   {\r
     setWebService(sh, true);\r
@@ -105,37 +111,43 @@ public class SeqSearchWSClient
     super();\r
     // add a class reference to the list\r
   }\r
+\r
   private void startSeqSearchClient(String altitle, AlignmentView msa,\r
-                                String db,\r
-                                Alignment seqdataset)\r
+          String db, Alignment seqdataset)\r
   {\r
     if (!locateWebService())\r
     {\r
       return;\r
     }\r
-    String visdb = (db==null || db == "") ? "default" : db; // need a visible name for a sequence db\r
-    boolean profileSearch = msa.getSequences().length>2 ? true : false;\r
+    String visdb = (db == null || db == "") ? "default" : db; // need a visible\r
+                                                              // name for a\r
+                                                              // sequence db\r
+    boolean profileSearch = msa.getSequences().length > 2 ? true : false;\r
     // single sequence or profile from alignment view\r
-    wsInfo.setProgressText( "Searching "+visdb+(!profileSearch ? " with sequence "+msa.getSequences()[0].getRefSeq().getName()\r
-              : " with profile") +\r
-                           " from " + altitle + "\nJob details\n");\r
-    \r
-    String jobtitle = WebServiceName+((WebServiceName.indexOf("earch")>-1) ? " " : " search ")+" of "+visdb+(!profileSearch ? " with sequence "+msa.getSequences()[0].getRefSeq().getName()\r
-            : " with profile") +\r
-            " from " + altitle;\r
-    SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL, wsInfo, alignFrame,\r
-                                            WebServiceName,\r
-                                            jobtitle,\r
-                                            msa,\r
-                                            db,\r
-                                            seqdataset);\r
+    wsInfo.setProgressText("Searching "\r
+            + visdb\r
+            + (!profileSearch ? " with sequence "\r
+                    + msa.getSequences()[0].getRefSeq().getName()\r
+                    : " with profile") + " from " + altitle\r
+            + "\nJob details\n");\r
+\r
+    String jobtitle = WebServiceName\r
+            + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")\r
+            + " of "\r
+            + visdb\r
+            + (!profileSearch ? " with sequence "\r
+                    + msa.getSequences()[0].getRefSeq().getName()\r
+                    : " with profile") + " from " + altitle;\r
+    SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,\r
+            wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,\r
+            seqdataset);\r
     wsInfo.setthisService(ssthread);\r
     ssthread.start();\r
   }\r
 \r
   /**\r
    * Initializes the server field with a valid service implementation.\r
-   *\r
+   * \r
    * @return true if service was located.\r
    */\r
   private boolean locateWebService()\r
@@ -146,15 +158,16 @@ public class SeqSearchWSClient
 \r
     try\r
     {\r
-      this.server = (SeqSearchI) loc.getSeqSearchService(new java.net.URL(WsURL));\r
-      ( (SeqSearchServiceSoapBindingStub)this.server).setTimeout(60000); // One minute timeout\r
-    }\r
-    catch (Exception ex)\r
+      this.server = (SeqSearchI) loc.getSeqSearchService(new java.net.URL(\r
+              WsURL));\r
+      ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One\r
+                                                                          // minute\r
+                                                                          // timeout\r
+    } catch (Exception ex)\r
     {\r
-      wsInfo.setProgressText("Serious! " + WebServiceName +\r
-                             " Service location failed\nfor URL :" + WsURL +\r
-                             "\n" +\r
-                             ex.getMessage());\r
+      wsInfo.setProgressText("Serious! " + WebServiceName\r
+              + " Service location failed\nfor URL :" + WsURL + "\n"\r
+              + ex.getMessage());\r
       wsInfo.setStatus(WebserviceInfo.ERROR);\r
       ex.printStackTrace();\r
 \r
@@ -175,14 +188,17 @@ public class SeqSearchWSClient
   {\r
     return "Sequence Database Search";\r
   }\r
+\r
   // simple caching of db parameters for each service endpoint\r
   private static Hashtable dbParamsForEndpoint;\r
-  static { \r
+  static\r
+  {\r
     dbParamsForEndpoint = new Hashtable();\r
   }\r
+\r
   public String[] getSupportedDatabases() throws Exception\r
   {\r
-    \r
+\r
     // check that we haven't already been to this service endpoint\r
     if (dbParamsForEndpoint.containsKey(WsURL))\r
     {\r
@@ -190,93 +206,97 @@ public class SeqSearchWSClient
     }\r
     if (!locateWebService())\r
     {\r
-      throw new Exception("Cannot contact service endpoint at "+WsURL); \r
+      throw new Exception("Cannot contact service endpoint at " + WsURL);\r
     }\r
     String database = server.getDatabase();\r
-    if (database==null)\r
+    if (database == null)\r
     {\r
-      dbParamsForEndpoint.put(WsURL, new String[] {});\r
+      dbParamsForEndpoint.put(WsURL, new String[]\r
+      {});\r
       return null;\r
     }\r
     StringTokenizer en = new StringTokenizer(database.trim(), ",| ");\r
     String[] dbs = new String[en.countTokens()];\r
-    for (int i=0; i<dbs.length; i++)\r
+    for (int i = 0; i < dbs.length; i++)\r
     {\r
       dbs[i++] = en.nextToken().trim();\r
     }\r
     dbParamsForEndpoint.put(WsURL, dbs);\r
     return dbs;\r
   }\r
+\r
   public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,\r
           final AlignFrame af)\r
   {\r
     // look for existing database service submenus on wsmenu\r
     Hashtable dbsrchs = new Hashtable();\r
     Vector newdbsrch = new Vector();\r
-    Component entries[] =  wsmenu.getComponents();\r
-    for (int i = 0; entries!=null && i<entries.length; i++)\r
+    Component entries[] = wsmenu.getComponents();\r
+    for (int i = 0; entries != null && i < entries.length; i++)\r
     {\r
       if (entries[i] instanceof JMenu)\r
       {\r
         dbsrchs.put(entries[i].getName(), entries[i]);\r
       }\r
     }\r
-    JMenu defmenu=(JMenu) dbsrchs.get("Default Database");\r
-    if (defmenu==null)\r
+    JMenu defmenu = (JMenu) dbsrchs.get("Default Database");\r
+    if (defmenu == null)\r
     {\r
-      dbsrchs.put("Default Database", defmenu = new JMenu("Default Database"));\r
+      dbsrchs.put("Default Database", defmenu = new JMenu(\r
+              "Default Database"));\r
       newdbsrch.addElement(defmenu);\r
     }\r
-      \r
-      String dbs[] = null;\r
-      try {\r
-        dbs = new jalview.ws.SeqSearchWSClient(sh).getSupportedDatabases();\r
-      } catch (Exception e)\r
+\r
+    String dbs[] = null;\r
+    try\r
+    {\r
+      dbs = new jalview.ws.SeqSearchWSClient(sh).getSupportedDatabases();\r
+    } catch (Exception e)\r
+    {\r
+      jalview.bin.Cache.log.warn(\r
+              "Database list request failed, so disabling SeqSearch Service client "\r
+                      + sh.getName() + " at " + sh.getEndpointURL(), e);\r
+      return;\r
+    }\r
+    JMenuItem method;\r
+    // do default entry\r
+    defmenu.add(method = new JMenuItem(sh.getName()));\r
+    method.setToolTipText(sh.getEndpointURL());\r
+    method.addActionListener(new ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
       {\r
-        jalview.bin.Cache.log.warn("Database list request failed, so disabling SeqSearch Service client "+sh.getName()+" at "+sh.getEndpointURL(), e);\r
-        return;\r
+        // use same input gatherer as for secondary structure prediction\r
+        // we could actually parameterise the gatherer method here...\r
+        AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();\r
+        new jalview.ws.SeqSearchWSClient(sh, af.getTitle(), msa, null, af\r
+                .getViewport().getAlignment().getDataset(), af);\r
       }\r
-      JMenuItem method;\r
-      // do default entry\r
-      defmenu.add(method = new JMenuItem(sh.getName()));\r
+    });\r
+    // add entry for each database the service supports\r
+    for (int db = 0; dbs != null && db < dbs.length; db++)\r
+    {\r
+      JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);\r
+      if (dbmenu == null)\r
+      {\r
+        dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));\r
+        newdbsrch.addElement(dbmenu);\r
+      }\r
+      // add the client handler code for this service\r
+      dbmenu.add(method = new JMenuItem(sh.getName()));\r
       method.setToolTipText(sh.getEndpointURL());\r
+      final String searchdb = dbs[db];\r
       method.addActionListener(new ActionListener()\r
       {\r
         public void actionPerformed(ActionEvent e)\r
         {\r
-          // use same input gatherer as for secondary structure prediction\r
-          // we could actually parameterise the gatherer method here...\r
           AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();\r
-          new jalview.ws.SeqSearchWSClient(sh, af.getTitle(), msa, null, \r
-                  af.getViewport().getAlignment().getDataset(),\r
+          new jalview.ws.SeqSearchWSClient(sh, af.getTitle(), msa,\r
+                  searchdb, af.getViewport().getAlignment().getDataset(),\r
                   af);\r
-          }\r
-        }\r
-      );\r
-      // add entry for each database the service supports\r
-      for (int db=0; dbs!=null && db<dbs.length; db++)\r
-      {\r
-        JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);\r
-        if (dbmenu==null)\r
-        {\r
-          dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));\r
-          newdbsrch.addElement(dbmenu);\r
         }\r
-        // add the client handler code for this service\r
-        dbmenu.add(method = new JMenuItem(sh.getName()));\r
-        method.setToolTipText(sh.getEndpointURL());\r
-        final String searchdb = dbs[db];\r
-        method.addActionListener(new ActionListener()\r
-        {\r
-          public void actionPerformed(ActionEvent e)\r
-          {\r
-            AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();\r
-            new jalview.ws.SeqSearchWSClient(sh, af.getTitle(), msa, searchdb, \r
-                      af.getViewport().getAlignment().getDataset(),\r
-                      af);\r
-          }\r
-        });\r
-      }\r
+      });\r
+    }\r
     // add the databases onto the seqsearch menu\r
     Enumeration e = newdbsrch.elements();\r
     while (e.hasMoreElements())\r
@@ -285,10 +305,12 @@ public class SeqSearchWSClient
       if (el instanceof JMenu)\r
       {\r
         wsmenu.add((JMenu) el);\r
-      } else {\r
+      }\r
+      else\r
+      {\r
         wsmenu.add((JMenuItem) el);\r
       }\r
     }\r
-    \r
+\r
   }\r
 }\r