public class ToStringBean
extends java.lang.Object
implements java.io.Serializable
It works on all read/write properties, recursively. It support all primitive types, Strings, Collections, ToString objects and multi-dimensional arrays of any of them.
Modifier and Type | Field and Description |
---|---|
private java.lang.Class |
_beanClass |
private java.lang.Object |
_obj |
private static java.lang.Object[] |
NO_PARAMS |
private static java.lang.ThreadLocal |
PREFIX_TL |
Modifier | Constructor and Description |
---|---|
protected |
ToStringBean(java.lang.Class beanClass)
Default constructor.
|
|
ToStringBean(java.lang.Class beanClass,
java.lang.Object obj)
Creates a ToStringBean to be used in a delegation pattern.
|
Modifier and Type | Method and Description |
---|---|
private void |
printArrayProperty(java.lang.StringBuffer sb,
java.lang.String prefix,
java.lang.Object array) |
private void |
printProperty(java.lang.StringBuffer sb,
java.lang.String prefix,
java.lang.Object value) |
java.lang.String |
toString()
Returns the String representation of the bean given in the constructor.
|
private java.lang.String |
toString(java.lang.String prefix)
Returns the String representation of the bean given in the constructor.
|
private static final java.lang.ThreadLocal PREFIX_TL
private static final java.lang.Object[] NO_PARAMS
private java.lang.Class _beanClass
private java.lang.Object _obj
protected ToStringBean(java.lang.Class beanClass)
To be used by classes extending ToStringBean only.
beanClass
- indicates the class to scan for properties, normally an interface class.public ToStringBean(java.lang.Class beanClass, java.lang.Object obj)
For example:
public class Foo implements ToString {
public String toString(String prefix) {
ToStringBean tsb = new ToStringBean(this);
return tsb.toString(prefix);
}
public String toString() {
return toString("Foo");
}
}
beanClass
- indicates the class to scan for properties, normally an interface class.obj
- object bean to create String representation.public java.lang.String toString()
It uses the Class name as the prefix.
toString
in class java.lang.Object
private java.lang.String toString(java.lang.String prefix)
prefix
- to use for bean properties.private void printProperty(java.lang.StringBuffer sb, java.lang.String prefix, java.lang.Object value)
private void printArrayProperty(java.lang.StringBuffer sb, java.lang.String prefix, java.lang.Object array)
Copyright © Sun Microsystems. All Rights Reserved.