001 package railo.intergral.fusiondebug.server.util; 002 003 import railo.intergral.fusiondebug.server.type.coll.FDCollection; 004 import railo.intergral.fusiondebug.server.type.coll.FDUDF; 005 import railo.intergral.fusiondebug.server.type.nat.FDNative; 006 import railo.intergral.fusiondebug.server.type.qry.FDQuery; 007 import railo.intergral.fusiondebug.server.type.simple.FDSimpleValue; 008 import railo.runtime.converter.ScriptConverter; 009 import railo.runtime.op.Caster; 010 import railo.runtime.op.Decision; 011 import railo.runtime.type.Collection; 012 import railo.runtime.type.Query; 013 import railo.runtime.type.UDF; 014 015 import com.intergral.fusiondebug.server.IFDStackFrame; 016 import com.intergral.fusiondebug.server.IFDValue; 017 018 public class FDCaster { 019 020 021 public static IFDValue toFDValue(IFDStackFrame frame,String name,Object value) { 022 if(value instanceof UDF) 023 return new FDUDF(frame,name, (UDF)value); 024 if(value instanceof Query) 025 return new FDQuery(frame, (Query)value); 026 //if(value instanceof Array) 027 // return new FDArray(frame,name,(Array)value); 028 if(value instanceof Collection) 029 return new FDCollection(frame,name,(Collection)value); 030 if(Decision.isCastableToString(value)) 031 return new FDSimpleValue(null,Caster.toString(value,null)); 032 return new FDNative(frame,name,value); 033 } 034 035 public static IFDValue toFDValue(IFDStackFrame frame,Object value) { 036 return toFDValue(frame,"", value); 037 } 038 039 /** 040 * translate a object to its string representation 041 * @param object 042 * @return 043 */ 044 public static String serialize(Object object) { 045 if(object==null) return "[null]"; 046 try { 047 return new ScriptConverter().serialize(object); 048 } 049 catch (Throwable t) { 050 return object.toString(); 051 } 052 } 053 054 public static Object unserialize(String value) { 055 // TODO 056 return value; 057 } 058 }