2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws1;
23 import java.awt.Component;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.Enumeration;
27 import java.util.Hashtable;
28 import java.util.StringTokenizer;
29 import java.util.Vector;
34 import jalview.datamodel.*;
36 import jalview.util.MessageManager;
44 public class SeqSearchWSClient extends WS1Client
47 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
49 ext.vamsas.SeqSearchI server;
51 AlignFrame alignFrame;
54 * Creates a new MsaWSClient object that uses a service given by an externally
55 * retrieved ServiceHandle
58 * service handle of type AbstractName(MsaWS)
65 * @param preserveOrder
69 public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
70 jalview.datamodel.AlignmentView msa, String db,
71 Alignment seqdataset, AlignFrame _alignFrame)
74 alignFrame = _alignFrame;
75 // can generalise the two errors below for metadata mapping from interface
76 // name to service client name
77 if (!sh.getAbstractName().equals(this.getServiceActionKey()))
79 JOptionPane.showMessageDialog(Desktop.desktop,
80 MessageManager.formatMessage("label.service_called_is_not_seq_search_service", new String[]{sh.getName()}),
81 MessageManager.getString("label.internal_jalview_error"), JOptionPane.WARNING_MESSAGE);
86 if ((wsInfo = setWebService(sh)) == null)
88 JOptionPane.showMessageDialog(Desktop.desktop,
89 MessageManager.formatMessage("label.seq_search_service_is_unknown", new String[]{sh.getName()}),
90 MessageManager.getString("label.internal_jalview_error"),
91 JOptionPane.WARNING_MESSAGE);
95 startSeqSearchClient(altitle, msa, db, seqdataset);
100 * non-process web service interaction - use this for calling HEADLESS
101 * synchronous service methods
105 public SeqSearchWSClient(ServiceHandle sh)
107 setWebService(sh, true);
110 public SeqSearchWSClient()
114 // add a class reference to the list
117 private void startSeqSearchClient(String altitle, AlignmentView msa,
118 String db, Alignment seqdataset)
120 if (!locateWebService())
124 String visdb = (db == null || db == "") ? "default" : db; // need a visible
127 boolean profileSearch = msa.getSequences().length > 2 ? true : false;
128 // single sequence or profile from alignment view
129 wsInfo.setProgressText("Searching "
131 + (!profileSearch ? " with sequence "
132 + msa.getSequences()[0].getRefSeq().getName()
133 : " with profile") + " from " + altitle
134 + "\nJob details\n");
136 String jobtitle = WebServiceName
137 + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
140 + (!profileSearch ? " with sequence "
141 + msa.getSequences()[0].getRefSeq().getName()
142 : " with profile") + " from " + altitle;
143 SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,
144 wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,
146 wsInfo.setthisService(ssthread);
151 * Initializes the server field with a valid service implementation.
153 * @return true if service was located.
155 private boolean locateWebService()
157 // this can be abstracted using reflection
158 // TODO: MuscleWS transmuted to generic MsaWS client
159 SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
163 this.server = (SeqSearchI) loc.getSeqSearchService(new java.net.URL(
165 ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One
168 } catch (Exception ex)
170 wsInfo.setProgressText("Serious! " + WebServiceName
171 + " Service location failed\nfor URL :" + WsURL + "\n"
173 wsInfo.setStatus(WebserviceInfo.ERROR);
174 ex.printStackTrace();
179 loc.getEngine().setOption("axis", "1");
184 protected String getServiceActionKey()
189 protected String getServiceActionDescription()
191 return "Sequence Database Search";
194 // simple caching of db parameters for each service endpoint
195 private static Hashtable dbParamsForEndpoint;
198 dbParamsForEndpoint = new Hashtable();
201 public String[] getSupportedDatabases() throws Exception
204 // check that we haven't already been to this service endpoint
205 if (dbParamsForEndpoint.containsKey(WsURL))
207 return (String[]) dbParamsForEndpoint.get(WsURL);
209 if (!locateWebService())
211 throw new Exception(MessageManager.formatMessage("exception.cannot_contact_service_endpoint_at", new String[]{WsURL}));
213 String database = server.getDatabase();
214 if (database == null)
216 dbParamsForEndpoint.put(WsURL, new String[]
220 StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
221 String[] dbs = new String[en.countTokens()];
222 for (int i = 0; i < dbs.length; i++)
224 dbs[i++] = en.nextToken().trim();
226 dbParamsForEndpoint.put(WsURL, dbs);
230 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
233 // look for existing database service submenus on wsmenu
234 Hashtable dbsrchs = new Hashtable();
235 Vector newdbsrch = new Vector();
236 Component entries[] = wsmenu.getComponents();
237 for (int i = 0; entries != null && i < entries.length; i++)
239 if (entries[i] instanceof JMenu)
241 dbsrchs.put(entries[i].getName(), entries[i]);
244 JMenu defmenu = (JMenu) dbsrchs.get("Default Database");
247 dbsrchs.put("Default Database", defmenu = new JMenu(
248 "Default Database"));
249 newdbsrch.addElement(defmenu);
255 dbs = new jalview.ws.jws1.SeqSearchWSClient(sh)
256 .getSupportedDatabases();
257 } catch (Exception e)
259 jalview.bin.Cache.log.warn(
260 "Database list request failed, so disabling SeqSearch Service client "
261 + sh.getName() + " at " + sh.getEndpointURL(), e);
266 defmenu.add(method = new JMenuItem(sh.getName()));
267 method.setToolTipText(sh.getEndpointURL());
268 method.addActionListener(new ActionListener()
270 public void actionPerformed(ActionEvent e)
272 // use same input gatherer as for secondary structure prediction
273 // we could actually parameterise the gatherer method here...
274 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
275 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null,
276 af.getViewport().getAlignment().getDataset(), af);
279 // add entry for each database the service supports
280 for (int db = 0; dbs != null && db < dbs.length; db++)
282 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
285 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
286 newdbsrch.addElement(dbmenu);
288 // add the client handler code for this service
289 dbmenu.add(method = new JMenuItem(sh.getName()));
290 method.setToolTipText(sh.getEndpointURL());
291 final String searchdb = dbs[db];
292 method.addActionListener(new ActionListener()
294 public void actionPerformed(ActionEvent e)
296 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
297 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
298 searchdb, af.getViewport().getAlignment().getDataset(),
303 // add the databases onto the seqsearch menu
304 Enumeration e = newdbsrch.elements();
305 while (e.hasMoreElements())
307 Object el = e.nextElement();
308 if (el instanceof JMenu)
310 wsmenu.add((JMenu) el);
314 wsmenu.add((JMenuItem) el);