2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.ws.jws2.jabaws2;
20 import jalview.gui.AlignFrame;
21 import jalview.gui.Desktop;
22 import jalview.ws.jws2.JabaParamStore;
23 import jalview.ws.jws2.MsaWSClient;
24 import jalview.ws.jws2.SequenceAnnotationWSClient;
25 import jalview.ws.params.ParamDatastoreI;
27 import java.io.Closeable;
29 import javax.swing.JMenu;
31 import compbio.data.msa.JABAService;
32 import compbio.data.msa.MsaWS;
33 import compbio.data.msa.SequenceAnnotation;
34 import compbio.metadata.PresetManager;
35 import compbio.metadata.RunnerConfig;
37 public class Jws2Instance
39 public String hosturl;
41 public String serviceType;
45 public JABAService service;
47 public String description;
53 * @param hosturl Service endpoint
54 * @param serviceType Category for this service's analysis
55 * @param action text describing their action that service performs (eg 'aligning', 'analysing')
56 * @param description Description from JABAWS registry
57 * @param service JABAWS registry ID for service
59 public Jws2Instance(String hosturl, String serviceType, String action,
60 String description, JABAService service)
63 this.hosturl = hosturl;
64 this.serviceType = serviceType;
65 this.service = service;
67 this.description = description;
68 int p = description.indexOf("MORE INFORMATION:");
71 docUrl = description.substring(description.indexOf("http", p)).trim();
72 if (docUrl.indexOf('\n') > -1)
74 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
80 PresetManager presets = null;
82 public JabaParamStore paramStore = null;
85 * non thread safe - gets the presets for this service (blocks whilst it calls
86 * the service to get the preset set)
88 * @return service presets or null if exceptions were raised.
90 public PresetManager getPresets()
96 if (service instanceof MsaWS<?>)
98 presets = ((MsaWS) service).getPresets();
101 if (service instanceof SequenceAnnotation<?>)
103 presets = ((SequenceAnnotation) service).getPresets();
105 } catch (Exception ex)
107 System.err.println("Exception when retrieving presets for service "
108 + serviceType + " at " + hosturl);
114 public String getHost()
118 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
119 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
120 * serviceurl.getHost(); } catch (Exception e) {
121 * System.err.println("Failed to parse service URL '" + hosturl +
122 * "' as a valid URL!"); } return null;
127 * @return short description of what the service will do
129 public String getActionText()
131 return action + " with " + serviceType;
135 * non-thread safe - blocks whilst accessing service to get complete set of
136 * available options and parameters
140 public RunnerConfig getRunnerConfig()
142 if (service instanceof MsaWS<?>)
144 return ((MsaWS) service).getRunnerOptions();
146 if (service instanceof SequenceAnnotation<?>)
148 return ((SequenceAnnotation) service).getRunnerOptions();
151 "Implementation Error: Runner Config not available for a JABAWS service of type "
152 + serviceType + " (" + service.getClass() + ")");
156 protected void finalize() throws Throwable
162 Closeable svc = (Closeable) service;
165 } catch (Exception e)
173 public ParamDatastoreI getParamStore()
175 if (paramStore == null)
179 paramStore = new JabaParamStore(this,
180 (Desktop.instance != null ? Desktop.getUserParameterStore()
182 } catch (Exception ex)
184 System.err.println("Unexpected exception creating JabaParamStore.");
185 ex.printStackTrace();
192 public String getUri()
194 // this is only valid for Jaba 1.0 - this formula might have to change!
196 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
197 : "/") + serviceType;
200 private boolean hasParams = false, lookedForParams = false;
202 public boolean hasParameters()
204 if (!lookedForParams)
206 lookedForParams = true;
209 hasParams = (getRunnerConfig().getArguments().size() > 0);
210 } catch (Exception e)
218 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
220 if (service instanceof MsaWS<?>)
222 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
224 else if (service instanceof SequenceAnnotation<?>)
226 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
231 public String getServiceTypeURI()
233 return "java:" + serviceType;
235 jalview.ws.uimodel.AlignAnalysisUIText aaui;
236 public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()