2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.ws.jws2.jabaws2;
21 import jalview.gui.AlignFrame;
22 import jalview.gui.Desktop;
23 import jalview.ws.jws2.JabaParamStore;
24 import jalview.ws.jws2.MsaWSClient;
25 import jalview.ws.jws2.SequenceAnnotationWSClient;
26 import jalview.ws.params.ParamDatastoreI;
28 import java.io.Closeable;
30 import javax.swing.JMenu;
32 import compbio.data.msa.JABAService;
33 import compbio.data.msa.MsaWS;
34 import compbio.data.msa.SequenceAnnotation;
35 import compbio.metadata.PresetManager;
36 import compbio.metadata.RunnerConfig;
38 public class Jws2Instance
40 public String hosturl;
42 public String serviceType;
46 public JABAService service;
48 public String description;
54 * @param hosturl Service endpoint
55 * @param serviceType Category for this service's analysis
56 * @param action text describing their action that service performs (eg 'aligning', 'analysing')
57 * @param description Description from JABAWS registry
58 * @param service JABAWS registry ID for service
60 public Jws2Instance(String hosturl, String serviceType, String action,
61 String description, JABAService service)
64 this.hosturl = hosturl;
65 this.serviceType = serviceType;
66 this.service = service;
68 this.description = description;
69 int p = description.indexOf("MORE INFORMATION:");
72 docUrl = description.substring(description.indexOf("http", p)).trim();
73 if (docUrl.indexOf('\n') > -1)
75 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
81 PresetManager presets = null;
83 public JabaParamStore paramStore = null;
86 * non thread safe - gets the presets for this service (blocks whilst it calls
87 * the service to get the preset set)
89 * @return service presets or null if exceptions were raised.
91 public PresetManager getPresets()
97 if (service instanceof MsaWS<?>)
99 presets = ((MsaWS) service).getPresets();
102 if (service instanceof SequenceAnnotation<?>)
104 presets = ((SequenceAnnotation) service).getPresets();
106 } catch (Exception ex)
108 System.err.println("Exception when retrieving presets for service "
109 + serviceType + " at " + hosturl);
115 public String getHost()
119 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
120 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
121 * serviceurl.getHost(); } catch (Exception e) {
122 * System.err.println("Failed to parse service URL '" + hosturl +
123 * "' as a valid URL!"); } return null;
128 * @return short description of what the service will do
130 public String getActionText()
132 return action + " with " + serviceType;
136 * non-thread safe - blocks whilst accessing service to get complete set of
137 * available options and parameters
141 public RunnerConfig getRunnerConfig()
143 if (service instanceof MsaWS<?>)
145 return ((MsaWS) service).getRunnerOptions();
147 if (service instanceof SequenceAnnotation<?>)
149 return ((SequenceAnnotation) service).getRunnerOptions();
152 "Implementation Error: Runner Config not available for a JABAWS service of type "
153 + serviceType + " (" + service.getClass() + ")");
157 protected void finalize() throws Throwable
163 Closeable svc = (Closeable) service;
166 } catch (Exception e)
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) ? ""
198 : "/") + serviceType;
201 private boolean hasParams = false, lookedForParams = false;
203 public boolean hasParameters()
205 if (!lookedForParams)
207 lookedForParams = true;
210 hasParams = (getRunnerConfig().getArguments().size() > 0);
211 } catch (Exception e)
219 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
221 if (service instanceof MsaWS<?>)
223 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
225 else if (service instanceof SequenceAnnotation<?>)
227 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
232 public String getServiceTypeURI()
234 return "java:" + serviceType;
236 jalview.ws.uimodel.AlignAnalysisUIText aaui;
237 public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()