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;
56 * @param hosturl Service endpoint
57 * @param serviceType Category for this service's analysis
58 * @param action text describing their action that service performs (eg 'aligning', 'analysing')
59 * @param description Description from JABAWS registry
60 * @param service JABAWS registry ID for service
62 public Jws2Instance(String hosturl, String serviceType, String action,
63 String description, JABAService service)
66 this.hosturl = hosturl;
67 this.serviceType = serviceType;
68 this.service = service;
70 this.description = description;
71 int p = description.indexOf("MORE INFORMATION:");
74 docUrl = description.substring(description.indexOf("http", p)).trim();
75 if (docUrl.indexOf('\n') > -1)
77 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
83 PresetManager presets = null;
85 public JabaParamStore paramStore = null;
88 * non thread safe - gets the presets for this service (blocks whilst it calls
89 * the service to get the preset set)
91 * @return service presets or null if exceptions were raised.
93 public PresetManager getPresets()
99 if (service instanceof MsaWS<?>)
101 presets = ((MsaWS) service).getPresets();
104 if (service instanceof SequenceAnnotation<?>)
106 presets = ((SequenceAnnotation) service).getPresets();
108 } catch (Exception ex)
110 System.err.println("Exception when retrieving presets for service "
111 + serviceType + " at " + hosturl);
117 public String getHost()
121 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
122 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
123 * serviceurl.getHost(); } catch (Exception e) {
124 * System.err.println("Failed to parse service URL '" + hosturl +
125 * "' as a valid URL!"); } return null;
130 * @return short description of what the service will do
132 public String getActionText()
134 return action + " with " + serviceType;
138 * non-thread safe - blocks whilst accessing service to get complete set of
139 * available options and parameters
143 public RunnerConfig getRunnerConfig()
145 if (service instanceof MsaWS<?>)
147 return ((MsaWS) service).getRunnerOptions();
149 if (service instanceof SequenceAnnotation<?>)
151 return ((SequenceAnnotation) service).getRunnerOptions();
154 "Implementation Error: Runner Config not available for a JABAWS service of type "
155 + serviceType + " (" + service.getClass() + ")");
159 protected void finalize() throws Throwable
165 Closeable svc = (Closeable) service;
168 } catch (Exception e)
176 public ParamDatastoreI getParamStore()
178 if (paramStore == null)
182 paramStore = new JabaParamStore(this,
183 (Desktop.instance != null ? Desktop.getUserParameterStore()
185 } catch (Exception ex)
187 System.err.println("Unexpected exception creating JabaParamStore.");
188 ex.printStackTrace();
195 public String getUri()
197 // this is only valid for Jaba 1.0 - this formula might have to change!
199 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
200 : "/") + serviceType;
203 private boolean hasParams = false, lookedForParams = false;
205 public boolean hasParameters()
207 if (!lookedForParams)
209 lookedForParams = true;
212 hasParams = (getRunnerConfig().getArguments().size() > 0);
213 } catch (Exception e)
221 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
223 if (service instanceof MsaWS<?>)
225 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
227 else if (service instanceof SequenceAnnotation<?>)
229 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
234 public String getServiceTypeURI()
236 return "java:" + serviceType;
238 jalview.ws.uimodel.AlignAnalysisUIText aaui;
239 public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()