import jalview.bin.Cache;
import jalview.io.*;
+import jalview.ws.params.ParamManager;
import java.awt.*;
import java.awt.datatransfer.*;
}).start();
}
+ public static WsParamSetManager wsparamManager = null;
+ public static ParamManager getUserParameterStore()
+ {
+ if (wsparamManager==null)
+ {
+ wsparamManager = new WsParamSetManager();
+ }
+ return wsparamManager;
+ }
+
}
if (isUserPreset)
{
String curname = ((String) setName.getSelectedItem()).trim();
- if (curname.length() > 0 && !curname.equals(lastParmSet))
- {
- _deleteUserPreset(lastParmSet);
- }
- _storeCurrentPreset(curname);
+ _updatePreset(lastParmSet, curname);
lastParmSet = curname;
isUserPreset = true;
initArgSetModified();
}
}
+
private void _deleteUserPreset(String lastParmSet2)
{
paramStore.deletePreset(lastParmSet2);
}
{
System.out.println("Testing opts dupes for "
- + lastserv.getHost() + " : "
+ + lastserv.getUri() + " : "
+ lastserv.getActionText() + ":" + pr.getName());
List<Option> rg = lastserv.getRunnerConfig().getOptions();
for (Option o : rg)
}
}
+ private void _renameExistingPreset(String oldName, String curSetName2)
+ {
+ paramStore.updatePreset(oldName, curSetName2, setDescr.getText(), getJobParams());
+ }
/**
* store current settings as given name. You should then reset gui.
{
paramStore.storePreset(curSetName2, setDescr.getText(), getJobParams());
}
+ private void _updatePreset(String lastParmSet2, String curname)
+ {
+ paramStore.updatePreset(lastParmSet2, curname, setDescr.getText(), getJobParams());
+
+ }
/**
* last saved name for this user preset
--- /dev/null
+package jalview.gui;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+
+import jalview.bin.Cache;
+import jalview.io.JalviewFileChooser;
+import jalview.ws.jws2.dm.JabaWsParamSet;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.ParamManager;
+import jalview.ws.params.WsParamSetI;
+
+/**
+ * store and retrieve web service parameter sets.
+ *
+ * @author JimP
+ *
+ */
+public class WsParamSetManager implements ParamManager
+{
+ Hashtable<String, ParamDatastoreI> paramparsers = new Hashtable<String, ParamDatastoreI>();
+
+ @Override
+ public WsParamSetI[] getParameterSet(String name, String serviceUrl,
+ boolean modifiable, boolean unmodifiable)
+ {
+ String files = Cache.getProperty("WS_PARAM_FILES");
+ if (files == null)
+ {
+ return null;
+ }
+ StringTokenizer st = new StringTokenizer(files, "|");
+ String pfile = null;
+ ArrayList<WsParamSetI> params = new ArrayList<WsParamSetI>();
+ while (st.hasMoreTokens())
+ {
+ pfile = st.nextToken();
+ try
+ {
+ WsParamSetI[] pset = parseParamFile(pfile);
+ for (WsParamSetI p : pset)
+ {
+ boolean add = false;
+ if (serviceUrl != null)
+ {
+ for (String url : p.getApplicableUrls())
+ {
+ if (url.equals(serviceUrl))
+ {
+ add = true;
+ }
+ }
+ }
+ else
+ {
+ add = true;
+ }
+ add &= (modifiable == p.isModifiable() || unmodifiable == !p
+ .isModifiable());
+ add &= name == null || p.getName().equals(name);
+
+ if (add)
+ {
+
+ params.add(p);
+ }
+
+ }
+ } catch (IOException e)
+ {
+ Cache.log
+ .info("Failed to parse parameter file "
+ + pfile
+ + " (Check that all JALVIEW_WSPARAMFILES entries are valid!)",
+ e);
+ }
+ }
+ return params.toArray(new WsParamSetI[0]);
+ }
+
+ private WsParamSetI[] parseParamFile(String filename) throws IOException
+ {
+ List<WsParamSetI> psets = new ArrayList<WsParamSetI>();
+ InputStreamReader is = new InputStreamReader(
+ new java.io.FileInputStream(new File(filename)), "UTF-8");
+
+ jalview.schemabinding.version2.WebServiceParameterSet wspset = new jalview.schemabinding.version2.WebServiceParameterSet();
+
+ org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
+ wspset);
+ unmar.setWhitespacePreserve(true);
+ try
+ {
+ wspset = (jalview.schemabinding.version2.WebServiceParameterSet) unmar
+ .unmarshal(is);
+ } catch (Exception ex)
+ {
+ throw new IOException(ex);
+ }
+ if (wspset != null && wspset.getParameters().length() > 0)
+ {
+ for (String url : wspset.getServiceURL())
+ {
+ ParamDatastoreI parser = paramparsers.get(url);
+ if (parser != null)
+ {
+ WsParamSetI pset = parser.parseServiceParameterFile(
+ wspset.getName(), wspset.getDescription(),
+ wspset.getServiceURL(), wspset.getParameters());
+ if (pset != null)
+ {
+ pset.setSourceFile(filename);
+ psets.add(pset);
+ break;
+ }
+ }
+ }
+ }
+
+ return psets.toArray(new WsParamSetI[0]);
+ }
+
+ @Override
+ public void storeParameterSet(WsParamSetI parameterSet)
+ {
+ String filename = parameterSet.getSourceFile();
+ File outfile = null;
+ try
+ {
+ if (filename != null && !((outfile = new File(filename)).canWrite()))
+ {
+ Cache.log.info("Can't write to " + filename
+ + " - Prompting for new file to write to.");
+ filename = null;
+ }
+ } catch (Exception e)
+ {
+ filename = null;
+ }
+
+ ParamDatastoreI parser = null;
+ for (String urls : parameterSet.getApplicableUrls())
+ {
+ if (parser == null)
+ {
+ parser = paramparsers.get(urls);
+ }
+ }
+ if (parser == null)
+ {
+ throw new Error(
+ "Implementation error: Can't find a marshaller for the parameter set");
+ }
+ if (filename == null)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
+ { "wsparams" }, new String[]
+ { "Web Service Parameter File" },
+ "Web Service Parameter File");
+ chooser.setFileView(new jalview.io.JalviewFileView());
+ chooser.setDialogTitle("Choose a filename for this parameter file");
+ chooser.setToolTipText("Save");
+ int value = chooser.showOpenDialog(Desktop.instance);
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ outfile = chooser.getSelectedFile();
+ jalview.bin.Cache
+ .setProperty("LAST_DIRECTORY", outfile.getParent());
+ filename = outfile.getAbsolutePath();
+ if (!filename.endsWith(".wsparams"))
+ {
+ filename = filename.concat(".wsparams");
+ outfile = new File(filename);
+ }
+ }
+ }
+ if (outfile != null)
+ {
+ String paramFiles = jalview.bin.Cache.getDefault("WS_PARAM_FILES",
+ filename);
+ if (paramFiles.indexOf(filename) == -1)
+ {
+ if (paramFiles.length() > 0)
+ {
+ paramFiles = paramFiles.concat("|");
+ }
+ paramFiles = paramFiles.concat(filename);
+ }
+ jalview.bin.Cache.setProperty("WS_PARAM_FILES", paramFiles);
+
+ jalview.schemabinding.version2.WebServiceParameterSet paramxml = new jalview.schemabinding.version2.WebServiceParameterSet();
+
+ paramxml.setName(parameterSet.getName());
+ paramxml.setDescription(parameterSet.getDescription());
+ paramxml.setServiceURL(parameterSet.getApplicableUrls().clone());
+ paramxml.setVersion("1.0");
+ try
+ {
+ paramxml.setParameters(parser
+ .generateServiceParameterFile(parameterSet));
+ PrintWriter out = new PrintWriter(new OutputStreamWriter(
+ new FileOutputStream(outfile), "UTF-8"));
+ paramxml.marshal(out);
+ out.close();
+ parameterSet.setSourceFile(filename);
+ } catch (Exception e)
+ {
+ Cache.log.error("Couldn't write parameter file to " + outfile, e);
+ }
+ }
+ }
+
+ /*
+ *
+ * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
+ * .getProperty("LAST_DIRECTORY"), new String[] { "jc" }, new String[] {
+ * "Jalview User Colours" }, "Jalview User Colours"); chooser.setFileView(new
+ * jalview.io.JalviewFileView());
+ * chooser.setDialogTitle("Load colour scheme");
+ * chooser.setToolTipText("Load");
+ *
+ * int value = chooser.showOpenDialog(this);
+ *
+ * if (value == JalviewFileChooser.APPROVE_OPTION) { File choice =
+ * chooser.getSelectedFile(); jalview.bin.Cache.setProperty("LAST_DIRECTORY",
+ * choice.getParent()); String defaultColours = jalview.bin.Cache.getDefault(
+ * "USER_DEFINED_COLOURS", choice.getPath()); if
+ * (defaultColours.indexOf(choice.getPath()) == -1) { defaultColours =
+ * defaultColours.concat("|") .concat(choice.getPath()); } (non-Javadoc)
+ *
+ * @see
+ * jalview.ws.params.ParamManager#deleteParameterSet(jalview.ws.params.WsParamSetI
+ * )
+ */
+ @Override
+ public void deleteParameterSet(WsParamSetI parameterSet)
+ {
+ String filename = parameterSet.getSourceFile();
+ if (filename == null || filename.trim().length() < 1)
+ {
+ return;
+ }
+ String paramFiles = jalview.bin.Cache.getDefault("WS_PARAM_FILES", "");
+ if (paramFiles.indexOf(filename) > -1)
+ {
+ String nparamFiles = new String();
+ StringTokenizer st = new StringTokenizer(paramFiles, "|");
+ while (st.hasMoreElements())
+ {
+ String fl = st.nextToken();
+ if (!fl.equals(filename))
+ {
+ nparamFiles = nparamFiles.concat("|").concat(fl);
+ }
+ }
+ jalview.bin.Cache.setProperty("WS_PARAM_FILES", nparamFiles);
+ }
+
+ try
+ {
+ File pfile = new File(filename);
+ if (pfile.exists() && pfile.canWrite())
+ {
+ if (JOptionPane.showConfirmDialog(Desktop.instance,
+ "Delete the preset's file, too ?", "Delete User Preset ?",
+ JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
+ {
+ pfile.delete();
+ }
+ }
+ } catch (Exception e)
+ {
+ Cache.log
+ .error("Exception when trying to delete webservice user preset: ",
+ e);
+ }
+ }
+
+ @Override
+ public void registerParser(String hosturl, ParamDatastoreI paramdataStore)
+ {
+ paramparsers.put(hosturl, paramdataStore);
+ }
+
+}
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
+import java.util.StringTokenizer;
import compbio.metadata.Argument;
import compbio.metadata.Option;
import jalview.ws.jws2.dm.JabaWsParamSet;
import jalview.ws.params.ArgumentI;
import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.ParamManager;
import jalview.ws.params.WsParamSetI;
public class JabaParamStore implements ParamDatastoreI
public JabaParamStore(Jws2Instance service)
{
- this.service = service;
- serviceOptions = service.getRunnerConfig();
- // TODO: discover all the user's locally sored presets for this service and populate the hash table
- // TODO: for JAL-632
+ this(service, null);
}
- /**
- * store the given parameters in the user parameter set database.
- *
- * @param storeSetName
- * - lastParmSet
- * @param descr
- * - setDescr.getText()
- * @param jobParams
- * - getJobParams()
- */
- private void _storeUserPreset(String storeSetName, String descr,
- List<Argument> jobParams)
- {
- // this is a simple hash store.
- editedParams.put(storeSetName, new JabaWsParamSet(storeSetName, descr,
- JabaParamStore.getJwsArgsfromJaba(jobParams)));
- // writeParam("Saving " + storeSetName + ": ", jobParams);
- }
+ ParamManager manager;
- private void writeParam(String nm, List<Argument> params)
+ public JabaParamStore(Jws2Instance service, ParamManager manager)
{
- for (Argument p : params)
+ this.service = service;
+ serviceOptions = service.getRunnerConfig();
+ this.manager = manager;
+ // discover all the user's locally stored presets for this service and
+ // populate the hash table
+ if (manager != null)
{
- System.out.println(nm + ":" + System.identityHashCode(p) + " Name: "
- + p.getName() + " Value: " + p.getDefaultValue());
+ manager.registerParser(service.getUri(), this);
+ WsParamSetI[] prams = manager.getParameterSet(null, service.getUri(),
+ true, false);
+ if (prams != null)
+ {
+ for (WsParamSetI paramset : prams)
+ {
+ if (paramset instanceof JabaWsParamSet)
+ {
+ editedParams.put(paramset.getName(), (JabaWsParamSet) paramset);
+ }
+ else
+ {
+ System.err
+ .println("Warning: Ignoring parameter set instance of type "
+ + paramset.getClass()
+ + " : Bound but not applicable for service at "
+ + service.getUri());
+ }
+ }
+ }
}
}
- private JabaWsParamSet _getUserPreset(String setName)
- {
- JabaWsParamSet pset = editedParams.get(setName);
- return pset;
- }
-
- /**
- * remove the given user preset from the preset stash
- *
- * @param setName
- */
- private void _deleteUserPreset(String setName)
- {
- editedParams.remove(setName);
- }
-
@Override
public List<WsParamSetI> getPresets()
{
{
if (editedParams.containsKey(name))
{
+ WsParamSetI parameterSet = editedParams.get(name);
editedParams.remove(name);
+ if (manager != null)
+ {
+ manager.deleteParameterSet(parameterSet);
+ }
return;
}
if (servicePresets.containsKey(name))
}
}
-
@Override
public void storePreset(String presetName, String text,
List<ArgumentI> jobParams)
{
JabaWsParamSet jps = new JabaWsParamSet(presetName, text, jobParams);
+ jps.setApplicableUrls(new String[]
+ { service.getUri() });
editedParams.put(jps.getName(), jps);
+ if (manager != null)
+ {
+ manager.storeParameterSet(jps);
+ }
}
@Override
- public boolean readParamSet(WsParamSetI wsp,
- Reader reader) throws IOException
+ public void updatePreset(String oldName, String presetName, String text,
+ List<ArgumentI> jobParams)
{
- if (!(wsp instanceof JabaWsParamSet))
+ JabaWsParamSet jps = (JabaWsParamSet) ((oldName != null) ? getPreset(oldName)
+ : getPreset(presetName));
+ if (jps == null)
{
- throw new Error("Implementation error: JabaWsParamSets can only be handled by JabaParamStore");
+ throw new Error("Implementation error: Can't locate either oldname ("
+ + oldName + ") or presetName (" + presetName
+ + "in the datastore!");
}
- List<String> lines=new ArrayList<String>();
- String line;
- BufferedReader br = new BufferedReader(reader);
- while ((line=br.readLine())!=null)
+ jps.setName(presetName);
+ jps.setDescription(text);
+ jps.setArguments(jobParams);
+ jps.setApplicableUrls(new String[]
+ { service.getUri() });
+ if (oldName != null && !oldName.equals(jps.getName()))
{
- lines.add(line);
+ editedParams.remove(oldName);
+ }
+ editedParams.put(jps.getName(), jps);
+
+ if (manager != null)
+ {
+ manager.storeParameterSet(jps);
}
- ((JabaWsParamSet) wsp).setjabaArguments(ParameterUtils.processParameters(lines, serviceOptions, " "));
- return true;
+ }
+
+ /**
+ * create a new, empty parameter set for this service
+ *
+ * @return
+ */
+ WsParamSetI newWsParamSet()
+ {
+ return new JabaWsParamSet();
+ };
+
+ private boolean involves(String[] urls)
+ {
+ boolean found = false;
+ for (String url : urls)
+ {
+ if (service.getUri().equalsIgnoreCase(url))
+ {
+ found = true;
+ break;
+ }
+ }
+ return found;
}
@Override
- public boolean writeParamSet(WsParamSetI wsp,
- Writer writer) throws IOException
+ public WsParamSetI parseServiceParameterFile(String name, String descr,
+ String[] urls, String parameterfile) throws IOException
{
- if (!(wsp instanceof JabaWsParamSet))
- {
- throw new Error("Implementation error: JabaWsParamSets can only be handled by JabaParamStore");
- }
- writer.write(ParameterUtils.writeParameterSet(((JabaWsParamSet)wsp).getjabaArguments(), " ")
- .toString());
- return true;
+ if (!involves(urls))
+ {
+ throw new IOException(
+ "Implementation error: Cannot find service url in the given url set!");
+
+ }
+ JabaWsParamSet wsp = new JabaWsParamSet();
+ wsp.setName(name);
+ wsp.setDescription(descr);
+ wsp.setApplicableUrls(urls.clone());
+
+ List<String> lines = new ArrayList<String>();
+ StringTokenizer st = new StringTokenizer(parameterfile, "\n");
+ while (st.hasMoreTokens())
+ {
+ lines.add(st.nextToken());
+ }
+ wsp.setjabaArguments(ParameterUtils.processParameters(lines,
+ serviceOptions, " "));
+ return wsp;
+ }
+
+ @Override
+ public String generateServiceParameterFile(WsParamSetI pset)
+ throws IOException
+ {
+ if (!involves(pset.getApplicableUrls()))
+ {
+ throw new IOException(
+ "Implementation error: Cannot find service url in the given url set for this service parameter store ("
+ + service.getUri() + ") !");
+
+ }
+ if (!(pset instanceof JabaWsParamSet))
+ {
+ throw new Error(
+ "Implementation error: JabaWsParamSets can only be handled by JabaParamStore");
+ }
+
+ StringBuffer rslt = new StringBuffer();
+ for (String ln : ParameterUtils.writeParameterSet(
+ ((JabaWsParamSet) pset).getjabaArguments(), " "))
+ {
+ rslt.append(ln);
+ rslt.append("\n");
+ }
+ ;
+ return rslt.toString();
}
}
@Override
public String[] getApplicableUrls()
{
- return new String[] { service.getHost()};
+ return new String[] { service.getUri()};
}
@Override
public String getSourceFile()
import jalview.bin.Cache;
import jalview.datamodel.AlignmentView;
import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
import jalview.ws.WSMenuEntryProviderI;
import jalview.ws.params.ParamDatastoreI;
import compbio.data.msa.MsaWS;
PresetManager presets = null;
- public JabaParamStore paramStore=null;
+ public JabaParamStore paramStore = null;
/**
* non thread safe - gets the presets for this service (blocks whilst it
{
if (paramStore == null)
{
- try {
- paramStore = new JabaParamStore(this);
+ try
+ {
+ paramStore = new JabaParamStore(this,
+ (Desktop.instance != null ? Desktop
+ .getUserParameterStore() : null));
} catch (Exception ex)
- {}
-
+ {
+ }
+
}
return paramStore;
}
+
+ public String getUri()
+ {
+ // this is only valid for Jaba 1.0 - this formula might have to change!
+ return hosturl+"/"+serviceType;
+ }
};
/**
{
// dynamically regenerate service list.
final JMenu jws2al = new JMenu("JABA Alignment");
- jws2al.addMenuListener(new MenuListener() {
- // TODO: future: add menu listener to parent menu - so submenus are populated *before* they are selected.
+ jws2al.addMenuListener(new MenuListener()
+ {
+ // TODO: future: add menu listener to parent menu - so submenus are
+ // populated *before* they are selected.
@Override
public void menuSelected(MenuEvent e)
{
public void menuDeselected(MenuEvent e)
{
// TODO Auto-generated method stub
-
+
}
@Override
public void menuCanceled(MenuEvent e)
{
// TODO Auto-generated method stub
-
+
}
-
+
});
wsmenu.add(jws2al);
}
+
private void populateWSMenuEntry(JMenu jws2al, final AlignFrame alignFrame)
{
if (running || services == null || services.size() == 0)
/**
* test the given URL with the JabaWS test code
+ *
* @param foo
* @return
*/
public static boolean testServiceUrl(URL foo)
{
- try {
- compbio.ws.client.WSTester.main(new String[] { "-h="+foo.toString()});
+ try
+ {
+ compbio.ws.client.WSTester.main(new String[]
+ { "-h=" + foo.toString() });
} catch (Exception e)
{
return false;
- }
- catch (OutOfMemoryError e)
+ } catch (OutOfMemoryError e)
{
return false;
- }
- catch (Error e)
+ } catch (Error e)
{
return false;
}
{
if (sh.paramStore == null)
{
- sh.paramStore = new JabaParamStore(sh);
+ sh.paramStore = new JabaParamStore(sh, Desktop.getUserParameterStore());
}
WsJobParameters jobParams = new WsJobParameters(sh, preset);
if (!jobParams.showRunDialog())
import java.io.IOException;
import java.util.List;
-public interface ParamDatastoreI
+public interface ParamDatastoreI
{
public List<WsParamSetI> getPresets();
public void deletePreset(String name);
/**
- * writes or overwrites the record for a modifiable WsParamSetI entry in the datastore.
+ * writes or overwrites the record for a modifiable WsParamSetI entry with a given name in the
+ * datastore.
+ *
* @param presetName
* @param text
* @param jobParams
- * may throw an illegal argument RunTimeException if the presetName overwrites an existing, unmodifiable preset.
+ * may throw an illegal argument RunTimeException if the presetName
+ * overwrites an existing, unmodifiable preset.
*/
public void storePreset(String presetName, String text,
List<ArgumentI> jobParams);
- public boolean readParamSet(WsParamSetI wsp, java.io.Reader reader)
+ /**
+ * update an existing instance with a new name, descriptive text and parameters.
+ * @param oldName
+ * @param presetName
+ * @param text
+ * @param jobParams
+ */
+ public void updatePreset(String oldName, String presetName, String text,
+ List<ArgumentI> jobParams);
+
+ /**
+ * factory method - builds a service specific parameter object using the given
+ * data
+ *
+ * @param name
+ * @param description
+ * @param applicable
+ * URLs
+ * @param parameterfile
+ * Service specific jalview parameter file (as returned from new
+ * method)
+ * @return null or valid WsParamSetI object for this service.
+ */
+
+ public WsParamSetI parseServiceParameterFile(String name,
+ String description, String[] serviceURL, String parameters)
throws IOException;
- public boolean writeParamSet(WsParamSetI wsp, java.io.Writer writer)
+ /**
+ * create the service specific parameter file for this pset object.
+ *
+ * @param pset
+ * @return string representation of the parameters specified by this set.
+ * @throws IOException
+ */
+ public String generateServiceParameterFile(WsParamSetI pset)
throws IOException;
}
package jalview.ws.params;
+
+import jalview.ws.jws2.dm.JabaWsParamSet;
+
/**
* Interface implemented by classes for maintaining user's parameters in a Jalview session
* @author JimP
* @param unmodifiable - if true, return server presets
* @return null if no parameters found, or one or more parameter sets
*/
- public abstract WsParamSetI[] getParameterSet(String name, String serviceUrl, boolean modifiable,boolean unmodifiable);
+ public WsParamSetI[] getParameterSet(String name, String serviceUrl, boolean modifiable,boolean unmodifiable);
+ /**
+ * save the given parameter set in the user's parameter set database.
+ * Note: this may result in a modal dialog box being raised.
+ * @param parameterSet
+ */
+ public void storeParameterSet(WsParamSetI parameterSet);
+ /**
+ * delete the specified parameter set from the database.
+ * Note: this may result in a modal dialog box being raised.
+ * @param parameterSet
+ */
+ public void deleteParameterSet(WsParamSetI parameterSet);
+ /**
+ * register a parser for the given host url
+ * @param hosturl
+ * @param jabaParamStore
+ */
+ public void registerParser(String hosturl, ParamDatastoreI paramdataStore);
}