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.jws2.jabaws2;
23 import jalview.gui.AlignFrame;
24 import jalview.gui.Desktop;
25 import jalview.util.MessageManager;
26 import jalview.ws.jws2.JabaParamStore;
27 import jalview.ws.jws2.MsaWSClient;
28 import jalview.ws.jws2.SequenceAnnotationWSClient;
29 import jalview.ws.params.ParamDatastoreI;
31 import java.io.Closeable;
33 import javax.swing.JMenu;
35 import compbio.data.msa.JABAService;
36 import compbio.data.msa.MsaWS;
37 import compbio.data.msa.SequenceAnnotation;
38 import compbio.metadata.PresetManager;
39 import compbio.metadata.RunnerConfig;
41 public class Jws2Instance
43 public String hosturl;
45 public String serviceType;
49 public JABAService service;
51 public String description;
60 * Category for this service's analysis
62 * text describing their action that service performs (eg 'aligning',
65 * Description from JABAWS registry
67 * JABAWS registry ID for service
69 public Jws2Instance(String hosturl, String serviceType, String action,
70 String description, JABAService service)
73 this.hosturl = hosturl;
74 this.serviceType = serviceType;
75 this.service = service;
77 this.description = description;
78 int p = description.indexOf("MORE INFORMATION:");
81 docUrl = description.substring(description.indexOf("http", p)).trim();
82 if (docUrl.indexOf('\n') > -1)
84 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
90 PresetManager presets = null;
92 public JabaParamStore paramStore = null;
95 * non thread safe - gets the presets for this service (blocks whilst it calls
96 * the service to get the preset set)
98 * @return service presets or null if exceptions were raised.
100 public PresetManager getPresets()
106 if (service instanceof MsaWS<?>)
108 presets = ((MsaWS) service).getPresets();
111 if (service instanceof SequenceAnnotation<?>)
113 presets = ((SequenceAnnotation) service).getPresets();
115 } catch (Exception ex)
117 System.err.println("Exception when retrieving presets for service "
118 + serviceType + " at " + hosturl);
124 public String getHost()
128 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
129 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
130 * serviceurl.getHost(); } catch (Exception e) {
131 * System.err.println("Failed to parse service URL '" + hosturl +
132 * "' as a valid URL!"); } return null;
137 * @return short description of what the service will do
139 public String getActionText()
141 return action + " with " + serviceType;
145 * non-thread safe - blocks whilst accessing service to get complete set of
146 * available options and parameters
150 public RunnerConfig getRunnerConfig()
152 if (service instanceof MsaWS<?>)
154 return ((MsaWS) service).getRunnerOptions();
156 if (service instanceof SequenceAnnotation<?>)
158 return ((SequenceAnnotation) service).getRunnerOptions();
160 throw new Error(MessageManager.formatMessage(
161 "error.implementation_error_runner_config_not_available",
162 new String[] { serviceType, service.getClass().toString() }));
166 protected void finalize() throws Throwable
172 Closeable svc = (Closeable) service;
175 } catch (Exception e)
183 public ParamDatastoreI getParamStore()
185 if (paramStore == null)
189 paramStore = new JabaParamStore(this,
190 (Desktop.instance != null ? Desktop.getUserParameterStore()
192 } catch (Exception ex)
194 System.err.println("Unexpected exception creating JabaParamStore.");
195 ex.printStackTrace();
202 public String getUri()
204 // this is only valid for Jaba 1.0 - this formula might have to change!
206 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
207 : "/") + serviceType;
210 private boolean hasParams = false, lookedForParams = false;
212 public boolean hasParameters()
214 if (!lookedForParams)
216 lookedForParams = true;
219 hasParams = (getRunnerConfig().getArguments().size() > 0);
220 } catch (Exception e)
228 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
230 if (service instanceof MsaWS<?>)
232 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
234 else if (service instanceof SequenceAnnotation<?>)
236 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
241 public String getServiceTypeURI()
243 return "java:" + serviceType;
246 jalview.ws.uimodel.AlignAnalysisUIText aaui;
248 public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()