001    package railo.intergral.fusiondebug.server.util;
002    
003    import java.util.Iterator;
004    
005    import railo.intergral.fusiondebug.server.type.FDVariable;
006    import railo.runtime.exp.PageException;
007    import railo.runtime.op.Constants;
008    import railo.runtime.type.Array;
009    import railo.runtime.type.ArrayImpl;
010    import railo.runtime.type.Collection;
011    import railo.runtime.type.Collection.Key;
012    import railo.runtime.type.KeyImpl;
013    import railo.runtime.type.Query;
014    import railo.runtime.type.QueryImpl;
015    import railo.runtime.type.Struct;
016    import railo.runtime.type.StructImpl;
017    
018    import com.intergral.fusiondebug.server.IFDValue;
019    import com.intergral.fusiondebug.server.IFDVariable;
020    
021    public class FDDump {
022    
023            //private static PrintStream out=System.out;
024    
025            public static void dump(IFDVariable var) {
026                    System.out.print(toString(var));
027            }
028    
029            public static String toString(Object value) {
030                    StringBuffer sb=new StringBuffer();
031                    dump(sb,value, 0);
032                    return sb.toString();
033            }
034            
035            public static String toString(IFDVariable var) {
036                    StringBuffer sb=new StringBuffer();
037                    dump(sb,var, 0);
038                    return sb.toString();
039            }
040            
041    
042            private static void dump(StringBuffer sb,Object value,int level) {
043                    if(value instanceof IFDValue) dump(sb, (IFDValue)value, level);
044                    else dump(sb, (IFDVariable)value, level);
045            }
046            
047            private static void dump(StringBuffer sb,IFDValue value,int level) {
048                    for(int i=0;i<level;i++){
049                            sb.append(" - ");
050                    }
051                    
052                    sb.append(value.toString());
053                    sb.append("\n");
054                    if(value.hasChildren()){ 
055                            Iterator it = value.getChildren().iterator();
056                            while(it.hasNext()){
057                                    Object o=it.next();
058                                    dump(sb,(IFDVariable) o,level+1);
059                            }
060                    }
061            }
062            
063            private static void dump(StringBuffer sb,IFDVariable var,int level) {
064                    for(int i=0;i<level;i++){
065                            sb.append(" - ");
066                    }
067                    sb.append(var.getName());
068                    sb.append(":");
069                    IFDValue value = var.getValue();
070                    
071                    sb.append(value.toString());
072                    sb.append("\n");
073                    //print.err(value.getClass().getName());
074                    if(value.hasChildren()){ 
075                            Iterator it = value.getChildren().iterator();
076                            while(it.hasNext()){
077                                    Object o=it.next();
078                                    //print.err(o.getClass().getName());
079                                    dump(sb,(IFDVariable) o,level+1);
080                                    //dump(sb,(IFDVariable) it.next(),level+1);
081                            }
082                    }
083            }
084            
085            public static void main(String[] args) throws PageException {
086                    Array arr = new ArrayImpl();
087                    arr.setEL(1, "aaa");
088                    arr.setEL(2, Boolean.TRUE);
089                    arr.setEL(5, Constants.INTEGER_3);
090                    
091                    Array sub1 = new ArrayImpl();
092                    sub1.setEL(1, "ddd");
093                    arr.setEL(6, sub1);
094                    
095                    Struct sct=new StructImpl();
096                    sct.set("susi1", "eee");
097                    sct.set("susi2", "fff");
098                    arr.setEL(7, sct);
099                    
100                    Key aaa = KeyImpl.intern("aaa");
101                    Key bbb = KeyImpl.intern("bbb");
102                    Query qry=new QueryImpl(new Collection.Key[]{aaa,bbb},2,"quererli");
103                    qry.setAt(aaa, 1, "a1");
104                    qry.setAt(bbb, 1, "b1");
105                    qry.setAt(aaa, 2, "a2");
106                    qry.setAt(bbb, 2, sct);
107                    arr.setEL(8, qry);
108                    
109                    //arr.setEL(9, new StringBuffer());
110    
111                    dump(new FDVariable(null,"susi",FDCaster.toFDValue(null,"susi",qry)));
112                    //dump(new FDVariable(null,"susi",FDCaster.toFDValue(null,"susi",arr)));
113                    
114                    //dump(FDCaster.toFDVariable("susi",arr));
115            }
116    }