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