2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
\r
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
21 import java.awt.Component;
\r
22 import java.awt.event.ActionEvent;
\r
23 import java.awt.event.ActionListener;
\r
24 import java.util.Enumeration;
\r
25 import java.util.Hashtable;
\r
26 import java.util.StringTokenizer;
\r
27 import java.util.Vector;
\r
29 import javax.swing.*;
\r
31 import ext.vamsas.*;
\r
32 import jalview.datamodel.*;
\r
33 import jalview.gui.*;
\r
39 * @version $Revision$
\r
41 public class SeqSearchWSClient
\r
45 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
\r
47 ext.vamsas.SeqSearchI server;
\r
48 AlignFrame alignFrame;
\r
51 * Creates a new MsaWSClient object that uses a service
\r
52 * given by an externally retrieved ServiceHandle
\r
54 * @param sh service handle of type AbstractName(MsaWS)
\r
55 * @param altitle DOCUMENT ME!
\r
56 * @param msa DOCUMENT ME!
\r
57 * @param submitGaps DOCUMENT ME!
\r
58 * @param preserveOrder DOCUMENT ME!
\r
61 public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
\r
62 jalview.datamodel.AlignmentView msa, String db,
\r
63 Alignment seqdataset,
\r
64 AlignFrame _alignFrame)
\r
67 alignFrame = _alignFrame;
\r
68 // can generalise the two errors below for metadata mapping from interface name to service client name
\r
69 if (!sh.getAbstractName().equals(this.getServiceActionKey()))
\r
71 JOptionPane.showMessageDialog(Desktop.desktop,
\r
72 "The Service called \n" + sh.getName() +
\r
73 "\nis not a \nSequence Search Service !",
\r
74 "Internal Jalview Error",
\r
75 JOptionPane.WARNING_MESSAGE);
\r
80 if ( (wsInfo = setWebService(sh)) == null)
\r
82 JOptionPane.showMessageDialog(Desktop.desktop,
\r
83 "The Sequence Search Service named " +
\r
85 " is unknown", "Internal Jalview Error",
\r
86 JOptionPane.WARNING_MESSAGE);
\r
90 startSeqSearchClient(altitle, msa, db, seqdataset);
\r
94 * non-process web service interaction - use this for calling HEADLESS synchronous service methods
\r
97 public SeqSearchWSClient(ServiceHandle sh)
\r
99 setWebService(sh, true);
\r
102 public SeqSearchWSClient()
\r
106 // add a class reference to the list
\r
108 private void startSeqSearchClient(String altitle, AlignmentView msa,
\r
110 Alignment seqdataset)
\r
112 if (!locateWebService())
\r
116 String visdb = (db==null || db == "") ? "default" : db; // need a visible name for a sequence db
\r
117 boolean profileSearch = msa.getSequences().length>2 ? true : false;
\r
118 // single sequence or profile from alignment view
\r
119 wsInfo.setProgressText( "Searching "+visdb+(!profileSearch ? " with sequence "+msa.getSequences()[0].getRefSeq().getName()
\r
120 : " with profile") +
\r
121 " from " + altitle + "\nJob details\n");
\r
123 String jobtitle = WebServiceName+((WebServiceName.indexOf("earch")>-1) ? " " : " search ")+" of "+visdb+(!profileSearch ? " with sequence "+msa.getSequences()[0].getRefSeq().getName()
\r
124 : " with profile") +
\r
125 " from " + altitle;
\r
126 SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL, wsInfo, alignFrame,
\r
132 wsInfo.setthisService(ssthread);
\r
137 * Initializes the server field with a valid service implementation.
\r
139 * @return true if service was located.
\r
141 private boolean locateWebService()
\r
143 // this can be abstracted using reflection
\r
144 // TODO: MuscleWS transmuted to generic MsaWS client
\r
145 SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
\r
149 this.server = (SeqSearchI) loc.getSeqSearchService(new java.net.URL(WsURL));
\r
150 ( (SeqSearchServiceSoapBindingStub)this.server).setTimeout(60000); // One minute timeout
\r
152 catch (Exception ex)
\r
154 wsInfo.setProgressText("Serious! " + WebServiceName +
\r
155 " Service location failed\nfor URL :" + WsURL +
\r
158 wsInfo.setStatus(WebserviceInfo.ERROR);
\r
159 ex.printStackTrace();
\r
164 loc.getEngine().setOption("axis", "1");
\r
169 protected String getServiceActionKey()
\r
171 return "SeqSearch";
\r
174 protected String getServiceActionDescription()
\r
176 return "Sequence Database Search";
\r
178 // simple caching of db parameters for each service endpoint
\r
179 private static Hashtable dbParamsForEndpoint;
\r
181 dbParamsForEndpoint = new Hashtable();
\r
183 public String[] getSupportedDatabases() throws Exception
\r
186 // check that we haven't already been to this service endpoint
\r
187 if (dbParamsForEndpoint.containsKey(WsURL))
\r
189 return (String[]) dbParamsForEndpoint.get(WsURL);
\r
191 if (!locateWebService())
\r
193 throw new Exception("Cannot contact service endpoint at "+WsURL);
\r
195 String database = server.getDatabase();
\r
196 if (database==null)
\r
198 dbParamsForEndpoint.put(WsURL, new String[] {});
\r
201 StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
\r
202 String[] dbs = new String[en.countTokens()];
\r
203 for (int i=0; i<dbs.length; i++)
\r
205 dbs[i++] = en.nextToken().trim();
\r
207 dbParamsForEndpoint.put(WsURL, dbs);
\r
210 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
\r
211 final AlignFrame af)
\r
213 // look for existing database service submenus on wsmenu
\r
214 Hashtable dbsrchs = new Hashtable();
\r
215 Vector newdbsrch = new Vector();
\r
216 Component entries[] = wsmenu.getComponents();
\r
217 for (int i = 0; entries!=null && i<entries.length; i++)
\r
219 if (entries[i] instanceof JMenu)
\r
221 dbsrchs.put(entries[i].getName(), entries[i]);
\r
224 JMenu defmenu=(JMenu) dbsrchs.get("Default Database");
\r
227 dbsrchs.put("Default Database", defmenu = new JMenu("Default Database"));
\r
228 newdbsrch.addElement(defmenu);
\r
231 String dbs[] = null;
\r
233 dbs = new jalview.ws.SeqSearchWSClient(sh).getSupportedDatabases();
\r
234 } catch (Exception e)
\r
236 jalview.bin.Cache.log.warn("Database list request failed, so disabling SeqSearch Service client "+sh.getName()+" at "+sh.getEndpointURL(), e);
\r
240 // do default entry
\r
241 defmenu.add(method = new JMenuItem(sh.getName()));
\r
242 method.setToolTipText(sh.getEndpointURL());
\r
243 method.addActionListener(new ActionListener()
\r
245 public void actionPerformed(ActionEvent e)
\r
247 // use same input gatherer as for secondary structure prediction
\r
248 // we could actually parameterise the gatherer method here...
\r
249 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
\r
250 new jalview.ws.SeqSearchWSClient(sh, af.getTitle(), msa, null,
\r
251 af.getViewport().getAlignment().getDataset(),
\r
256 // add entry for each database the service supports
\r
257 for (int db=0; dbs!=null && db<dbs.length; db++)
\r
259 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
\r
262 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
\r
263 newdbsrch.addElement(dbmenu);
\r
265 // add the client handler code for this service
\r
266 dbmenu.add(method = new JMenuItem(sh.getName()));
\r
267 method.setToolTipText(sh.getEndpointURL());
\r
268 final String searchdb = dbs[db];
\r
269 method.addActionListener(new ActionListener()
\r
271 public void actionPerformed(ActionEvent e)
\r
273 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
\r
274 new jalview.ws.SeqSearchWSClient(sh, af.getTitle(), msa, searchdb,
\r
275 af.getViewport().getAlignment().getDataset(),
\r
280 // add the databases onto the seqsearch menu
\r
281 Enumeration e = newdbsrch.elements();
\r
282 while (e.hasMoreElements())
\r
284 Object el = e.nextElement();
\r
285 if (el instanceof JMenu)
\r
287 wsmenu.add((JMenu) el);
\r
289 wsmenu.add((JMenuItem) el);
\r