Package Specification.Galaxy

Source Code of Specification.Galaxy.ValueHandler

package Specification.Galaxy;

import java.util.Map;
import java.util.TreeMap;

import FileOps.XStream.AdvancedXStreamHandler;
import Galaxy.Tree.Tool.Database.DBValue.AppendParamValue;
import Galaxy.Tree.Tool.Database.DBValue.BaseValue;
import Galaxy.Tree.Tool.Database.DBValue.ValueTranslationValue;

/**
* Correctly parses and generates the value tag to include the
* galaxy_value, remote_value fields, as well as the contents.
* @author viper
*
*/
public class ValueHandler extends AdvancedXStreamHandler{

  public ValueHandler() {
    super(BaseValue.class);
    // TODO Auto-generated constructor stub
  }

  @Override
  public Map<String, String> mapFromObject(Object o) {
    // TODO Auto-generated method stub
    Map<String,String> mymap = new TreeMap<String,String>();
    if(o instanceof ValueTranslationValue){
      ValueTranslationValue v = (ValueTranslationValue)o;
      mymap.put("galaxy_value", v.getGalaxyValue());
      mymap.put("remote_value", v.getRemoteValue());
    }
    else if(o instanceof AppendParamValue){
      AppendParamValue a = (AppendParamValue)o;
      mymap.put("name", a.getName());
      mymap.put("missing", a.getMissing());
     
    }
    return mymap;
  }

  @Override
  public Object mapToObject(Map<String, String> attributes) {
    // TODO Auto-generated method stub
    //Must be
    if(attributes.containsKey("missing") ||
      attributes.containsKey("name")){
      AppendParamValue appendParamValue = new AppendParamValue();
      appendParamValue.setMissing(attributes.get("missing"));
      appendParamValue.setName(attributes.get("name"));
      return appendParamValue;
    }
    else if(attributes.containsKey("galaxy_value") ||
        attributes.containsKey("remote_value")){
      ValueTranslationValue valueTranslationValue =
            new ValueTranslationValue();
      valueTranslationValue.setGalaxyValue(attributes.get("galaxy_value"));
      valueTranslationValue.setRemoteValue(attributes.get("remote_value"));
      return valueTranslationValue;
    }
    else
      return null;
  }
  public boolean canConvert(Class arg0) {
    // TODO Auto-generated method stub
    if(arg0.equals(ValueTranslationValue.class) ||
        arg0.equals(AppendParamValue.class)||
        arg0.equals(BaseValue.class))
      return true;
    return false;
  }

}
TOP

Related Classes of Specification.Galaxy.ValueHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.