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;
30 import jalview.ws.uimodel.AlignAnalysisUIText;
32 import java.io.Closeable;
34 import javax.swing.JMenu;
36 import compbio.data.msa.JABAService;
37 import compbio.data.msa.MsaWS;
38 import compbio.data.msa.SequenceAnnotation;
39 import compbio.metadata.PresetManager;
40 import compbio.metadata.RunnerConfig;
42 public class Jws2Instance
44 public String hosturl;
46 public String serviceType;
50 public JABAService service;
52 public String description;
61 * Category for this service's analysis
63 * text describing their action that service performs (eg 'aligning',
66 * Description from JABAWS registry
68 * JABAWS registry ID for service
70 public Jws2Instance(String hosturl, String serviceType, String action,
71 String description, JABAService service)
74 this.hosturl = hosturl;
75 this.serviceType = serviceType;
76 this.service = service;
78 this.description = description;
79 int p = description.indexOf("MORE INFORMATION:");
82 docUrl = description.substring(description.indexOf("http", p)).trim();
83 if (docUrl.indexOf('\n') > -1)
85 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
91 PresetManager presets = null;
93 public JabaParamStore paramStore = null;
96 * non thread safe - gets the presets for this service (blocks whilst it calls
97 * the service to get the preset set)
99 * @return service presets or null if exceptions were raised.
101 public PresetManager getPresets()
107 if (service instanceof MsaWS<?>)
109 presets = ((MsaWS) service).getPresets();
112 if (service instanceof SequenceAnnotation<?>)
114 presets = ((SequenceAnnotation) service).getPresets();
116 } catch (Exception ex)
118 System.err.println("Exception when retrieving presets for service "
119 + serviceType + " at " + hosturl);
125 public String getHost()
129 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
130 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
131 * serviceurl.getHost(); } catch (Exception e) {
132 * System.err.println("Failed to parse service URL '" + hosturl +
133 * "' as a valid URL!"); } return null;
138 * @return short description of what the service will do
140 public String getActionText()
142 return action + " with " + serviceType;
146 * non-thread safe - blocks whilst accessing service to get complete set of
147 * available options and parameters
151 public RunnerConfig getRunnerConfig()
153 if (service instanceof MsaWS<?>)
155 return ((MsaWS) service).getRunnerOptions();
157 if (service instanceof SequenceAnnotation<?>)
159 return ((SequenceAnnotation) service).getRunnerOptions();
161 throw new Error(MessageManager.formatMessage("error.implementation_error_runner_config_not_available", new String[]{serviceType,service.getClass().toString()}));
165 protected void finalize() throws Throwable
171 Closeable svc = (Closeable) service;
174 } catch (Exception e)
182 public ParamDatastoreI getParamStore()
184 if (paramStore == null)
188 paramStore = new JabaParamStore(this,
189 (Desktop.instance != null ? Desktop.getUserParameterStore()
191 } catch (Exception ex)
193 System.err.println("Unexpected exception creating JabaParamStore.");
194 ex.printStackTrace();
201 public String getUri()
203 // this is only valid for Jaba 1.0 - this formula might have to change!
205 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
206 : "/") + serviceType;
209 private boolean hasParams = false, lookedForParams = false;
211 public boolean hasParameters()
213 if (!lookedForParams)
215 lookedForParams = true;
218 hasParams = (getRunnerConfig().getArguments().size() > 0);
219 } catch (Exception e)
227 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
229 if (service instanceof MsaWS<?>)
231 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
233 else if (service instanceof SequenceAnnotation<?>)
235 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
240 public String getServiceTypeURI()
242 return "java:" + serviceType;
245 AlignAnalysisUIText aaui;
247 public AlignAnalysisUIText getAlignAnalysisUI()