import compbio.metadata.ValueConstrain.Type;
import jalview.util.jarInputStreamProvider;
+import jalview.ws.jws2.JabaParamStore;
+import jalview.ws.jws2.JabaPreset;
import jalview.ws.jws2.Jws2Discoverer;
import jalview.ws.jws2.ParameterUtils;
import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
+import jalview.ws.jws2.dm.JabaOption;
+import jalview.ws.jws2.dm.JabaParameter;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.OptionI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.ParameterI;
+import jalview.ws.params.ValueConstrainI;
+import jalview.ws.params.WsParamSetI;
/**
* job parameter editing/browsing dialog box. User can browse existing settings
JScrollPane paramPane = new JScrollPane();
- // JList paramList = new JList();
JPanel paramList = new JPanel();
RunnerConfig serviceOptions;
- private BorderLayout jparamLayout;
+ ParamDatastoreI paramStore;
WsJobParameters(Jws2Instance service)
{
this(service, null);
}
- public WsJobParameters(Jws2Instance service, Preset p)
+ public WsJobParameters(Jws2Instance service, WsParamSetI preset)
{
- this(null, service, p, null);
+ this(null, service, preset, null);
}
/**
* @param desktop
* - if null, create new JFrame outside of desktop
* @param service
- * @param p
+ * @param preset
*/
- public WsJobParameters(JFrame parent, Jws2Instance service, Preset p,
+ public WsJobParameters(JFrame parent, Jws2Instance service, WsParamSetI preset,
List<Argument> jobArgset)
{
+ this(parent, null, service, preset, jobArgset);
+ }
+
+ /**
+ *
+ * @param parent
+ * @param paramStorei
+ * @param service
+ * @param preset
+ * @param jobArgset
+ */
+ public WsJobParameters(JFrame parent, ParamDatastoreI paramStorei,
+ Jws2Instance service, WsParamSetI preset, List<Argument> jobArgset)
+ {
super();
jbInit();
+ this.paramStore = paramStorei;
+ if (paramStore == null)
+ {
+ paramStore = service.getParamStore();
+ }
+ this.service = service;
// argSetModified(false);
// populate parameter table
- initForService(service, p, jobArgset);
+ initForService(service, preset, jobArgset);
// display in new JFrame attached to parent.
validate();
}
setDetails.add(setDescrView, BorderLayout.CENTER);
// setDetails.setPreferredSize(new Dimension(360, 100));
jobParameters.setBorder(new TitledBorder("Parameters"));
- jobParameters.setLayout(jparamLayout = new BorderLayout());
+ jobParameters.setLayout(new BorderLayout());
paramPane.setPreferredSize(new Dimension(360, 300));
paramPane.getVerticalScrollBar().setUnitIncrement(20);
// paramPanel.setPreferredSize(new Dimension(360, 300));
}
}
+ private void _deleteUserPreset(String lastParmSet2)
+ {
+ paramStore.deletePreset(lastParmSet2);
+ }
+
protected void delete_actionPerformed(ActionEvent e)
{
if (isUserPreset)
*/
boolean settingDialog = false;
- void initForService(Jws2Instance service, Preset p,
- List<Argument> jobArgset)
+ void initForService(Jws2Instance service, WsParamSetI jabap,
+ List<Argument> jabajobArgset)
{
+ WsParamSetI p = null;
+ List<ArgumentI> jobArgset = null;
settingDialog = true;
- this.service = service;
+ { // instantiate the abstract proxy for Jaba objects
+ jobArgset = jabajobArgset == null ? null : JabaParamStore
+ .getJwsArgsfromJaba(jabajobArgset);
+ p = jabap; // (jabap != null) ? paramStore.getPreset(jabap.getName()) : null;
+ }
// TODO: Recover window geometry prefs for this service
// jobPanel.setDividerLocation(proportionalLocation)
// settingsPanel.setDividerLocation(proportionalLocation)
{
exnames.put((String) setName.getItemAt(i), setName.getItemAt(i));
}
+ servicePresets = new Hashtable();
// Add the default entry - if not present already.
if (!exnames.contains(SVC_DEF))
{
setName.addItem(SVC_DEF);
exnames.put(SVC_DEF, SVC_DEF);
+ servicePresets.put(SVC_DEF, SVC_DEF);
}
- serviceOptions = service.getRunnerConfig();
- // add any presets not already added.
String curname = (p == null ? "" : p.getName());
- PresetManager prman = service.getPresets();
- servicePresets = new Hashtable();
- if (prman != null)
+ for (WsParamSetI pr : paramStore.getPresets())
{
- List prList = service.getPresets().getPresets();
- if (prList != null)
+ if (!pr.isModifiable())
{
- for (Object pr : prList)
- {
- servicePresets.put(((Preset) pr).getName(), "preset");
- if (!exnames.contains(((Preset) pr).getName()))
- {
- setName.addItem(((Preset) pr).getName());
- }
- }
+ servicePresets.put(pr.getName(), "preset");
+ }
+ else
+ {
+ }
+ if (!exnames.contains(pr.getName()))
+ {
+ setName.addItem(pr.getName());
}
}
// TODO: if initial jobArgset matches a given user setting or preset then
}
@SuppressWarnings("unchecked")
- private void updateTable(Preset p, List<Argument> jobArgset)
+ private void updateTable(WsParamSetI p, List<ArgumentI> jobArgset)
{
- List<Parameter> setargs = new ArrayList<Parameter>();
// populate table from default parameter set.
- List<Argument> args = serviceOptions.getArguments();
+ List<ArgumentI> args = paramStore.getServiceParameters();
// split to params and required arguments
{
- for (Argument arg : args)
+ for (ArgumentI myarg : args)
{
- Argument myarg = (Argument) arg;
// Ideally, Argument would implement isRequired !
- if (myarg instanceof Parameter)
+ if (myarg instanceof ParameterI)
{
- Parameter parm = (Parameter) myarg;
+ ParameterI parm = (ParameterI) myarg;
addParameter(parm);
}
else
{
- if (myarg instanceof Option)
+ if (myarg instanceof OptionI)
{
- Option opt = (Option) myarg;
+ OptionI opt = (OptionI) myarg;
addOption(opt).resetToDefault();
}
else
{
System.err.println("Ignoring unknown service argument type "
- + arg.getClass().getName());
+ + myarg.getClass().getName());
}
}
}
// TODO - URL link
try
{
- args = p.getArguments(serviceOptions);
+ args = p.getArguments();
} catch (Exception e)
{
e.printStackTrace();
}
// TODO: check if args should be unselected prior to resetting using the
// preset
- setargs.clear();
}
else
{
{
isUserPreset = false;
// first call - so create a dummy name
+
setName.setSelectedItem(lastSetName = SVC_DEF);
}
}
// get setargs from current object
if (args != null)
{
- for (Argument arg : args)
+ for (ArgumentI arg : args)
{
- if (arg instanceof Parameter)
+ if (arg instanceof ParameterI)
{
- setParameter((Parameter) arg);
+ setParameter((ParameterI) arg);
}
else
{
- if (arg instanceof Option)
+ if (arg instanceof OptionI)
{
// System.out.println("Setting option "
// + System.identityHashCode(arg) + ":" + arg.getName()
// + " with " + arg.getDefaultValue());
- selectOption((Option) arg, arg.getDefaultValue());
+ selectOption((OptionI) arg, arg.getDefaultValue());
}
}
{
return;
}
-
if (!b)
{
modifiedElements.remove(modifiedElement);
}
else
{
+ if (b && modifiedElement == setName
+ && modifiedElements.contains(modifiedElement))
+ {
+ // HACK! prevents iteration on makeSetNameValid
+ b = false;
+ }
modifiedElements.put(modifiedElement, modifiedElement);
}
// set mod status based on presence of elements in table
if (newuserset)
{
int i = 0;
- while (_getUserPreset(tnm) != null)
+ while (paramStore.getPreset(tnm) != null)
{
tnm = nm + " (" + (++i) + ")";
renamed = true;
settingDialog = stn;
}
- private void addParameter(Parameter parm)
+ private void addParameter(ParameterI arg)
{
- ParamBox pb = paramSet.get(parm.getName());
+ ParamBox pb = paramSet.get(arg.getName());
if (pb == null)
{
- pb = new ParamBox(this, parm);
- paramSet.put(parm.getName(), pb);
+ pb = new ParamBox(this, arg);
+ paramSet.put(arg.getName(), pb);
paramList.add(pb);
}
pb.init();
// take the defaults from the parameter
- pb.updateControls(parm);
+ pb.updateControls(arg);
}
- private void setParameter(Parameter arg)
+ private void setParameter(ParameterI arg)
{
ParamBox pb = paramSet.get(arg.getName());
if (pb == null)
}
- private void selectOption(Option opt, String string)
+ private void selectOption(OptionI option, String string)
{
- OptionBox cb = optSet.get(opt.getName());
+ OptionBox cb = optSet.get(option.getName());
if (cb == null)
{
- cb = addOption(opt);
+ cb = addOption(option);
}
cb.enabled.setSelected(string != null); // initial state for an option.
if (string != null)
{
- if (opt.getPossibleValues().contains(string))
+ if (option.getPossibleValues().contains(string))
{
cb.val.setSelectedItem(string);
}
else
{
- throw new Error("Invalid value " + string + " for option " + opt);
+ throw new Error("Invalid value " + string + " for option " + option);
}
}
- if (opt.isRequired() && !cb.enabled.isSelected())
+ if (option.isRequired() && !cb.enabled.isSelected())
{
// TODO: indicate paramset is not valid.. option needs to be selected!
}
JTextField valueField = null;
- ValueConstrain validator = null;
+ ValueConstrainI validator = null;
JPanel settingPanel = new JPanel();
final URL finfo;
- public ParamBox(final WsJobParameters pmlayout, Parameter parm)
+ public ParamBox(final WsJobParameters pmlayout, ParameterI parm)
{
pmdialogbox = pmlayout;
setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
boolean adjusting = false;
- Parameter parameter;
+ ParameterI parameter;
JComboBox choicebox;
return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
}
- public void updateControls(Parameter parm)
+ public void updateControls(ParameterI parm)
{
adjusting = true;
boolean init = (choicebox == null && valueField == null);
Object lastVal;
- public Parameter getParameter()
+ public ParameterI getParameter()
{
- Parameter prm = ParameterUtils.copyParameter(parameter);
- try
+ ParameterI prm = parameter.copy();
+ if (choice)
{
- if (choice)
- {
- prm.setDefaultValue((String) choicebox.getSelectedItem());
- }
- else
- {
- prm.setDefaultValue(valueField.getText());
- }
- } catch (WrongParameterException e)
+ prm.setDefaultValue((String) choicebox.getSelectedItem());
+ }
+ else
{
- e.printStackTrace();
- return null;
+ prm.setDefaultValue(valueField.getText());
}
return prm;
}
{
valueField.setText(valueField.getText().trim());
iVal = Integer.valueOf(valueField.getText());
+ if (validator.getMin()!=null && validator.getMin().intValue()>iVal)
+ {
+ iVal = validator.getMin().intValue();
+ // TODO: provide visual indication that hard limit was reached for this parameter
+ }
+ if (validator.getMax()!=null && validator.getMax().intValue()<iVal)
+ {
+ iVal = validator.getMax().intValue();
+ // TODO: provide visual indication that hard limit was reached for this parameter
+ }
} catch (Exception e)
{
}
try
{
fVal = Float.valueOf(valueField.getText());
+ if (validator.getMin()!=null && validator.getMin().floatValue()>fVal)
+ {
+ fVal = validator.getMin().floatValue();
+ // TODO: provide visual indication that hard limit was reached for this parameter
+ }
+ if (validator.getMax()!=null && validator.getMax().floatValue()<fVal)
+ {
+ fVal = validator.getMax().floatValue();
+ // TODO: provide visual indication that hard limit was reached for this parameter
+ }
} catch (Exception e)
{
}
boolean hasLink = false;
- Option option;
+ OptionI option;
- public OptionBox(Option opt)
+ public OptionBox(OptionI opt)
{
option = opt;
setLayout(new BorderLayout());
}
}
- public Option getOptionIfEnabled()
+ public OptionI getOptionIfEnabled()
{
if (!enabled.isSelected())
{
return null;
}
- Option opt = null;
- try
- {
- opt = jalview.ws.jws2.ParameterUtils.copyOption(option);
+ OptionI opt = option.copy();
- if (val.getSelectedItem() != null)
- {
- opt.setDefaultValue((String) val.getSelectedItem());
- }
- } catch (WrongParameterException e)
+ if (val.getSelectedItem() != null)
{
- e.printStackTrace();
- return null;
+ opt.setDefaultValue((String) val.getSelectedItem());
}
return opt;
}
}
- private OptionBox addOption(Option opt)
+ private OptionBox addOption(OptionI opt)
{
OptionBox cb = optSet.get(opt.getName());
if (cb == null)
lastserv.getRunnerConfig(), " ");
readparam = jalview.ws.jws2.ParameterUtils
.writeParameterSet(pset, " ");
- Iterator<String> o=pr.getOptions().iterator(),s = writeparam.iterator(), t = readparam
- .iterator();
- boolean failed=false;
+ Iterator<String> o = pr.getOptions().iterator(), s = writeparam
+ .iterator(), t = readparam.iterator();
+ boolean failed = false;
while (s.hasNext() && t.hasNext())
{
- String on=o.next(),sn = s.next(),st=t.next();
+ String on = o.next(), sn = s.next(), st = t.next();
if (!sn.equals(st))
{
- System.out.println("Original was "+on+" Phase 1 wrote " + sn
- + "\tPhase 2 wrote " + st);
- failed=true;
+ System.out.println("Original was " + on
+ + " Phase 1 wrote " + sn + "\tPhase 2 wrote "
+ + st);
+ failed = true;
}
}
if (failed)
{
- System.out.println("Original parameters:\n"+pr.getOptions());
- System.out.println("Wrote parameters in first set:\n"+writeparam);
- System.out.println("Wrote parameters in second set:\n"+readparam);
+ System.out.println("Original parameters:\n"
+ + pr.getOptions());
+ System.out.println("Wrote parameters in first set:\n"
+ + writeparam);
+ System.out.println("Wrote parameters in second set:\n"
+ + readparam);
}
} catch (Exception e)
e.printStackTrace();
}
}
- WsJobParameters pgui = new WsJobParameters(lastserv, pr);
+ WsJobParameters pgui = new WsJobParameters(lastserv, new JabaPreset(lastserv, pr));
JFrame jf = new JFrame("Parameters for "
+ lastserv.getActionText());
JPanel cont = new JPanel();
}
}
- public List<Argument> getJobParams()
+ public List<ArgumentI> getJobParams()
{
- List<Argument> argSet = new ArrayList<Argument>();
+ List<ArgumentI> argSet = new ArrayList<ArgumentI>();
// recover options and parameters from GUI
for (OptionBox opts : optSet.values())
{
- Option opt = opts.getOptionIfEnabled();
+ OptionI opt = opts.getOptionIfEnabled();
if (opt != null)
{
argSet.add(opt);
}
for (ParamBox parambox : paramSet.values())
{
- Parameter parm = parambox.getParameter();
+ ParameterI parm = parambox.getParameter();
if (parm != null)
{
argSet.add(parm);
String lastParmSet = null;
- Hashtable<String, Object[]> editedParams = new Hashtable<String, Object[]>();
-
- /**
+ /*
+ * Hashtable<String, Object[]> editedParams = new Hashtable<String,
+ * Object[]>();
+ *
* 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.
- Object[] pset;
- editedParams.put(storeSetName, pset = new Object[3]);
- pset[0] = storeSetName;
- pset[1] = descr;
- pset[2] = jobParams;
- // writeParam("Saving " + storeSetName + ": ", jobParams);
- }
-
- private void writeParam(String nm, List<Argument> params)
- {
- for (Argument p : params)
- {
- System.out.println(nm + ":" + System.identityHashCode(p) + " Name: "
- + p.getName() + " Value: " + p.getDefaultValue());
- }
- }
-
- private Object[] _getUserPreset(String setName)
- {
- Object[] pset = editedParams.get(setName);
- // if (pset != null)
- // writeParam("Retrieving " + setName + ": ", (List<Argument>) pset[2]);
- return pset;
- }
-
- /**
- * remove the given user preset from the preset stash
+ * @param storeSetName - lastParmSet
+ *
+ * @param descr - setDescr.getText()
+ *
+ * @param jobParams - getJobParams()
+ *
+ * private void _storeUserPreset(String storeSetName, String descr,
+ * List<ArgumentI> jobParams) { // this is a simple hash store. Object[] pset;
+ * editedParams.put(storeSetName, pset = new Object[3]); pset[0] =
+ * storeSetName; pset[1] = descr; pset[2] = jobParams; // writeParam("Saving "
+ * + storeSetName + ": ", jobParams); }
+ *
+ * private void writeParam(String nm, List<ArgumentI> params) { for (ArgumentI
+ * p : params) { System.out.println(nm + ":" + System.identityHashCode(p) +
+ * " Name: " + p.getName() + " Value: " + p.getDefaultValue()); } }
+ *
+ * private Object[] _getUserPreset(String setName) { Object[] pset =
+ * editedParams.get(setName); // if (pset != null) // writeParam("Retrieving "
+ * + setName + ": ", (List<Argument>) pset[2]); return pset; }
+ *
+ * * remove the given user preset from the preset stash
*
* @param setName
+ *
+ * private void _deleteUserPreset(String setName) {
+ * editedParams.remove(setName); }
*/
- private void _deleteUserPreset(String setName)
- {
- editedParams.remove(setName);
- }
private void syncSetNamesWithStore()
{
while (n < setName.getItemCount())
{
String item = (String) setName.getItemAt(n);
- if (!isServicePreset(item) && _getUserPreset(item) == null)
+ if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
{
setName.removeItemAt(n);
}
n++;
}
}
- for (String upn : editedParams.keySet())
+ if (!items.contains(SVC_DEF))
+ {
+ setName.addItem(SVC_DEF);
+ }
+ for (WsParamSetI upn : paramStore.getPresets())
{
- if (!items.contains(upn))
+ if (!items.contains(upn.getName()))
{
- setName.addItem(upn);
+ setName.addItem(upn.getName());
}
}
}
{
settingDialog = true;
// updateTable(null,null); // first reset to defaults
- Object[] pset = null;
+ WsParamSetI pset = null;
if (nextPreset != null && nextPreset.length() > 0)
{
- pset = _getUserPreset(nextPreset);
+ pset = paramStore.getPreset(nextPreset);
}
if (pset != null)
{
- isUserPreset = true;
- setDescr.setText((String) pset[1]);
- updateTable(null, (List<Argument>) pset[2]);
- lastParmSet = nextPreset;
- }
- else
- {
- isUserPreset = false;
- setDescr.setText("");
- // must be a default preset from service
- Preset p = null;
- try
- {
- PresetManager prman = service.getPresets();
- if (prman != null)
- {
- isUserPreset = false;
- p = prman.getPresetByName(nextPreset);
- }
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- if (p != null)
+ if (pset.isModifiable())
{
- updateTable(p, null);
+ isUserPreset = true;
+ setDescr.setText(pset.getDescription());
+ updateTable(null, pset.getArguments());
lastParmSet = nextPreset;
}
else
{
- updateTable(null, null);
- lastParmSet = SVC_DEF;
+ isUserPreset = false;
+ setDescr.setText("");
+ // must be a default preset from service
+ updateTable(pset, null);
+ lastParmSet = nextPreset;
}
}
+ else
+ {
+ isUserPreset = false;
+ // Service defaults
+ updateTable(null, null);
+ lastParmSet = SVC_DEF;
+ }
+
initArgSetModified();
syncSetNamesWithStore();
setName.setSelectedItem(lastParmSet);
*/
private void _storeCurrentPreset(String curSetName2)
{
- _storeUserPreset(curSetName2, setDescr.getText(), getJobParams());
+ paramStore.storePreset(curSetName2, setDescr.getText(), getJobParams());
}
/**
checkDescrModified();
}
- public Preset getPreset()
+ /**
+ *
+ * @return null or the service preset selected by the user
+ */
+ public WsParamSetI getPreset()
{
if (isUserPreset || isModified()
|| (lastParmSet != null && lastParmSet.equals(SVC_DEF)))
}
else
{
- Preset p = null;
- try
- {
- return (Preset) service.getPresets().getPresetByName(lastParmSet);
- } catch (Exception e)
- {
- e.printStackTrace();
- return null;
- }
+ return paramStore.getPreset(lastParmSet);
}
}
}
\ No newline at end of file
--- /dev/null
+package jalview.ws.jws2;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import compbio.metadata.Argument;
+import compbio.metadata.Option;
+import compbio.metadata.Parameter;
+import compbio.metadata.Preset;
+import compbio.metadata.PresetManager;
+import compbio.metadata.RunnerConfig;
+
+import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
+import jalview.ws.jws2.dm.JabaOption;
+import jalview.ws.jws2.dm.JabaParameter;
+import jalview.ws.jws2.dm.JabaWsParamSet;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.WsParamSetI;
+
+public class JabaParamStore implements ParamDatastoreI
+{
+
+ Hashtable<String, JabaWsParamSet> editedParams = new Hashtable<String, JabaWsParamSet>();
+
+ private Jws2Instance service;
+
+ private RunnerConfig serviceOptions;
+
+ private Hashtable<String, JabaPreset> servicePresets;
+
+ 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
+ }
+
+ /**
+ * 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);
+ }
+
+ private void writeParam(String nm, List<Argument> params)
+ {
+ for (Argument p : params)
+ {
+ System.out.println(nm + ":" + System.identityHashCode(p) + " Name: "
+ + p.getName() + " Value: " + p.getDefaultValue());
+ }
+ }
+
+ 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()
+ {
+ List<WsParamSetI> prefs = new ArrayList();
+ if (servicePresets == null)
+ {
+ servicePresets = new Hashtable<String, JabaPreset>();
+ PresetManager prman;
+ if ((prman = service.getPresets()) != null)
+ {
+ List pset = prman.getPresets();
+ if (pset != null)
+ {
+ for (Object pr : pset)
+ {
+ JabaPreset prset = new JabaPreset(service, (Preset) pr);
+ servicePresets.put(prset.getName(), prset);
+ }
+ }
+ }
+ }
+ for (JabaPreset pr : servicePresets.values())
+ {
+ prefs.add(pr);
+ }
+ for (WsParamSetI wspset : editedParams.values())
+ {
+ prefs.add(wspset);
+ }
+ return prefs;
+ }
+
+ @Override
+ public WsParamSetI getPreset(String name)
+ {
+ for (WsParamSetI pr : getPresets())
+ {
+ if (pr.getName().equals(name))
+ {
+ return pr;
+ }
+ }
+ return null;
+ }
+
+ public static List<ArgumentI> getJwsArgsfromJaba(List jabargs)
+ {
+ List<ArgumentI> rgs = new ArrayList<ArgumentI>();
+ for (Object rg : jabargs)
+ {
+ ArgumentI narg = (rg instanceof Parameter) ? new JabaParameter(
+ (Parameter) rg) : (rg instanceof Option) ? new JabaOption(
+ (Option) rg) : null;
+ if (narg == null)
+ {
+ throw new Error(
+ "Implementation Error: Cannot handle Jaba parameter object "
+ + rg.getClass());
+ }
+ else
+ {
+ rgs.add(narg);
+ }
+ }
+ return rgs;
+ }
+
+ public static List getJabafromJwsArgs(List<ArgumentI> jwsargs)
+ {
+ List rgs = new ArrayList();
+ for (ArgumentI rg : jwsargs)
+ {
+ Argument narg = (rg instanceof JabaOption) ? ((JabaOption) rg)
+ .getOption() : null;
+ if (narg == null)
+ {
+ throw new Error(
+ "Implementation Error: Cannot handle Jaba parameter object "
+ + rg.getClass());
+ }
+ else
+ {
+ rgs.add(narg);
+ }
+ }
+ return rgs;
+ }
+
+ @Override
+ public List<ArgumentI> getServiceParameters()
+ {
+ return getJwsArgsfromJaba(serviceOptions.getArguments());
+ }
+
+ @Override
+ public boolean presetExists(String name)
+ {
+ return (editedParams.containsKey(name) || servicePresets
+ .containsKey(name));
+ }
+
+ @Override
+ public void deletePreset(String name)
+ {
+ if (editedParams.containsKey(name))
+ {
+ editedParams.remove(name);
+ return;
+ }
+ if (servicePresets.containsKey(name))
+ {
+ throw new Error(
+ "Implementation error: Attempt to delete a service preset!");
+ }
+ }
+
+
+ @Override
+ public void storePreset(String presetName, String text,
+ List<ArgumentI> jobParams)
+ {
+ JabaWsParamSet jps = new JabaWsParamSet(presetName, text, jobParams);
+ editedParams.put(jps.getName(), jps);
+ }
+
+ @Override
+ public boolean readParamSet(WsParamSetI wsp,
+ Reader reader) throws IOException
+ {
+ if (!(wsp instanceof JabaWsParamSet))
+ {
+ throw new Error("Implementation error: JabaWsParamSets can only be handled by JabaParamStore");
+ }
+ List<String> lines=new ArrayList<String>();
+ String line;
+ BufferedReader br = new BufferedReader(reader);
+ while ((line=br.readLine())!=null)
+ {
+ lines.add(line);
+ }
+ ((JabaWsParamSet) wsp).setjabaArguments(ParameterUtils.processParameters(lines, serviceOptions, " "));
+ return true;
+ }
+
+ @Override
+ public boolean writeParamSet(WsParamSetI wsp,
+ Writer writer) 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;
+ }
+
+}