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.api.JalviewServiceEndpointProviderI;
27 import jalview.ws.api.ServiceWithParameters;
28 import jalview.ws.jws2.JabaParamStore;
29 import jalview.ws.jws2.MsaWSClient;
30 import jalview.ws.jws2.SequenceAnnotationWSClient;
31 import jalview.ws.params.ParamDatastoreI;
32 import jalview.ws.params.ParamManager;
34 import java.io.Closeable;
37 import javax.swing.JMenu;
39 import compbio.data.msa.JABAService;
40 import compbio.data.msa.MsaWS;
41 import compbio.data.msa.SequenceAnnotation;
42 import compbio.metadata.PresetManager;
43 import compbio.metadata.RunnerConfig;
45 public class Jws2Instance extends ServiceWithParameters
46 implements JalviewServiceEndpointProviderI, AutoCloseable
49 public JABAService service;
56 * Category for this service's analysis
58 * text describing their action that service performs (eg 'aligning',
61 * Description from JABAWS registry
63 * JABAWS registry ID for service
65 public Jws2Instance(String hosturl, String serviceType, String action,
66 String description, JABAService service)
68 super(action, action, serviceType, description, hosturl);
69 this.service = service;
70 int p = description.indexOf("MORE INFORMATION:");
73 String docUrl = description.substring(description.indexOf("http", p))
75 if (docUrl.indexOf('\n') > -1)
77 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
79 if (docUrl.length() > 0)
83 URL url = new URL(docUrl);
86 setDocumentationUrl(docUrl);
97 PresetManager presets = null;
99 public JabaParamStore paramStore = null;
102 * non thread safe - gets the presets for this service (blocks whilst it calls
103 * the service to get the preset set)
105 * @return service presets or null if exceptions were raised.
107 public PresetManager getPresets()
113 if (service instanceof MsaWS<?>)
115 presets = ((MsaWS) service).getPresets();
118 if (service instanceof SequenceAnnotation<?>)
120 presets = ((SequenceAnnotation) service).getPresets();
122 } catch (Exception ex)
124 System.err.println("Exception when retrieving presets for service "
125 + getServiceType() + " at " + getHostURL());
132 * non-thread safe - blocks whilst accessing service to get complete set of
133 * available options and parameters
137 public RunnerConfig getRunnerConfig()
139 if (service instanceof MsaWS<?>)
141 return ((MsaWS) service).getRunnerOptions();
143 if (service instanceof SequenceAnnotation<?>)
145 return ((SequenceAnnotation) service).getRunnerOptions();
147 throw new Error(MessageManager.formatMessage(
148 "error.implementation_error_runner_config_not_available",
150 { getServiceType(), service.getClass().toString() }));
160 ((Closeable) service).close();
161 } catch (Throwable t)
170 public ParamDatastoreI getParamStore()
172 if (paramStore == null)
176 paramStore = new JabaParamStore(this,
177 (Desktop.instance != null ? Desktop.getUserParameterStore()
179 } catch (Exception ex)
181 System.err.println("Unexpected exception creating JabaParamStore.");
182 ex.printStackTrace();
189 public String getUri()
191 // TODO verify that service parameter sets in projects are consistent with
193 // this is only valid for Jaba 1.0 - this formula might have to change!
195 + (getHostURL().lastIndexOf("/") == (getHostURL().length() - 1)
201 private boolean hasParams = false, lookedForParams = false;
204 public boolean hasParameters()
206 if (!lookedForParams)
208 lookedForParams = true;
211 hasParams = (getRunnerConfig().getArguments().size() > 0);
212 } catch (Exception e)
220 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
222 if (service instanceof MsaWS<?>)
224 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
226 else if (service instanceof SequenceAnnotation<?>)
228 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
233 public String getNameURI()
235 return "java:" + getName();
238 jalview.ws.uimodel.AlignAnalysisUIText aaui;
240 public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()
246 * initialise a parameter store for this service
248 * @param userParameterStore
249 * - the user ParamManager (e.g. Desktop.getUserParameterStore() )
252 public void initParamStore(ParamManager userParameterStore)
254 if (paramStore == null)
256 paramStore = new JabaParamStore(this, userParameterStore);
261 * an object that implements one or more interfaces in jalview.ws.api
266 public Object getEndpoint()
272 if (service instanceof MsaWS<?>)
274 return new JabawsMsaInstance(this);
277 // service is for sequence analysis