package Specification.Galaxy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import FileOps.XStream.AdvancedXStreamHandler;
import Galaxy.Tree.Tool.Command.Command;
import Galaxy.Tree.Tool.Input.Param.Option;
/**
* This handler handles the option field properly, correctly
* parsing and generating the select field and the contents.
* @author viper
*
*/
public class OptionHandler extends AdvancedXStreamHandler{
public OptionHandler(){
super(Option.class);
}
@Override
public Map<String, String> mapFromObject(Object o) {
// TODO Auto-generated method stub
Option c = (Option) o;
Map<String, String> myMapping;
myMapping = new HashMap<String, String>();
myMapping.put(NAME_TAG, "option");
myMapping.put(VALUE_TAG, c.getContents());
myMapping.put("value", c.getValue());
if(c.isSelected() != null)
myMapping.put("selected", c.isSelected().toString());
else
myMapping.put("selected", "false" .toString());
return myMapping;
}
@Override
public Object mapToObject(Map<String, String> attributes) {
Option option;
String contents;
List<String> tokens = new ArrayList();
final String val;
final Boolean selected;
contents = attributes.get(VALUE_TAG);
val = attributes.get("value");
selected = new Boolean(attributes.get("selected"));
option = new Option(val, contents);
option.setSelected(selected);
return option;
}
}