/**************************************************************************
 * Display the type, value, etc. of any variable 
 *************************************************************************/
import java.lang.reflect.*;

public class Dump 
{
    static String content(Object o)  
    {
        StringBuffer buffer = new StringBuffer();
        Class oClass = o.getClass();                    //get reference to the Class 

        if (oClass.isArray())                           //if the object of the Class is an array 
        {
            buffer.append("[");
            int length = Array.getLength(o);
            for (int i = 0; i < length; i++)            //loop for as many elements 
            {
                Object value = Array.get(o, i);         //get the element value as an object
                if (value != null) 
                {
                    if (value.getClass().isArray())     //if the value is an array          
                    {
                        String c = content(value);      //do recursive call 
                        buffer.append(c);
                    }
                    else                                //if the value is not an array,
                        buffer.append(value);           //simply add the value            
                }                                       
                if (i < length-1)                       //if not the last elment 
                    buffer.append(",");                 //append ,
            }
            buffer.append("]");
        } 
        else                                            //if the object of the Class is not an array 
        {
            buffer.append("{");

            if (oClass != null)                         //if the object != null 
            {
                Field[] fields = oClass.getDeclaredFields();
                int length = fields.length;
                for (int i = 0; i < length; i++)                //loop for as many fields 
                {
                    fields[i].setAccessible(true);              //allow me to access even if private
                    buffer.append(fields[i].getName());
                    buffer.append("=");
                    try {
                        Object value = fields[i].get(o);        //get the field value as an object
                        if (value != null) 
                        {
                            if (value.getClass().isArray())     //if the value is an array          
                            {
                                String c = content(value);      //do recursive call 
                                buffer.append(c);
                            }
                            else                                //if the value is not an array,
                                buffer.append(value);           //simply add the value 
                        }                                       
                        if (i < length-1)
                            buffer.append(", ");
                    } 
                    catch (IllegalAccessException e) { } 
                }
//              oClass = oClass.getSuperclass();
            }
            buffer.append("}");
        }
        return buffer.toString();
    }
}