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.UIinfo;
27 import jalview.ws.jws2.JabaParamStore;
28 import jalview.ws.jws2.MsaWSClient;
29 import jalview.ws.jws2.SequenceAnnotationWSClient;
30 import jalview.ws.params.ParamDatastoreI;
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 extends UIinfo
44 public String hosturl;
46 public JABAService service;
55 * Category for this service's analysis
57 * text describing their action that service performs (eg 'aligning',
60 * Description from JABAWS registry
62 * JABAWS registry ID for service
64 public Jws2Instance(String hosturl, String serviceType, String action,
65 String description, JABAService service)
67 super(action, action, serviceType, description);
68 this.hosturl = hosturl;
69 this.service = service;
70 int p = description.indexOf("MORE INFORMATION:");
73 docUrl = description.substring(description.indexOf("http", p)).trim();
74 if (docUrl.indexOf('\n') > -1)
76 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
82 PresetManager presets = null;
84 public JabaParamStore paramStore = null;
87 * non thread safe - gets the presets for this service (blocks whilst it calls
88 * the service to get the preset set)
90 * @return service presets or null if exceptions were raised.
92 public PresetManager getPresets()
98 if (service instanceof MsaWS<?>)
100 presets = ((MsaWS) service).getPresets();
103 if (service instanceof SequenceAnnotation<?>)
105 presets = ((SequenceAnnotation) service).getPresets();
107 } catch (Exception ex)
109 System.err.println("Exception when retrieving presets for service "
110 + getServiceType() + " at " + hosturl);
116 public String getHost()
120 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
121 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
122 * serviceurl.getHost(); } catch (Exception e) {
123 * System.err.println("Failed to parse service URL '" + hosturl +
124 * "' as a valid URL!"); } return null;
129 * @return short description of what the service will do
131 public String getActionText()
133 return getAction() + " with " + getServiceType();
137 * non-thread safe - blocks whilst accessing service to get complete set of
138 * available options and parameters
142 public RunnerConfig getRunnerConfig()
144 if (service instanceof MsaWS<?>)
146 return ((MsaWS) service).getRunnerOptions();
148 if (service instanceof SequenceAnnotation<?>)
150 return ((SequenceAnnotation) service).getRunnerOptions();
152 throw new Error(MessageManager.formatMessage(
153 "error.implementation_error_runner_config_not_available",
155 { getServiceType(), service.getClass().toString() }));
159 protected void finalize() throws Throwable
165 ((Closeable) service).close();
166 } catch (Throwable t)
174 public ParamDatastoreI getParamStore()
176 if (paramStore == null)
180 paramStore = new JabaParamStore(this,
181 (Desktop.instance != null ? Desktop.getUserParameterStore()
183 } catch (Exception ex)
185 System.err.println("Unexpected exception creating JabaParamStore.");
186 ex.printStackTrace();
193 public String getUri()
195 // this is only valid for Jaba 1.0 - this formula might have to change!
197 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
202 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()