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.Alignment;
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.SeqSearchI;
43 import ext.vamsas.SeqSearchServiceLocator;
44 import ext.vamsas.SeqSearchServiceSoapBindingStub;
45 import ext.vamsas.ServiceHandle;
53 public class SeqSearchWSClient extends WS1Client
56 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
58 ext.vamsas.SeqSearchI server;
60 AlignFrame alignFrame;
63 * Creates a new MsaWSClient object that uses a service given by an externally
64 * retrieved ServiceHandle
67 * service handle of type AbstractName(MsaWS)
74 * @param preserveOrder
78 public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
79 jalview.datamodel.AlignmentView msa, String db,
80 Alignment seqdataset, AlignFrame _alignFrame)
83 alignFrame = _alignFrame;
84 // can generalise the two errors below for metadata mapping from interface
85 // name to service client name
86 if (!sh.getAbstractName().equals(this.getServiceActionKey()))
88 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
90 "label.service_called_is_not_seq_search_service",
91 new String[] { sh.getName() }), MessageManager
92 .getString("label.internal_jalview_error"),
93 JOptionPane.WARNING_MESSAGE);
98 if ((wsInfo = setWebService(sh)) == null)
100 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
101 .formatMessage("label.seq_search_service_is_unknown",
102 new String[] { sh.getName() }), MessageManager
103 .getString("label.internal_jalview_error"),
104 JOptionPane.WARNING_MESSAGE);
108 startSeqSearchClient(altitle, msa, db, seqdataset);
113 * non-process web service interaction - use this for calling HEADLESS
114 * synchronous service methods
118 public SeqSearchWSClient(ServiceHandle sh)
120 setWebService(sh, true);
123 public SeqSearchWSClient()
127 // add a class reference to the list
130 private void startSeqSearchClient(String altitle, AlignmentView msa,
131 String db, Alignment seqdataset)
133 if (!locateWebService())
137 String visdb = (db == null || db == "") ? "default" : db; // need a visible
140 boolean profileSearch = msa.getSequences().length > 2 ? true : false;
141 // single sequence or profile from alignment view
142 wsInfo.setProgressText("Searching "
144 + (!profileSearch ? " with sequence "
145 + msa.getSequences()[0].getRefSeq().getName()
146 : " with profile") + " from " + altitle
147 + "\nJob details\n");
149 String jobtitle = WebServiceName
150 + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
153 + (!profileSearch ? " with sequence "
154 + msa.getSequences()[0].getRefSeq().getName()
155 : " with profile") + " from " + altitle;
156 SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,
157 wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,
159 wsInfo.setthisService(ssthread);
164 * Initializes the server field with a valid service implementation.
166 * @return true if service was located.
168 private boolean locateWebService()
170 // this can be abstracted using reflection
171 // TODO: MuscleWS transmuted to generic MsaWS client
172 SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
176 this.server = (SeqSearchI) loc.getSeqSearchService(new java.net.URL(
178 ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One
181 } catch (Exception ex)
183 wsInfo.setProgressText("Serious! " + WebServiceName
184 + " Service location failed\nfor URL :" + WsURL + "\n"
186 wsInfo.setStatus(WebserviceInfo.ERROR);
187 ex.printStackTrace();
192 loc.getEngine().setOption("axis", "1");
197 protected String getServiceActionKey()
202 protected String getServiceActionDescription()
204 return "Sequence Database Search";
207 // simple caching of db parameters for each service endpoint
208 private static Hashtable dbParamsForEndpoint;
211 dbParamsForEndpoint = new Hashtable();
214 public String[] getSupportedDatabases() throws Exception
217 // check that we haven't already been to this service endpoint
218 if (dbParamsForEndpoint.containsKey(WsURL))
220 return (String[]) dbParamsForEndpoint.get(WsURL);
222 if (!locateWebService())
224 throw new Exception(MessageManager.formatMessage(
225 "exception.cannot_contact_service_endpoint_at",
226 new String[] { WsURL }));
228 String database = server.getDatabase();
229 if (database == null)
231 dbParamsForEndpoint.put(WsURL, new String[] {});
234 StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
235 String[] dbs = new String[en.countTokens()];
236 for (int i = 0; i < dbs.length; i++)
238 dbs[i++] = en.nextToken().trim();
240 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()
284 public void actionPerformed(ActionEvent e)
286 // use same input gatherer as for secondary structure prediction
287 // we could actually parameterise the gatherer method here...
288 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
289 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null,
290 af.getViewport().getAlignment().getDataset(), af);
293 // add entry for each database the service supports
294 for (int db = 0; dbs != null && db < dbs.length; db++)
296 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
299 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
300 newdbsrch.addElement(dbmenu);
302 // add the client handler code for this service
303 dbmenu.add(method = new JMenuItem(sh.getName()));
304 method.setToolTipText(sh.getEndpointURL());
305 final String searchdb = dbs[db];
306 method.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
311 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
312 searchdb, af.getViewport().getAlignment().getDataset(),
317 // add the databases onto the seqsearch menu
318 Enumeration e = newdbsrch.elements();
319 while (e.hasMoreElements())
321 Object el = e.nextElement();
322 if (el instanceof JMenu)
324 wsmenu.add((JMenu) el);
328 wsmenu.add((JMenuItem) el);