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.JvOptionPane;
28 import jalview.gui.WebserviceInfo;
29 import jalview.util.MessageManager;
31 import java.awt.Component;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.util.Enumeration;
35 import java.util.Hashtable;
36 import java.util.StringTokenizer;
37 import java.util.Vector;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuItem;
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;
60 * Creates a new MsaWSClient object that uses a service given by an externally
61 * retrieved ServiceHandle
64 * service handle of type AbstractName(MsaWS)
71 * @param preserveOrder
75 public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
76 jalview.datamodel.AlignmentView msa, String db,
77 AlignmentI seqdataset, AlignFrame _alignFrame)
80 alignFrame = _alignFrame;
81 // can generalise the two errors below for metadata mapping from interface
82 // name to service client name
83 if (!sh.getAbstractName().equals(this.getServiceActionKey()))
85 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
86 MessageManager.formatMessage(
87 "label.service_called_is_not_seq_search_service",
90 MessageManager.getString("label.internal_jalview_error"),
91 JvOptionPane.WARNING_MESSAGE);
96 if ((wsInfo = setWebService(sh)) == null)
98 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
99 MessageManager.formatMessage(
100 "label.seq_search_service_is_unknown", new String[]
102 MessageManager.getString("label.internal_jalview_error"),
103 JvOptionPane.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 " + visdb
144 + msa.getSequences()[0].getRefSeq().getName()
146 + " from " + altitle + "\nJob details\n");
148 String jobtitle = WebServiceName
149 + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
153 + msa.getSequences()[0].getRefSeq().getName()
155 + " 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 = loc.getSeqSearchService(new java.net.URL(WsURL));
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", new String[]
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",
262 defmenu = new JMenu("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(),
281 defmenu.add(method = new JMenuItem(sh.getName()));
282 method.setToolTipText(sh.getEndpointURL());
283 method.addActionListener(new ActionListener()
286 public void actionPerformed(ActionEvent e)
288 // use same input gatherer as for secondary structure prediction
289 // we could actually parameterise the gatherer method here...
290 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
291 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null,
292 af.getViewport().getAlignment().getDataset(), af);
295 // add entry for each database the service supports
296 for (int db = 0; dbs != null && db < dbs.length; db++)
298 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
301 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
302 newdbsrch.addElement(dbmenu);
304 // add the client handler code for this service
305 dbmenu.add(method = new JMenuItem(sh.getName()));
306 method.setToolTipText(sh.getEndpointURL());
307 final String searchdb = dbs[db];
308 method.addActionListener(new ActionListener()
311 public void actionPerformed(ActionEvent e)
313 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
314 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
315 searchdb, af.getViewport().getAlignment().getDataset(),
320 // add the databases onto the seqsearch menu
321 Enumeration e = newdbsrch.elements();
322 while (e.hasMoreElements())
324 Object el = e.nextElement();
325 if (el instanceof JMenu)
327 wsmenu.add((JMenu) el);
331 wsmenu.add((JMenuItem) el);