2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.ws.jws1;
21 import java.awt.Component;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.util.Enumeration;
25 import java.util.Hashtable;
26 import java.util.StringTokenizer;
27 import java.util.Vector;
32 import jalview.datamodel.*;
41 public class SeqSearchWSClient extends WS1Client
44 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
46 ext.vamsas.SeqSearchI server;
48 AlignFrame alignFrame;
51 * Creates a new MsaWSClient object that uses a service given by an externally
52 * retrieved ServiceHandle
55 * service handle of type AbstractName(MsaWS)
62 * @param preserveOrder
66 public SeqSearchWSClient(ext.vamsas.ServiceHandle sh, String altitle,
67 jalview.datamodel.AlignmentView msa, String db,
68 Alignment seqdataset, AlignFrame _alignFrame)
71 alignFrame = _alignFrame;
72 // can generalise the two errors below for metadata mapping from interface
73 // name to service client name
74 if (!sh.getAbstractName().equals(this.getServiceActionKey()))
76 JOptionPane.showMessageDialog(Desktop.desktop,
77 "The Service called \n" + sh.getName()
78 + "\nis not a \nSequence Search Service !",
79 "Internal Jalview Error", JOptionPane.WARNING_MESSAGE);
84 if ((wsInfo = setWebService(sh)) == null)
86 JOptionPane.showMessageDialog(Desktop.desktop,
87 "The Sequence Search Service named " + sh.getName()
88 + " is unknown", "Internal Jalview Error",
89 JOptionPane.WARNING_MESSAGE);
93 startSeqSearchClient(altitle, msa, db, seqdataset);
98 * non-process web service interaction - use this for calling HEADLESS
99 * synchronous service methods
103 public SeqSearchWSClient(ServiceHandle sh)
105 setWebService(sh, true);
108 public SeqSearchWSClient()
112 // add a class reference to the list
115 private void startSeqSearchClient(String altitle, AlignmentView msa,
116 String db, Alignment seqdataset)
118 if (!locateWebService())
122 String visdb = (db == null || db == "") ? "default" : db; // need a visible
125 boolean profileSearch = msa.getSequences().length > 2 ? true : false;
126 // single sequence or profile from alignment view
127 wsInfo.setProgressText("Searching "
129 + (!profileSearch ? " with sequence "
130 + msa.getSequences()[0].getRefSeq().getName()
131 : " with profile") + " from " + altitle
132 + "\nJob details\n");
134 String jobtitle = WebServiceName
135 + ((WebServiceName.indexOf("earch") > -1) ? " " : " search ")
138 + (!profileSearch ? " with sequence "
139 + msa.getSequences()[0].getRefSeq().getName()
140 : " with profile") + " from " + altitle;
141 SeqSearchWSThread ssthread = new SeqSearchWSThread(server, WsURL,
142 wsInfo, alignFrame, WebServiceName, jobtitle, msa, db,
144 wsInfo.setthisService(ssthread);
149 * Initializes the server field with a valid service implementation.
151 * @return true if service was located.
153 private boolean locateWebService()
155 // this can be abstracted using reflection
156 // TODO: MuscleWS transmuted to generic MsaWS client
157 SeqSearchServiceLocator loc = new SeqSearchServiceLocator(); // Default
161 this.server = (SeqSearchI) loc.getSeqSearchService(new java.net.URL(
163 ((SeqSearchServiceSoapBindingStub) this.server).setTimeout(60000); // One
166 } catch (Exception ex)
168 wsInfo.setProgressText("Serious! " + WebServiceName
169 + " Service location failed\nfor URL :" + WsURL + "\n"
171 wsInfo.setStatus(WebserviceInfo.ERROR);
172 ex.printStackTrace();
177 loc.getEngine().setOption("axis", "1");
182 protected String getServiceActionKey()
187 protected String getServiceActionDescription()
189 return "Sequence Database Search";
192 // simple caching of db parameters for each service endpoint
193 private static Hashtable dbParamsForEndpoint;
196 dbParamsForEndpoint = new Hashtable();
199 public String[] getSupportedDatabases() throws Exception
202 // check that we haven't already been to this service endpoint
203 if (dbParamsForEndpoint.containsKey(WsURL))
205 return (String[]) dbParamsForEndpoint.get(WsURL);
207 if (!locateWebService())
209 throw new Exception("Cannot contact service endpoint at " + WsURL);
211 String database = server.getDatabase();
212 if (database == null)
214 dbParamsForEndpoint.put(WsURL, new String[]
218 StringTokenizer en = new StringTokenizer(database.trim(), ",| ");
219 String[] dbs = new String[en.countTokens()];
220 for (int i = 0; i < dbs.length; i++)
222 dbs[i++] = en.nextToken().trim();
224 dbParamsForEndpoint.put(WsURL, dbs);
228 public void attachWSMenuEntry(JMenu wsmenu, final ServiceHandle sh,
231 // look for existing database service submenus on wsmenu
232 Hashtable dbsrchs = new Hashtable();
233 Vector newdbsrch = new Vector();
234 Component entries[] = wsmenu.getComponents();
235 for (int i = 0; entries != null && i < entries.length; i++)
237 if (entries[i] instanceof JMenu)
239 dbsrchs.put(entries[i].getName(), entries[i]);
242 JMenu defmenu = (JMenu) dbsrchs.get("Default Database");
245 dbsrchs.put("Default Database", defmenu = new JMenu(
246 "Default Database"));
247 newdbsrch.addElement(defmenu);
253 dbs = new jalview.ws.jws1.SeqSearchWSClient(sh)
254 .getSupportedDatabases();
255 } catch (Exception e)
257 jalview.bin.Cache.log.warn(
258 "Database list request failed, so disabling SeqSearch Service client "
259 + sh.getName() + " at " + sh.getEndpointURL(), e);
264 defmenu.add(method = new JMenuItem(sh.getName()));
265 method.setToolTipText(sh.getEndpointURL());
266 method.addActionListener(new ActionListener()
268 public void actionPerformed(ActionEvent e)
270 // use same input gatherer as for secondary structure prediction
271 // we could actually parameterise the gatherer method here...
272 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
273 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa, null,
274 af.getViewport().getAlignment().getDataset(), af);
277 // add entry for each database the service supports
278 for (int db = 0; dbs != null && db < dbs.length; db++)
280 JMenu dbmenu = (JMenu) dbsrchs.get(dbs[db]);
283 dbsrchs.put(dbs[db], dbmenu = new JMenu(dbs[db]));
284 newdbsrch.addElement(dbmenu);
286 // add the client handler code for this service
287 dbmenu.add(method = new JMenuItem(sh.getName()));
288 method.setToolTipText(sh.getEndpointURL());
289 final String searchdb = dbs[db];
290 method.addActionListener(new ActionListener()
292 public void actionPerformed(ActionEvent e)
294 AlignmentView msa = af.gatherSeqOrMsaForSecStrPrediction();
295 new jalview.ws.jws1.SeqSearchWSClient(sh, af.getTitle(), msa,
296 searchdb, af.getViewport().getAlignment().getDataset(),
301 // add the databases onto the seqsearch menu
302 Enumeration e = newdbsrch.elements();
303 while (e.hasMoreElements())
305 Object el = e.nextElement();
306 if (el instanceof JMenu)
308 wsmenu.add((JMenu) el);
312 wsmenu.add((JMenuItem) el);