-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)\r
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
- * \r
- * This file is part of Jalview.\r
- * \r
- * Jalview is free software: you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License \r
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
- * \r
- * Jalview is distributed in the hope that it will be useful, but \r
- * WITHOUT ANY WARRANTY; without even the implied warranty \r
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
- * PURPOSE. See the GNU General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package jalview.ws;\r
-\r
-import java.awt.Component;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ActionListener;\r
-import java.util.Enumeration;\r
-import java.util.Hashtable;\r
-import java.util.StringTokenizer;\r
-import java.util.Vector;\r
-\r
-import javax.swing.*;\r
-\r
-import ext.vamsas.*;\r
-import jalview.datamodel.*;\r
-import jalview.gui.*;\r
-\r
-/**\r
- * DOCUMENT ME!\r
- * \r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class SeqSearchWSClient extends WS1Client\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 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, AlignFrame _alignFrame)\r
- {\r
- super();\r
- alignFrame = _alignFrame;\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", JOptionPane.WARNING_MESSAGE);\r
-\r
- return;\r
- }\r
-\r
- if ((wsInfo = setWebService(sh)) == null)\r
- {\r
- JOptionPane.showMessageDialog(Desktop.desktop,\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\r
- * synchronous service methods\r
- * \r
- * @param sh\r
- */\r
- public SeqSearchWSClient(ServiceHandle sh)\r
- {\r
- setWebService(sh, true);\r
- }\r
-\r
- public SeqSearchWSClient()\r
- {\r
-\r
- super();\r
- // add a class reference to the list\r
- }\r
-\r
- private void startSeqSearchClient(String altitle, AlignmentView msa,\r
- String db, Alignment seqdataset)\r
- {\r
- if (!locateWebService())\r
- {\r
- return;\r
- }\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 "\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
- * @return true if service was located.\r
- */\r
- private boolean locateWebService()\r
- {\r
- // this can be abstracted using reflection\r
- // TODO: MuscleWS transmuted to generic MsaWS client\r
- SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default\r
-\r
- try\r
- {\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 + "\n"\r
- + ex.getMessage());\r
- wsInfo.setStatus(WebserviceInfo.ERROR);\r
- ex.printStackTrace();\r
-\r
- return false;\r
- }\r
-\r
- loc.getEngine().setOption("axis", "1");\r
-\r
- return true;\r
- }\r
-\r
- protected String getServiceActionKey()\r
- {\r
- return "SeqSearch";\r
- }\r
-\r
- protected String getServiceActionDescription()\r
- {\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
- {\r
- dbParamsForEndpoint = new Hashtable();\r
- }\r
-\r
- public String[] getSupportedDatabases() throws Exception\r
- {\r
-\r
- // check that we haven't already been to this service endpoint\r
- if (dbParamsForEndpoint.containsKey(WsURL))\r
- {\r
- return (String[]) dbParamsForEndpoint.get(WsURL);\r
- }\r
- if (!locateWebService())\r
- {\r
- throw new Exception("Cannot contact service endpoint at " + WsURL);\r
- }\r
- String database = server.getDatabase();\r
- if (database == null)\r
- {\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
- {\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
- {\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
- {\r
- dbsrchs.put("Default Database", defmenu = new JMenu(\r
- "Default Database"));\r
- newdbsrch.addElement(defmenu);\r
- }\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
- // 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
- });\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,\r
- searchdb, af.getViewport().getAlignment().getDataset(),\r
- af);\r
- }\r
- });\r
- }\r
- // add the databases onto the seqsearch menu\r
- Enumeration e = newdbsrch.elements();\r
- while (e.hasMoreElements())\r
- {\r
- Object el = e.nextElement();\r
- if (el instanceof JMenu)\r
- {\r
- wsmenu.add((JMenu) el);\r
- }\r
- else\r
- {\r
- wsmenu.add((JMenuItem) el);\r
- }\r
- }\r
-\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ */
+package jalview.ws.jws1;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import javax.swing.*;
+
+import ext.vamsas.*;
+import jalview.datamodel.*;
+import jalview.gui.*;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class SeqSearchWSClient extends WS1Client
+{
+ /**
+ * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
+ */
+ ext.vamsas.SeqSearchI server;
+
+ AlignFrame alignFrame;
+
+ /**
+ * Creates a new MsaWSClient object that uses a service given by an externally
+ * retrieved ServiceHandle
+ *
+ * @param sh
+ * service handle of type AbstractName(MsaWS)
+ * @param altitle
+ * DOCUMENT ME!
+ * @param msa
+ * DOCUMENT ME!
+ * @param submitGaps
+ * DOCUMENT ME!
+ * @param preserveOrder
+ * DOCUMENT ME!
+ */
+
+ public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
+ jalview.datamodel.AlignmentView msa, String db,
+ Alignment seqdataset, AlignFrame _alignFrame)
+ {
+ super();
+ alignFrame = _alignFrame;
+ // can generalise the two errors below for metadata mapping from interface
+ // name to service client name
+ if (!sh.getAbstractName().equals(this.getServiceActionKey()))
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "The Service called \n" + sh.getName()
+ + "\nis not a \nSequence Search Service !",
+ "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+
+ if ((wsInfo = setWebService(sh)) == null)
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "The Sequence Search Service named " + sh.getName()
+ + " is unknown", "Internal Jalview Error",
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+ startSeqSearchClient(altitle, msa, db, seqdataset);
+
+ }
+
+ /**
+ * non-process web service interaction - use this for calling HEADLESS
+ * synchronous service methods
+ *
+ * @param sh
+ */
+ public SeqSearchWSClient(ServiceHandle sh)
+ {
+ setWebService(sh, true);
+ }
+
+ public SeqSearchWSClient()
+ {
+
+ super();
+ // add a class reference to the list
+ }
+
+ private void startSeqSearchClient(String altitle, AlignmentView msa,
+ String db, Alignment seqdataset)
+ {
+ if (!locateWebService())
+ {
+ return;
+ }
+ String visdb = (db == null || db == "") ? "default" : db; // need a visible
+ // name for a
+ // sequence db
+ boolean profileSearch = msa.getSequences().length > 2 ? true : false;
+ // single sequence or profile from alignment view
+ wsInfo.setProgressText("Searching "
+ + visdb
+ + (!profileSearch ? " with sequence "
+ + msa.getSequences()[0].getRefSeq().getName()
+ : " with profile") + " from " + altitle
+ + "\nJob details\n");
+
+ String jobtitle = WebServiceName
+ + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
+ + " of "
+ + visdb
+ + (!profileSearch ? " with sequence "
+ + msa.getSequences()[0].getRefSeq().getName()
+ : " with profile") + " from " + altitle;
+ SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,
+ wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,
+ seqdataset);
+ wsInfo.setthisService(ssthread);
+ ssthread.start();
+ }
+
+ /**
+ * Initializes the server field with a valid service implementation.
+ *
+ * @return true if service was located.
+ */
+ private boolean locateWebService()
+ {
+ // this can be abstracted using reflection
+ // TODO: MuscleWS transmuted to generic MsaWS client
+ SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
+
+ try
+ {
+ this.server = (SeqSearchI) loc.getSeqSearchService(new java.net.URL(
+ WsURL));
+ ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One
+ // minute
+ // timeout
+ } catch (Exception ex)
+ {
+ wsInfo.setProgressText("Serious! " + WebServiceName
+ + " Service location failed\nfor URL :" + WsURL + "\n"
+ + ex.getMessage());
+ wsInfo.setStatus(WebserviceInfo.ERROR);
+ ex.printStackTrace();
+
+ return false;
+ }
+
+ loc.getEngine().setOption("axis", "1");
+
+ return true;
+ }
+
+ protected String getServiceActionKey()
+ {
+ return "SeqSearch";
+ }
+
+ protected String getServiceActionDescription()
+ {
+ return "Sequence Database Search";
+ }
+
+ // simple caching of db parameters for each service endpoint
+ private static Hashtable dbParamsForEndpoint;
+ static
+ {
+ dbParamsForEndpoint = new Hashtable();
+ }
+
+ public String[] getSupportedDatabases() throws Exception
+ {
+
+ // check that we haven't already been to this service endpoint
+ if (dbParamsForEndpoint.containsKey(WsURL))
+ {
+ return (String[]) dbParamsForEndpoint.get(WsURL);
+ }
+ if (!locateWebService())
+ {
+ throw new Exception("Cannot contact service endpoint at " + WsURL);
+ }
+ String database = server.getDatabase();
+ if (database == null)
+ {
+ dbParamsForEndpoint.put(WsURL, new String[]
+ {});
+ return null;
+ }
+ StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
+ String[] dbs = new String[en.countTokens()];
+ for (int i = 0; i < dbs.length; i++)
+ {
+ dbs[i++] = en.nextToken().trim();
+ }
+ dbParamsForEndpoint.put(WsURL, dbs);
+ return dbs;
+ }
+
+ public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
+ final AlignFrame af)
+ {
+ // look for existing database service submenus on wsmenu
+ Hashtable dbsrchs = new Hashtable();
+ Vector newdbsrch = new Vector();
+ Component entries[] = wsmenu.getComponents();
+ for (int i = 0; entries != null && i < entries.length; i++)
+ {
+ if (entries[i] instanceof JMenu)
+ {
+ dbsrchs.put(entries[i].getName(), entries[i]);
+ }
+ }
+ JMenu defmenu = (JMenu) dbsrchs.get("Default Database");
+ if (defmenu == null)
+ {
+ dbsrchs.put("Default Database", defmenu = new JMenu(
+ "Default Database"));
+ newdbsrch.addElement(defmenu);
+ }
+
+ String dbs[] = null;
+ try
+ {
+ dbs = new jalview.ws.jws1.SeqSearchWSClient(sh).getSupportedDatabases();
+ } catch (Exception e)
+ {
+ jalview.bin.Cache.log.warn(
+ "Database list request failed, so disabling SeqSearch Service client "
+ + sh.getName() + " at " + sh.getEndpointURL(), e);
+ return;
+ }
+ JMenuItem method;
+ // do default entry
+ defmenu.add(method = new JMenuItem(sh.getName()));
+ method.setToolTipText(sh.getEndpointURL());
+ method.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ // use same input gatherer as for secondary structure prediction
+ // we could actually parameterise the gatherer method here...
+ AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
+ new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null, af
+ .getViewport().getAlignment().getDataset(), af);
+ }
+ });
+ // add entry for each database the service supports
+ for (int db = 0; dbs != null && db < dbs.length; db++)
+ {
+ JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
+ if (dbmenu == null)
+ {
+ dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
+ newdbsrch.addElement(dbmenu);
+ }
+ // add the client handler code for this service
+ dbmenu.add(method = new JMenuItem(sh.getName()));
+ method.setToolTipText(sh.getEndpointURL());
+ final String searchdb = dbs[db];
+ method.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
+ new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
+ searchdb, af.getViewport().getAlignment().getDataset(),
+ af);
+ }
+ });
+ }
+ // add the databases onto the seqsearch menu
+ Enumeration e = newdbsrch.elements();
+ while (e.hasMoreElements())
+ {
+ Object el = e.nextElement();
+ if (el instanceof JMenu)
+ {
+ wsmenu.add((JMenu) el);
+ }
+ else
+ {
+ wsmenu.add((JMenuItem) el);
+ }
+ }
+
+ }
+}