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;
19 import compbio.ws.client.Jws2Client;
20 import compbio.ws.client.Services;
22 public class Jws2Instance
24 public String hosturl;
26 public String serviceType;
28 public JABAService service;
29 public String description;
31 public Jws2Instance(String hosturl, String serviceType, String action, String description,
35 this.hosturl = hosturl;
36 this.serviceType = serviceType;
37 this.service = service;
39 this.description = description;
43 PresetManager presets = null;
45 public JabaParamStore paramStore = null;
48 * non thread safe - gets the presets for this service (blocks whilst it calls
49 * the service to get the preset set)
51 * @return service presets or null if exceptions were raised.
53 public PresetManager getPresets()
59 if (service instanceof MsaWS<?>)
61 presets = ((MsaWS) service).getPresets();
64 if (service instanceof SequenceAnnotation<?>)
66 presets = ((SequenceAnnotation) service).getPresets();
68 } catch (Exception ex)
70 System.err.println("Exception when retrieving presets for service "
71 + serviceType + " at " + hosturl);
77 public String getHost()
81 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
82 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
83 * serviceurl.getHost(); } catch (Exception e) {
84 * System.err.println("Failed to parse service URL '" + hosturl +
85 * "' as a valid URL!"); } return null;
90 * @return short description of what the service will do
92 public String getActionText()
94 return action+" with " + serviceType;
98 * non-thread safe - blocks whilst accessing service to get complete set of
99 * available options and parameters
103 public RunnerConfig getRunnerConfig()
105 if (service instanceof MsaWS<?>)
107 return ((MsaWS) service).getRunnerOptions();
109 if (service instanceof SequenceAnnotation<?>)
111 return ((SequenceAnnotation) service).getRunnerOptions();
113 throw new Error("Implementation Error: Runner Config not available for a JABAWS service of type "+serviceType+" ("+service.getClass()+")");
117 protected void finalize() throws Throwable
123 Closeable svc = (Closeable) service;
126 } catch (Exception e)
134 public ParamDatastoreI getParamStore()
136 if (paramStore == null)
140 paramStore = new JabaParamStore(this,
141 (Desktop.instance != null ? Desktop.getUserParameterStore()
143 } catch (Exception ex)
151 public String getUri()
153 // this is only valid for Jaba 1.0 - this formula might have to change!
155 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
156 : "/") + serviceType;
159 private boolean hasParams = false, lookedForParams = false;
161 public boolean hasParameters()
163 if (!lookedForParams)
165 lookedForParams = true;
168 hasParams = (getRunnerConfig().getArguments().size() > 0);
169 } catch (Exception e)
177 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
179 if (service instanceof MsaWS<?>)
181 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
183 if (service instanceof SequenceAnnotation<?>){
184 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this, alignFrame);