2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ws.jws1;
20 import java.awt.Component;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.util.Enumeration;
24 import java.util.Hashtable;
25 import java.util.StringTokenizer;
26 import java.util.Vector;
31 import jalview.datamodel.*;
40 public class SeqSearchWSClient extends WS1Client
43 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
45 ext.vamsas.SeqSearchI server;
47 AlignFrame alignFrame;
50 * Creates a new MsaWSClient object that uses a service given by an externally
51 * retrieved ServiceHandle
54 * service handle of type AbstractName(MsaWS)
61 * @param preserveOrder
65 public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
66 jalview.datamodel.AlignmentView msa, String db,
67 Alignment seqdataset, AlignFrame _alignFrame)
70 alignFrame = _alignFrame;
71 // can generalise the two errors below for metadata mapping from interface
72 // name to service client name
73 if (!sh.getAbstractName().equals(this.getServiceActionKey()))
75 JOptionPane.showMessageDialog(Desktop.desktop,
76 "The Service called \n" + sh.getName()
77 + "\nis not a \nSequence Search Service !",
78 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
83 if ((wsInfo = setWebService(sh)) == null)
85 JOptionPane.showMessageDialog(Desktop.desktop,
86 "The Sequence Search Service named " + sh.getName()
87 + " is unknown", "Internal Jalview Error",
88 JOptionPane.WARNING_MESSAGE);
92 startSeqSearchClient(altitle, msa, db, seqdataset);
97 * non-process web service interaction - use this for calling HEADLESS
98 * synchronous service methods
102 public SeqSearchWSClient(ServiceHandle sh)
104 setWebService(sh, true);
107 public SeqSearchWSClient()
111 // add a class reference to the list
114 private void startSeqSearchClient(String altitle, AlignmentView msa,
115 String db, Alignment seqdataset)
117 if (!locateWebService())
121 String visdb = (db == null || db == "") ? "default" : db; // need a visible
124 boolean profileSearch = msa.getSequences().length > 2 ? true : false;
125 // single sequence or profile from alignment view
126 wsInfo.setProgressText("Searching "
128 + (!profileSearch ? " with sequence "
129 + msa.getSequences()[0].getRefSeq().getName()
130 : " with profile") + " from " + altitle
131 + "\nJob details\n");
133 String jobtitle = WebServiceName
134 + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
137 + (!profileSearch ? " with sequence "
138 + msa.getSequences()[0].getRefSeq().getName()
139 : " with profile") + " from " + altitle;
140 SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,
141 wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,
143 wsInfo.setthisService(ssthread);
148 * Initializes the server field with a valid service implementation.
150 * @return true if service was located.
152 private boolean locateWebService()
154 // this can be abstracted using reflection
155 // TODO: MuscleWS transmuted to generic MsaWS client
156 SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
160 this.server = (SeqSearchI) loc.getSeqSearchService(new java.net.URL(
162 ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One
165 } catch (Exception ex)
167 wsInfo.setProgressText("Serious! " + WebServiceName
168 + " Service location failed\nfor URL :" + WsURL + "\n"
170 wsInfo.setStatus(WebserviceInfo.ERROR);
171 ex.printStackTrace();
176 loc.getEngine().setOption("axis", "1");
181 protected String getServiceActionKey()
186 protected String getServiceActionDescription()
188 return "Sequence Database Search";
191 // simple caching of db parameters for each service endpoint
192 private static Hashtable dbParamsForEndpoint;
195 dbParamsForEndpoint = new Hashtable();
198 public String[] getSupportedDatabases() throws Exception
201 // check that we haven't already been to this service endpoint
202 if (dbParamsForEndpoint.containsKey(WsURL))
204 return (String[]) dbParamsForEndpoint.get(WsURL);
206 if (!locateWebService())
208 throw new Exception("Cannot contact service endpoint at " + WsURL);
210 String database = server.getDatabase();
211 if (database == null)
213 dbParamsForEndpoint.put(WsURL, new String[]
217 StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
218 String[] dbs = new String[en.countTokens()];
219 for (int i = 0; i < dbs.length; i++)
221 dbs[i++] = en.nextToken().trim();
223 dbParamsForEndpoint.put(WsURL, dbs);
227 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
230 // look for existing database service submenus on wsmenu
231 Hashtable dbsrchs = new Hashtable();
232 Vector newdbsrch = new Vector();
233 Component entries[] = wsmenu.getComponents();
234 for (int i = 0; entries != null && i < entries.length; i++)
236 if (entries[i] instanceof JMenu)
238 dbsrchs.put(entries[i].getName(), entries[i]);
241 JMenu defmenu = (JMenu) dbsrchs.get("Default Database");
244 dbsrchs.put("Default Database", defmenu = new JMenu(
245 "Default Database"));
246 newdbsrch.addElement(defmenu);
252 dbs = new jalview.ws.jws1.SeqSearchWSClient(sh)
253 .getSupportedDatabases();
254 } catch (Exception e)
256 jalview.bin.Cache.log.warn(
257 "Database list request failed, so disabling SeqSearch Service client "
258 + sh.getName() + " at " + sh.getEndpointURL(), e);
263 defmenu.add(method = new JMenuItem(sh.getName()));
264 method.setToolTipText(sh.getEndpointURL());
265 method.addActionListener(new ActionListener()
267 public void actionPerformed(ActionEvent e)
269 // use same input gatherer as for secondary structure prediction
270 // we could actually parameterise the gatherer method here...
271 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
272 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null,
273 af.getViewport().getAlignment().getDataset(), af);
276 // add entry for each database the service supports
277 for (int db = 0; dbs != null && db < dbs.length; db++)
279 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
282 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
283 newdbsrch.addElement(dbmenu);
285 // add the client handler code for this service
286 dbmenu.add(method = new JMenuItem(sh.getName()));
287 method.setToolTipText(sh.getEndpointURL());
288 final String searchdb = dbs[db];
289 method.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent e)
293 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
294 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
295 searchdb, af.getViewport().getAlignment().getDataset(),
300 // add the databases onto the seqsearch menu
301 Enumeration e = newdbsrch.elements();
302 while (e.hasMoreElements())
304 Object el = e.nextElement();
305 if (el instanceof JMenu)
307 wsmenu.add((JMenu) el);
311 wsmenu.add((JMenuItem) el);