in core/src/main/java/flex/messaging/util/ToStringPrettyPrinter.java [75:172]
protected void prettifyComplexType(Object o) {
// Avoid circular references
if (!isKnownObject(o)) {
StringBuffer header = new StringBuffer();
Class c = o.getClass();
if (hasCustomToStringMethod(c)) {
trace.write(String.valueOf(o));
} else if (o instanceof Collection) {
Collection col = ((Collection) o);
header.append(c.getName()).append(" (Collection size:").append(col.size()).append(")");
trace.startArray(header.toString());
Iterator it = col.iterator();
int i = 0;
while (it.hasNext()) {
trace.arrayElement(i);
internalPrettify(it.next());
trace.newLine();
i++;
}
trace.endArray();
} else if (c.isArray()) {
Class componentType = c.getComponentType();
int count = Array.getLength(o);
header.append(componentType.getName()).append("[] (Array length:").append(count).append(")");
trace.startArray(header.toString());
// Check whether it is primitive array case, we omit printing the content of primitive array
// To avoid cases like large byte array.
if (!componentType.isPrimitive()) {
for (int i = 0; i < count; i++) {
trace.arrayElement(i);
internalPrettify(Array.get(o, i));
trace.newLine();
}
}
trace.endArray();
} else if (o instanceof Document) {
try {
String xml = XMLUtil.documentToString((Document) o);
trace.write(xml);
} catch (IOException ex) {
trace.write("(Document not printable)");
}
} else {
PropertyProxy proxy = PropertyProxyRegistry.getProxy(o);
if (o instanceof PrettyPrintable) {
PrettyPrintable pp = (PrettyPrintable) o;
header.append(pp.toStringHeader());
} else {
header.append(c.getName());
if (o instanceof Map) {
header.append(" (Map size:").append(((Map) o).size()).append(")");
}
}
trace.startObject(header.toString());
List propertyNames = proxy.getPropertyNames();
if (propertyNames != null) {
Iterator it = propertyNames.iterator();
while (it.hasNext()) {
String propName = (String) it.next();
trace.namedElement(propName);
Object value = null;
if (trace.nextElementExclude) {
trace.nextElementExclude = false;
value = Log.VALUE_SUPRESSED;
} else {
if (o instanceof PrettyPrintable) {
String customToString = ((PrettyPrintable) o).toStringCustomProperty(propName);
if (customToString != null) {
value = customToString;
}
}
if (value == null) {
value = proxy.getValue(propName);
}
}
internalPrettify(value);
trace.newLine();
}
}
trace.endObject();
}
}
}