From: Mateusz Warowny Date: Wed, 23 Mar 2022 17:39:32 +0000 (+0100) Subject: JAL-3878 Create beans for un/marshalling service parameters X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3bd49104c09d90f1118ee58b789eaf4d79779e8d;p=jalview.git JAL-3878 Create beans for un/marshalling service parameters --- diff --git a/src/jalview/ws2/params/ArgumentBean.java b/src/jalview/ws2/params/ArgumentBean.java new file mode 100644 index 0000000..65b29bb --- /dev/null +++ b/src/jalview/ws2/params/ArgumentBean.java @@ -0,0 +1,82 @@ +package jalview.ws2.params; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import jalview.ws.params.ArgumentI; + +/** + * A minimal bean implementing {@link ArgumentI} which stores argument + * name, label and value. It's mainly used to marshal and unmarshal + * parameter values of a preset. + * + * @author mmwarowny + * + */ +@XmlRootElement(name = "parameter") +class ArgumentBean implements ArgumentI +{ + String name; + + String label; + + String value; + + ArgumentBean() + { + this.name = null; + this.label = null; + this.value = null; + } + + ArgumentBean(ArgumentI copyof) + { + this.name = copyof.getName(); + this.label = copyof.getLabel(); + this.value = copyof.getValue(); + } + + @XmlAttribute + @Override + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + @XmlElement + @Override + public String getLabel() + { + return label; + } + + public void setLabel(String label) + { + this.label = label; + } + + @XmlElement + @Override + public String getValue() + { + return value; + } + + @Override + public void setValue(String selectedItem) + { + this.value = selectedItem; + } + + @Override + public String toString() + { + return String.format("Parameter(name=%s, value=%s)", name, value); + } +} \ No newline at end of file diff --git a/src/jalview/ws2/params/ArgumentBeanList.java b/src/jalview/ws2/params/ArgumentBeanList.java new file mode 100644 index 0000000..87c15bd --- /dev/null +++ b/src/jalview/ws2/params/ArgumentBeanList.java @@ -0,0 +1,51 @@ +package jalview.ws2.params; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import jalview.ws.params.ArgumentI; + +/** + * A wrapper of {@link ArgumentBean} list that can be marshaled or unmarshalled. + * Used by {@link SimpleParamDatastore} to read and store parameters in a file. + * + * @see ArgumentBean + * @see SimpleParamDatastore + * @author mmwarowny + */ +@XmlRootElement(name = "arguments") +class ArgumentBeanList +{ + @XmlElement(name = "argument") + public List arguments = Collections.emptyList(); + + ArgumentBeanList() + { + } + + ArgumentBeanList(List arguments) + { + this.arguments = arguments; + } + + static ArgumentBeanList fromList(List list) + { + var args = new ArrayList(); + for (var item : list) + args.add(item instanceof ArgumentBean ? (ArgumentBean) item : new ArgumentBean(item)); + return new ArgumentBeanList(args); + } + + @Override + public String toString() + { + var elements = new String[arguments.size()]; + for (int i = 0; i < arguments.size(); i++) + elements[i] = arguments.toString(); + return "[" + String.join(", ", elements) + "]"; + } +} \ No newline at end of file