/*
 * Created on Nov 17, 2005
 */
package uk.org.ponder.conversion;

import uk.org.ponder.mapping.DataAlterationRequest;

/**
 * Converts objects to and from strings using one of a repertoire of strategies
 * (leaf conversion, XML or JSON)
 * 
 * @author Antranig Basman (antranig@caret.cam.ac.uk)
 * 
 */
public class GeneralConverter {
  private SerializationProvider XMLProvider;
  private SerializationProvider JSONProvider;
  private GeneralLeafParser leafParser;
  
  /**
   * @param provider the XMLProvider to set
   */
  public void setXMLProvider(SerializationProvider provider) {
    XMLProvider = provider;
  }
  /**
   * @param provider the JSONProvider to set
   */
  public void setJSONProvider(SerializationProvider provider) {
    JSONProvider = provider;
  }
  /**
   * @param leafParser the leafParser to set
   */
  public void setLeafParser(GeneralLeafParser leafParser) {
    this.leafParser = leafParser;
  }
  
  
  public String render(Object torender, String encoding) {
    if (encoding.equals(DataAlterationRequest.JSON_ENCODING)) {
      return JSONProvider.toString(torender);
    }
    else if (encoding.equals(DataAlterationRequest.XML_ENCODING)) {
        return XMLProvider.toString(torender);
      }
      else return leafParser.render(torender);
  }

  public Object parse(String toparse, Class targetclass, String encoding) {
    if (DataAlterationRequest.JSON_ENCODING.equals(encoding)) {
      return JSONProvider.fromString(toparse);
    }
    else if (DataAlterationRequest.XML_ENCODING.equals(encoding)) {
        return XMLProvider.fromString(toparse);
      }
    else return leafParser.parse(targetclass, toparse);
  }

}

@@ -982,32 +982,154 @@
 ing encoding) %7B%0A
+    if (torender == null %7C%7C leafParser.isLeafType(torender.getClass())) %7B%0A      return leafParser.render(torender);%0A    %7D%0A
     if (encoding
@@ -1359,135 +1359,318 @@
     
-  
 else 
-return leafParser.render(torender);%0A  %7D%0A%0A  public Object parse(String toparse, Class targetclass, String encoding) %7B%0A   
+throw new IllegalArgumentException(%22Cannot convert non-leaf %22 + torender.getClass() + %22 using leaf encoding%22);%0A  %7D%0A%0A  public Object parse(String toparse, Class targetclass, String encoding) %7B%0A    if (leafParser.isLeafType(targetclass)) %7B%0A      return leafParser.parse(targetclass, toparse);%0A    %7D%0A    else
  if 
@@ -1916,52 +1916,108 @@
 lse 
-return leafParser.parse(targetclass, toparse
+throw new IllegalArgumentException(%22Cannot convert non-leaf %22 + targetclass + %22 using leaf encoding%22
 );%0A 

Fix for RSF-78, with incorrect encoding of leaf types in bindings and elsewhere (Encoding of String arrays for multiple-select fossils will probably still barf) TestSelect test case expanded RequestLauncher infrastructure corrected to put incoming VPs through the full parse process Extra constructor for UIInput Comments