From: jprocter Date: Tue, 31 Aug 2010 16:14:38 +0000 (+0000) Subject: utilities for cloning and manipulating JabaWS parameter objects. X-Git-Tag: Release_2_6~84 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=650159ffaacc133f9d58c604b8010393cdd1f01a;p=jalview.git utilities for cloning and manipulating JabaWS parameter objects. --- diff --git a/src/jalview/ws/jws2/ParameterUtils.java b/src/jalview/ws/jws2/ParameterUtils.java new file mode 100644 index 0000000..00878fb --- /dev/null +++ b/src/jalview/ws/jws2/ParameterUtils.java @@ -0,0 +1,79 @@ +package jalview.ws.jws2; + +import java.util.HashSet; +import java.util.List; + +import compbio.metadata.*; +public class ParameterUtils +{ + + public static Option copyOption(Option option) + { + Option copy = new Option(option.getName(), option.getDescription()); + setOptionFrom(copy, option); + return copy; + } + public static void setOptionFrom(Option copy, Option option) + { + copy.setName(option.getName()); + copy.setDescription(option.getDescription()); + copy.setFurtherDetails(option.getFurtherDetails()); + copy.setRequired(option.isRequired()); + List names = option.getOptionNames(); + if (names!=null){ + if (names.size()==1) + { + HashSet st = new HashSet(); + st.add(names.get(0)); + copy.setOptionNames(st); + } else { + copy.addOptionNames(names.toArray(new String[]{})); + } + } + try { + if (option.getDefaultValue()!=null) + { + copy.setDefaultValue(option.getDefaultValue()); + } + } catch (Exception ex) + { + ex.printStackTrace(); + } + } + + public static ValueConstrain copyValueConstrain(ValueConstrain vc) + { + try {ValueConstrain copy = new ValueConstrain(); + if (vc.getMax()!=null) { + copy.setMax(vc.getMax().toString()); + } + if (vc.getMin()!=null) { + copy.setMin(vc.getMin().toString()); + } + if (vc.getType()!=null) { + copy.setType(vc.getType()); + } + return copy; + } + catch (Exception e) + { + e.printStackTrace(); + throw new Error("Implementation error: could not copy ValueConstrain!"); + } + } + public static Parameter copyParameter(Parameter parameter) + { + Parameter copy = new Parameter(parameter.getName(), parameter.getDescription()); + if (parameter.getValidValue()!=null) { + copy.setValidValue(copyValueConstrain(parameter.getValidValue())); + } + List pv = parameter.getPossibleValues(); + if (pv!=null) + { + copy.addPossibleValues(pv.toArray(new String[]{})); + } + setOptionFrom(copy, parameter); + return copy; + } + +}