1 package jalview.ws.jws2.jabaws2;
3 import jalview.gui.AlignFrame;
4 import jalview.gui.Desktop;
5 import jalview.ws.jws2.JabaParamStore;
6 import jalview.ws.jws2.MsaWSClient;
7 import jalview.ws.jws2.SequenceAnnotationWSClient;
8 import jalview.ws.params.ParamDatastoreI;
10 import java.io.Closeable;
12 import javax.swing.JMenu;
14 import compbio.data.msa.JABAService;
15 import compbio.data.msa.MsaWS;
16 import compbio.data.msa.SequenceAnnotation;
17 import compbio.metadata.PresetManager;
18 import compbio.metadata.RunnerConfig;
20 public class Jws2Instance
22 public String hosturl;
24 public String serviceType;
28 public JABAService service;
30 public String description;
34 public Jws2Instance(String hosturl, String serviceType, String action,
35 String description, JABAService service)
38 this.hosturl = hosturl;
39 this.serviceType = serviceType;
40 this.service = service;
42 this.description = description;
43 int p = description.indexOf("MORE INFORMATION:");
46 docUrl = description.substring(description.indexOf("http", p)).trim();
47 if (docUrl.indexOf('\n') > -1)
49 docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
55 PresetManager presets = null;
57 public JabaParamStore paramStore = null;
60 * non thread safe - gets the presets for this service (blocks whilst it calls
61 * the service to get the preset set)
63 * @return service presets or null if exceptions were raised.
65 public PresetManager getPresets()
71 if (service instanceof MsaWS<?>)
73 presets = ((MsaWS) service).getPresets();
76 if (service instanceof SequenceAnnotation<?>)
78 presets = ((SequenceAnnotation) service).getPresets();
80 } catch (Exception ex)
82 System.err.println("Exception when retrieving presets for service "
83 + serviceType + " at " + hosturl);
89 public String getHost()
93 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
94 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
95 * serviceurl.getHost(); } catch (Exception e) {
96 * System.err.println("Failed to parse service URL '" + hosturl +
97 * "' as a valid URL!"); } return null;
102 * @return short description of what the service will do
104 public String getActionText()
106 return action + " with " + serviceType;
110 * non-thread safe - blocks whilst accessing service to get complete set of
111 * available options and parameters
115 public RunnerConfig getRunnerConfig()
117 if (service instanceof MsaWS<?>)
119 return ((MsaWS) service).getRunnerOptions();
121 if (service instanceof SequenceAnnotation<?>)
123 return ((SequenceAnnotation) service).getRunnerOptions();
126 "Implementation Error: Runner Config not available for a JABAWS service of type "
127 + serviceType + " (" + service.getClass() + ")");
131 protected void finalize() throws Throwable
137 Closeable svc = (Closeable) service;
140 } catch (Exception e)
148 public ParamDatastoreI getParamStore()
150 if (paramStore == null)
154 paramStore = new JabaParamStore(this,
155 (Desktop.instance != null ? Desktop.getUserParameterStore()
157 } catch (Exception ex)
165 public String getUri()
167 // this is only valid for Jaba 1.0 - this formula might have to change!
169 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
170 : "/") + serviceType;
173 private boolean hasParams = false, lookedForParams = false;
175 public boolean hasParameters()
177 if (!lookedForParams)
179 lookedForParams = true;
182 hasParams = (getRunnerConfig().getArguments().size() > 0);
183 } catch (Exception e)
191 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
193 if (service instanceof MsaWS<?>)
195 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
197 else if (service instanceof SequenceAnnotation<?>)
199 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
204 public String getServiceTypeURI()
206 return "java:" + serviceType;