2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.ws.jws2.jabaws2;
20 import jalview.gui.AlignFrame;
21 import jalview.gui.Desktop;
22 import jalview.ws.jws2.JabaParamStore;
23 import jalview.ws.jws2.MsaWSClient;
24 import jalview.ws.jws2.SequenceAnnotationWSClient;
25 import jalview.ws.params.ParamDatastoreI;
27 import java.io.Closeable;
29 import javax.swing.JMenu;
31 import compbio.data.msa.JABAService;
32 import compbio.data.msa.MsaWS;
33 import compbio.data.msa.SequenceAnnotation;
34 import compbio.metadata.PresetManager;
35 import compbio.metadata.RunnerConfig;
37 public class Jws2Instance
39 public String hosturl;
41 public String serviceType;
45 public JABAService service;
47 public String description;
51 public Jws2Instance(String hosturl, String serviceType, String action,
52 String description, JABAService service)
55 this.hosturl = hosturl;
56 this.serviceType = serviceType;
57 this.service = service;
59 this.description = description;
60 int p = description.indexOf("MORE INFORMATION:");
63 docUrl = description.substring(description.indexOf("http", p)).trim();
64 if (docUrl.indexOf('\n') > -1)
66 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
72 PresetManager presets = null;
74 public JabaParamStore paramStore = null;
77 * non thread safe - gets the presets for this service (blocks whilst it calls
78 * the service to get the preset set)
80 * @return service presets or null if exceptions were raised.
82 public PresetManager getPresets()
88 if (service instanceof MsaWS<?>)
90 presets = ((MsaWS) service).getPresets();
93 if (service instanceof SequenceAnnotation<?>)
95 presets = ((SequenceAnnotation) service).getPresets();
97 } catch (Exception ex)
99 System.err.println("Exception when retrieving presets for service "
100 + serviceType + " at " + hosturl);
106 public String getHost()
110 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
111 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
112 * serviceurl.getHost(); } catch (Exception e) {
113 * System.err.println("Failed to parse service URL '" + hosturl +
114 * "' as a valid URL!"); } return null;
119 * @return short description of what the service will do
121 public String getActionText()
123 return action + " with " + serviceType;
127 * non-thread safe - blocks whilst accessing service to get complete set of
128 * available options and parameters
132 public RunnerConfig getRunnerConfig()
134 if (service instanceof MsaWS<?>)
136 return ((MsaWS) service).getRunnerOptions();
138 if (service instanceof SequenceAnnotation<?>)
140 return ((SequenceAnnotation) service).getRunnerOptions();
143 "Implementation Error: Runner Config not available for a JABAWS service of type "
144 + serviceType + " (" + service.getClass() + ")");
148 protected void finalize() throws Throwable
154 Closeable svc = (Closeable) service;
157 } catch (Exception e)
165 public ParamDatastoreI getParamStore()
167 if (paramStore == null)
171 paramStore = new JabaParamStore(this,
172 (Desktop.instance != null ? Desktop.getUserParameterStore()
174 } catch (Exception ex)
176 System.err.println("Unexpected exception creating JabaParamStore.");
177 ex.printStackTrace();
184 public String getUri()
186 // this is only valid for Jaba 1.0 - this formula might have to change!
188 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
189 : "/") + serviceType;
192 private boolean hasParams = false, lookedForParams = false;
194 public boolean hasParameters()
196 if (!lookedForParams)
198 lookedForParams = true;
201 hasParams = (getRunnerConfig().getArguments().size() > 0);
202 } catch (Exception e)
210 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
212 if (service instanceof MsaWS<?>)
214 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
216 else if (service instanceof SequenceAnnotation<?>)
218 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
223 public String getServiceTypeURI()
225 return "java:" + serviceType;