2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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.ws.jws2.JabaParamStore;
26 import jalview.ws.jws2.MsaWSClient;
27 import jalview.ws.jws2.SequenceAnnotationWSClient;
28 import jalview.ws.params.ParamDatastoreI;
30 import java.io.Closeable;
32 import javax.swing.JMenu;
34 import compbio.data.msa.JABAService;
35 import compbio.data.msa.MsaWS;
36 import compbio.data.msa.SequenceAnnotation;
37 import compbio.metadata.PresetManager;
38 import compbio.metadata.RunnerConfig;
40 public class Jws2Instance
42 public String hosturl;
44 public String serviceType;
48 public JABAService service;
50 public String description;
59 * Category for this service's analysis
61 * text describing their action that service performs (eg 'aligning',
64 * Description from JABAWS registry
66 * JABAWS registry ID for service
68 public Jws2Instance(String hosturl, String serviceType, String action,
69 String description, JABAService service)
72 this.hosturl = hosturl;
73 this.serviceType = serviceType;
74 this.service = service;
76 this.description = description;
77 int p = description.indexOf("MORE INFORMATION:");
80 docUrl = description.substring(description.indexOf("http", p)).trim();
81 if (docUrl.indexOf('\n') > -1)
83 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
89 PresetManager presets = null;
91 public JabaParamStore paramStore = null;
94 * non thread safe - gets the presets for this service (blocks whilst it calls
95 * the service to get the preset set)
97 * @return service presets or null if exceptions were raised.
99 public PresetManager getPresets()
105 if (service instanceof MsaWS<?>)
107 presets = ((MsaWS) service).getPresets();
110 if (service instanceof SequenceAnnotation<?>)
112 presets = ((SequenceAnnotation) service).getPresets();
114 } catch (Exception ex)
116 System.err.println("Exception when retrieving presets for service "
117 + serviceType + " at " + hosturl);
123 public String getHost()
127 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
128 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
129 * serviceurl.getHost(); } catch (Exception e) {
130 * System.err.println("Failed to parse service URL '" + hosturl +
131 * "' as a valid URL!"); } return null;
136 * @return short description of what the service will do
138 public String getActionText()
140 return action + " with " + serviceType;
144 * non-thread safe - blocks whilst accessing service to get complete set of
145 * available options and parameters
149 public RunnerConfig getRunnerConfig()
151 if (service instanceof MsaWS<?>)
153 return ((MsaWS) service).getRunnerOptions();
155 if (service instanceof SequenceAnnotation<?>)
157 return ((SequenceAnnotation) service).getRunnerOptions();
160 "Implementation Error: Runner Config not available for a JABAWS service of type "
161 + serviceType + " (" + service.getClass() + ")");
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 jalview.ws.uimodel.AlignAnalysisUIText aaui;
247 public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()