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.bin.Cache;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.AlignmentView;
26 import jalview.gui.AlignFrame;
27 import jalview.gui.Desktop;
28 import jalview.gui.JvOptionPane;
29 import jalview.gui.WebserviceInfo;
30 import jalview.util.MessageManager;
32 import java.awt.Component;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.util.Enumeration;
36 import java.util.Hashtable;
37 import java.util.StringTokenizer;
38 import java.util.Vector;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuItem;
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 AlignmentI 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 JvOptionPane.showMessageDialog(Desktop.desktop,
89 MessageManager.formatMessage(
90 "label.service_called_is_not_seq_search_service",
93 MessageManager.getString("label.internal_jalview_error"),
94 JvOptionPane.WARNING_MESSAGE);
99 if ((wsInfo = setWebService(sh)) == null)
101 JvOptionPane.showMessageDialog(Desktop.desktop,
102 MessageManager.formatMessage(
103 "label.seq_search_service_is_unknown", new String[]
105 MessageManager.getString("label.internal_jalview_error"),
106 JvOptionPane.WARNING_MESSAGE);
110 startSeqSearchClient(altitle, msa, db, seqdataset);
115 * non-process web service interaction - use this for calling HEADLESS
116 * synchronous service methods
120 public SeqSearchWSClient(ServiceHandle sh)
122 setWebService(sh, true);
125 public SeqSearchWSClient()
129 // add a class reference to the list
132 private void startSeqSearchClient(String altitle, AlignmentView msa,
133 String db, AlignmentI seqdataset)
135 if (!locateWebService())
139 String visdb = (db == null || db == "") ? "default" : db; // need a visible
142 boolean profileSearch = msa.getSequences().length > 2 ? true : false;
143 // single sequence or profile from alignment view
144 wsInfo.setProgressText("Searching " + visdb
147 + msa.getSequences()[0].getRefSeq().getName()
149 + " from " + altitle + "\nJob details\n");
151 String jobtitle = WebServiceName
152 + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
156 + msa.getSequences()[0].getRefSeq().getName()
158 + " from " + altitle;
159 SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,
160 wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,
162 wsInfo.setthisService(ssthread);
167 * Initializes the server field with a valid service implementation.
169 * @return true if service was located.
171 private boolean locateWebService()
173 // this can be abstracted using reflection
174 // TODO: MuscleWS transmuted to generic MsaWS client
175 SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
179 this.server = loc.getSeqSearchService(new java.net.URL(WsURL));
180 ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One
183 } catch (Exception ex)
185 wsInfo.setProgressText("Serious! " + WebServiceName
186 + " Service location failed\nfor URL :" + WsURL + "\n"
188 wsInfo.setStatus(WebserviceInfo.ERROR);
189 ex.printStackTrace();
194 loc.getEngine().setOption("axis", "1");
199 protected String getServiceActionKey()
204 protected String getServiceActionDescription()
206 return "Sequence Database Search";
209 // simple caching of db parameters for each service endpoint
210 private static Hashtable dbParamsForEndpoint;
213 dbParamsForEndpoint = new Hashtable();
216 public String[] getSupportedDatabases() throws Exception
219 // check that we haven't already been to this service endpoint
220 if (dbParamsForEndpoint.containsKey(WsURL))
222 return (String[]) dbParamsForEndpoint.get(WsURL);
224 if (!locateWebService())
226 throw new Exception(MessageManager.formatMessage(
227 "exception.cannot_contact_service_endpoint_at", new String[]
230 String database = server.getDatabase();
231 if (database == null)
233 dbParamsForEndpoint.put(WsURL, new String[] {});
236 StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
237 String[] dbs = new String[en.countTokens()];
238 for (int i = 0; i < dbs.length; i++)
240 dbs[i++] = en.nextToken().trim();
242 dbParamsForEndpoint.put(WsURL, dbs);
247 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
250 // look for existing database service submenus on wsmenu
251 Hashtable dbsrchs = new Hashtable();
252 Vector newdbsrch = new Vector();
253 Component entries[] = wsmenu.getComponents();
254 for (int i = 0; entries != null && i < entries.length; i++)
256 if (entries[i] instanceof JMenu)
258 dbsrchs.put(entries[i].getName(), entries[i]);
261 JMenu defmenu = (JMenu) dbsrchs.get("Default Database");
264 dbsrchs.put("Default Database",
265 defmenu = new JMenu("Default Database"));
266 newdbsrch.addElement(defmenu);
272 dbs = new jalview.ws.jws1.SeqSearchWSClient(sh)
273 .getSupportedDatabases();
274 } catch (Exception e)
277 "Database list request failed, so disabling SeqSearch Service client "
278 + sh.getName() + " at " + sh.getEndpointURL(),
284 defmenu.add(method = new JMenuItem(sh.getName()));
285 method.setToolTipText(sh.getEndpointURL());
286 method.addActionListener(new ActionListener()
289 public void actionPerformed(ActionEvent e)
291 // use same input gatherer as for secondary structure prediction
292 // we could actually parameterise the gatherer method here...
293 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
294 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null,
295 af.getViewport().getAlignment().getDataset(), af);
298 // add entry for each database the service supports
299 for (int db = 0; dbs != null && db < dbs.length; db++)
301 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
304 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
305 newdbsrch.addElement(dbmenu);
307 // add the client handler code for this service
308 dbmenu.add(method = new JMenuItem(sh.getName()));
309 method.setToolTipText(sh.getEndpointURL());
310 final String searchdb = dbs[db];
311 method.addActionListener(new ActionListener()
314 public void actionPerformed(ActionEvent e)
316 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
317 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
318 searchdb, af.getViewport().getAlignment().getDataset(),
323 // add the databases onto the seqsearch menu
324 Enumeration e = newdbsrch.elements();
325 while (e.hasMoreElements())
327 Object el = e.nextElement();
328 if (el instanceof JMenu)
330 wsmenu.add((JMenu) el);
334 wsmenu.add((JMenuItem) el);