org.openbp.common.dump
Class Dumper

java.lang.Object
  extended by org.openbp.common.dump.Dumper

public class Dumper
extends java.lang.Object

Generic class for dumping objects. Used for debugging and logging purposes.
The dump methods gather information about the object to dump using Java reflections. By default, each data member of a class and its superclasses will be dumped. If you want to override this behaviour, the object must implement the Dumpable interface.
The class keeps track of objects already dumped to prevent endless recursions.

Author:
Heiko Erhardt

Constructor Summary
Dumper()
          Do not instantiate this class!
 
Method Summary
 void dump(java.lang.Object object)
          Dumps an object to standard output.
 void dump(java.lang.Object object, java.io.Writer writer)
          Dumps an object to an output.
 void dump(java.lang.Object object, java.io.Writer writer, int indent)
          Dumps an object to an output.
 void dump(java.lang.String title, java.lang.Object o)
          Dumps an object to standard output with a title.
 void dump(java.lang.String title, java.lang.Object o, java.io.Writer writer, int indent)
          Dumps an object to an output with a title.
 void dumpMembers(java.lang.Object o, java.lang.Class cls, java.io.Writer writer, int indent)
          Dump the members of an object.
 int getMaxSetSize()
          Gets the maximum size of a set to be dumped.
 boolean getSkipNull()
          Gets the flag that determines if to skip null values.
 boolean getSkipStatic()
          Gets the flag that determines if to skip static data members.
 void setMaxSetSize(int maxSetSizeArg)
          Sets the maximum size of a set to be dumped.
 void setSkipNull(boolean skipNullArg)
          Sets the flag that determines if to skip null values.
 void setSkipStatic(boolean skipStaticArg)
          Sets the flag that determines if to skip static data members.
 void write(java.io.Writer writer, int indent)
          Writes the indent to the output writer.
protected  void write(java.io.Writer writer, java.lang.String s)
          Writes a string to the output writer.
protected  void write(java.io.Writer writer, java.lang.String s, int indent)
          Writes a string to the output writer.
protected  void writeln(java.io.Writer writer)
          Writes a newline to the output writer.
protected  void writeln(java.io.Writer writer, java.lang.String s)
          Writes a string and a newline to the output writer.
protected  void writeln(java.io.Writer writer, java.lang.String s, int indent)
          Writes a string to the output writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dumper

public Dumper()
Do not instantiate this class!

Method Detail

dump

public void dump(java.lang.Object object)
Dumps an object to standard output. Shorthand for dump (object, new PrintWriter (System.out, true)).

Parameters:
object - The object to dump

dump

public void dump(java.lang.String title,
                 java.lang.Object o)
Dumps an object to standard output with a title. Shorthand for dump (title, object, new PrintWriter (System.out, true), 0).

Parameters:
title - The title is prepended to the actual object dump
o - The object to dump Each indent level will translate to a tab character.

dump

public void dump(java.lang.Object object,
                 java.io.Writer writer)
Dumps an object to an output. Shorthand for dump (object, writer, 0).
If the object implements Dumpable, the class name of the object will be written on one line, followed by the output of the object's dump(Object) method on the subsequent lines, indented by 1.
Otherwise, the toString representation of the object will be output and the line terminated.

Parameters:
object - The object to dump
writer - Writer object to use for output generation

dump

public void dump(java.lang.Object object,
                 java.io.Writer writer,
                 int indent)
Dumps an object to an output. If the object implements Dumpable, the class name of the object will be written on one line, followed by the output of the object's dump(Object) method on the subsequent lines, indented by 1.
Otherwise, the toString representation of the object will be output and the line terminated.

Parameters:
object - The object to dump
writer - Writer object to use for output generation
indent - Indentation level (0 = no indentation)
Each indent level will translate to a tab character.

dump

public void dump(java.lang.String title,
                 java.lang.Object o,
                 java.io.Writer writer,
                 int indent)
Dumps an object to an output with a title. If the object implements Dumpable, the class name of the object will be written on one line, followed by the output of the object's dump(Object) method on the subsequent lines, indented by 1.
Otherwise, the toString representation of the object will be output and the line terminated.

Parameters:
title - The title is prepended to the actual object dump
o - The object to dump
writer - Writer object to use for output generation
indent - Indentation level (0 = no indentation)
Each indent level will translate to a tab character.

dumpMembers

public void dumpMembers(java.lang.Object o,
                        java.lang.Class cls,
                        java.io.Writer writer,
                        int indent)
Dump the members of an object. Also dumps the fields of the superclass of the object.

Parameters:
o - The object to dump
cls - Class object to use for the inspection of the fields of the object
writer - Writer object to use for output generation
indent - Indentation level (0 = no indentation)
Each indent level will translate to a tab character.

write

public void write(java.io.Writer writer,
                  int indent)
Writes the indent to the output writer.

Parameters:
writer - Writer object to use for output generation
indent - Indentation level (0 = no indentation)
Each indent level will translate to a tab character.

write

protected void write(java.io.Writer writer,
                     java.lang.String s)
              throws java.io.IOException
Writes a string to the output writer.

Parameters:
writer - Writer object to use for output generation
s - The string to write
Throws:
java.io.IOException - On i/o error

write

protected void write(java.io.Writer writer,
                     java.lang.String s,
                     int indent)
              throws java.io.IOException
Writes a string to the output writer.

Parameters:
writer - Writer object to use for output generation
s - The string to write
indent - Indentation level
Throws:
java.io.IOException - On i/o error

writeln

protected void writeln(java.io.Writer writer)
                throws java.io.IOException
Writes a newline to the output writer.

Parameters:
writer - Writer object to use for output generation
Throws:
java.io.IOException - On i/o error

writeln

protected void writeln(java.io.Writer writer,
                       java.lang.String s)
                throws java.io.IOException
Writes a string and a newline to the output writer.

Parameters:
writer - Writer object to use for output generation
s - The string to write
Throws:
java.io.IOException - On i/o error

writeln

protected void writeln(java.io.Writer writer,
                       java.lang.String s,
                       int indent)
                throws java.io.IOException
Writes a string to the output writer.

Parameters:
writer - Writer object to use for output generation
s - The string to write
indent - Indentation level
Throws:
java.io.IOException - On i/o error

getMaxSetSize

public int getMaxSetSize()
Gets the maximum size of a set to be dumped. Default: 10 elements


setMaxSetSize

public void setMaxSetSize(int maxSetSizeArg)
Sets the maximum size of a set to be dumped. Default: 10 elements


getSkipStatic

public boolean getSkipStatic()
Gets the flag that determines if to skip static data members. Default: true


setSkipStatic

public void setSkipStatic(boolean skipStaticArg)
Sets the flag that determines if to skip static data members. Default: true


getSkipNull

public boolean getSkipNull()
Gets the flag that determines if to skip null values. Default: true


setSkipNull

public void setSkipNull(boolean skipNullArg)
Sets the flag that determines if to skip null values. Default: true



Copyright © 2011. All Rights Reserved.