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;
38 int p=description.indexOf("MORE INFORMATION:");
41 docUrl = description.substring(description.indexOf("http",p)).trim();
42 if (docUrl.indexOf('\n')>-1) { docUrl = docUrl.substring(0,docUrl.indexOf("\n")).trim(); }
47 PresetManager presets = null;
49 public JabaParamStore paramStore = null;
52 * non thread safe - gets the presets for this service (blocks whilst it calls
53 * the service to get the preset set)
55 * @return service presets or null if exceptions were raised.
57 public PresetManager getPresets()
63 if (service instanceof MsaWS<?>)
65 presets = ((MsaWS) service).getPresets();
68 if (service instanceof SequenceAnnotation<?>)
70 presets = ((SequenceAnnotation) service).getPresets();
72 } catch (Exception ex)
74 System.err.println("Exception when retrieving presets for service "
75 + serviceType + " at " + hosturl);
81 public String getHost()
85 * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) {
86 * return serviceurl.getHost()+":"+serviceurl.getPort(); } return
87 * serviceurl.getHost(); } catch (Exception e) {
88 * System.err.println("Failed to parse service URL '" + hosturl +
89 * "' as a valid URL!"); } return null;
94 * @return short description of what the service will do
96 public String getActionText()
98 return action+" with " + serviceType;
102 * non-thread safe - blocks whilst accessing service to get complete set of
103 * available options and parameters
107 public RunnerConfig getRunnerConfig()
109 if (service instanceof MsaWS<?>)
111 return ((MsaWS) service).getRunnerOptions();
113 if (service instanceof SequenceAnnotation<?>)
115 return ((SequenceAnnotation) service).getRunnerOptions();
117 throw new Error("Implementation Error: Runner Config not available for a JABAWS service of type "+serviceType+" ("+service.getClass()+")");
121 protected void finalize() throws Throwable
127 Closeable svc = (Closeable) service;
130 } catch (Exception e)
138 public ParamDatastoreI getParamStore()
140 if (paramStore == null)
144 paramStore = new JabaParamStore(this,
145 (Desktop.instance != null ? Desktop.getUserParameterStore()
147 } catch (Exception ex)
155 public String getUri()
157 // this is only valid for Jaba 1.0 - this formula might have to change!
159 + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? ""
160 : "/") + serviceType;
163 private boolean hasParams = false, lookedForParams = false;
165 public boolean hasParameters()
167 if (!lookedForParams)
169 lookedForParams = true;
172 hasParams = (getRunnerConfig().getArguments().size() > 0);
173 } catch (Exception e)
181 public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
183 if (service instanceof MsaWS<?>)
185 new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
187 if (service instanceof SequenceAnnotation<?>){
188 new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
193 public String getServiceTypeURI()
195 return "java:"+serviceType;