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;
26 public JABAService service;
27 public String description;
29 public Jws2Instance(String hosturl, String serviceType, String action, String description,
33 this.hosturl = hosturl;
34 this.serviceType = serviceType;
35 this.service = service;
37 this.description = description;
41 PresetManager presets = null;
43 public JabaParamStore paramStore = null;
46 * non thread safe - gets the presets for this service (blocks whilst it calls
47 * the service to get the preset set)
49 * @return service presets or null if exceptions were raised.
51 public PresetManager getPresets()
57 if (service instanceof MsaWS<?>)
59 presets = ((MsaWS) service).getPresets();
62 if (service instanceof SequenceAnnotation<?>)
64 presets = ((SequenceAnnotation) service).getPresets();
66 } catch (Exception ex)
68 System.err.println("Exception when retrieving presets for service "
69 + serviceType + " at " + hosturl);
75 public String getHost()
79 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
80 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
81 * serviceurl.getHost(); } catch (Exception e) {
82 * System.err.println("Failed to parse service URL '" + hosturl +
83 * "' as a valid URL!"); } return null;
88 * @return short description of what the service will do
90 public String getActionText()
92 return action+" with " + serviceType;
96 * non-thread safe - blocks whilst accessing service to get complete set of
97 * available options and parameters
101 public RunnerConfig getRunnerConfig()
103 if (service instanceof MsaWS<?>)
105 return ((MsaWS) service).getRunnerOptions();
107 if (service instanceof SequenceAnnotation<?>)
109 return ((SequenceAnnotation) service).getRunnerOptions();
111 throw new Error("Implementation Error: Runner Config not available for a JABAWS service of type "+serviceType+" ("+service.getClass()+")");
115 protected void finalize() throws Throwable
121 Closeable svc = (Closeable) service;
124 } catch (Exception e)
132 public ParamDatastoreI getParamStore()
134 if (paramStore == null)
138 paramStore = new JabaParamStore(this,
139 (Desktop.instance != null ? Desktop.getUserParameterStore()
141 } catch (Exception ex)
149 public String getUri()
151 // this is only valid for Jaba 1.0 - this formula might have to change!
153 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
154 : "/") + serviceType;
157 private boolean hasParams = false, lookedForParams = false;
159 public boolean hasParameters()
161 if (!lookedForParams)
163 lookedForParams = true;
166 hasParams = (getRunnerConfig().getArguments().size() > 0);
167 } catch (Exception e)
175 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
177 if (service instanceof MsaWS<?>)
179 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
181 if (service instanceof SequenceAnnotation<?>){
182 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this, alignFrame);