2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 jalview.datamodel.AlignmentI;
24 import jalview.datamodel.AlignmentView;
25 import jalview.gui.AlignFrame;
26 import jalview.gui.Desktop;
27 import jalview.gui.WebserviceInfo;
28 import jalview.util.MessageManager;
30 import java.awt.Component;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33 import java.util.Enumeration;
34 import java.util.Hashtable;
35 import java.util.StringTokenizer;
36 import java.util.Vector;
38 import javax.swing.JMenu;
39 import javax.swing.JMenuItem;
40 import javax.swing.JOptionPane;
42 import ext.vamsas.SeqSearchServiceLocator;
43 import ext.vamsas.SeqSearchServiceSoapBindingStub;
44 import ext.vamsas.ServiceHandle;
52 public class SeqSearchWSClient extends WS1Client
55 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
57 ext.vamsas.SeqSearchI server;
59 AlignFrame alignFrame;
62 * Creates a new MsaWSClient object that uses a service given by an externally
63 * retrieved ServiceHandle
66 * service handle of type AbstractName(MsaWS)
73 * @param preserveOrder
77 public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
78 jalview.datamodel.AlignmentView msa, String db,
79 AlignmentI seqdataset, AlignFrame _alignFrame)
82 alignFrame = _alignFrame;
83 // can generalise the two errors below for metadata mapping from interface
84 // name to service client name
85 if (!sh.getAbstractName().equals(this.getServiceActionKey()))
87 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
89 "label.service_called_is_not_seq_search_service",
90 new String[] { sh.getName() }), MessageManager
91 .getString("label.internal_jalview_error"),
92 JOptionPane.WARNING_MESSAGE);
97 if ((wsInfo = setWebService(sh)) == null)
99 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
100 .formatMessage("label.seq_search_service_is_unknown",
101 new String[] { sh.getName() }), MessageManager
102 .getString("label.internal_jalview_error"),
103 JOptionPane.WARNING_MESSAGE);
107 startSeqSearchClient(altitle, msa, db, seqdataset);
112 * non-process web service interaction - use this for calling HEADLESS
113 * synchronous service methods
117 public SeqSearchWSClient(ServiceHandle sh)
119 setWebService(sh, true);
122 public SeqSearchWSClient()
126 // add a class reference to the list
129 private void startSeqSearchClient(String altitle, AlignmentView msa,
130 String db, AlignmentI seqdataset)
132 if (!locateWebService())
136 String visdb = (db == null || db == "") ? "default" : db; // need a visible
139 boolean profileSearch = msa.getSequences().length > 2 ? true : false;
140 // single sequence or profile from alignment view
141 wsInfo.setProgressText("Searching "
143 + (!profileSearch ? " with sequence "
144 + msa.getSequences()[0].getRefSeq().getName()
145 : " with profile") + " from " + altitle
146 + "\nJob details\n");
148 String jobtitle = WebServiceName
149 + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
152 + (!profileSearch ? " with sequence "
153 + msa.getSequences()[0].getRefSeq().getName()
154 : " with profile") + " from " + altitle;
155 SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,
156 wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,
158 wsInfo.setthisService(ssthread);
163 * Initializes the server field with a valid service implementation.
165 * @return true if service was located.
167 private boolean locateWebService()
169 // this can be abstracted using reflection
170 // TODO: MuscleWS transmuted to generic MsaWS client
171 SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
175 this.server = loc.getSeqSearchService(new java.net.URL(
177 ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One
180 } catch (Exception ex)
182 wsInfo.setProgressText("Serious! " + WebServiceName
183 + " Service location failed\nfor URL :" + WsURL + "\n"
185 wsInfo.setStatus(WebserviceInfo.ERROR);
186 ex.printStackTrace();
191 loc.getEngine().setOption("axis", "1");
196 protected String getServiceActionKey()
201 protected String getServiceActionDescription()
203 return "Sequence Database Search";
206 // simple caching of db parameters for each service endpoint
207 private static Hashtable dbParamsForEndpoint;
210 dbParamsForEndpoint = new Hashtable();
213 public String[] getSupportedDatabases() throws Exception
216 // check that we haven't already been to this service endpoint
217 if (dbParamsForEndpoint.containsKey(WsURL))
219 return (String[]) dbParamsForEndpoint.get(WsURL);
221 if (!locateWebService())
223 throw new Exception(MessageManager.formatMessage(
224 "exception.cannot_contact_service_endpoint_at",
225 new String[] { WsURL }));
227 String database = server.getDatabase();
228 if (database == null)
230 dbParamsForEndpoint.put(WsURL, new String[] {});
233 StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
234 String[] dbs = new String[en.countTokens()];
235 for (int i = 0; i < dbs.length; i++)
237 dbs[i++] = en.nextToken().trim();
239 dbParamsForEndpoint.put(WsURL, dbs);
244 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
247 // look for existing database service submenus on wsmenu
248 Hashtable dbsrchs = new Hashtable();
249 Vector newdbsrch = new Vector();
250 Component entries[] = wsmenu.getComponents();
251 for (int i = 0; entries != null && i < entries.length; i++)
253 if (entries[i] instanceof JMenu)
255 dbsrchs.put(entries[i].getName(), entries[i]);
258 JMenu defmenu = (JMenu) dbsrchs.get("Default Database");
261 dbsrchs.put("Default Database", defmenu = new JMenu(
262 "Default Database"));
263 newdbsrch.addElement(defmenu);
269 dbs = new jalview.ws.jws1.SeqSearchWSClient(sh)
270 .getSupportedDatabases();
271 } catch (Exception e)
273 jalview.bin.Cache.log.warn(
274 "Database list request failed, so disabling SeqSearch Service client "
275 + sh.getName() + " at " + sh.getEndpointURL(), e);
280 defmenu.add(method = new JMenuItem(sh.getName()));
281 method.setToolTipText(sh.getEndpointURL());
282 method.addActionListener(new ActionListener()
285 public void actionPerformed(ActionEvent e)
287 // use same input gatherer as for secondary structure prediction
288 // we could actually parameterise the gatherer method here...
289 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
290 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null,
291 af.getViewport().getAlignment().getDataset(), af);
294 // add entry for each database the service supports
295 for (int db = 0; dbs != null && db < dbs.length; db++)
297 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
300 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
301 newdbsrch.addElement(dbmenu);
303 // add the client handler code for this service
304 dbmenu.add(method = new JMenuItem(sh.getName()));
305 method.setToolTipText(sh.getEndpointURL());
306 final String searchdb = dbs[db];
307 method.addActionListener(new ActionListener()
310 public void actionPerformed(ActionEvent e)
312 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
313 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
314 searchdb, af.getViewport().getAlignment().getDataset(),
319 // add the databases onto the seqsearch menu
320 Enumeration e = newdbsrch.elements();
321 while (e.hasMoreElements())
323 Object el = e.nextElement();
324 if (el instanceof JMenu)
326 wsmenu.add((JMenu) el);
330 wsmenu.add((JMenuItem) el);