in tapestry-framework/src/org/apache/tapestry/util/exception/ExceptionAnalyzer.java [118:226]
protected Throwable buildDescription(Throwable exception)
{
BeanInfo info;
Class exceptionClass;
ExceptionProperty property;
PropertyDescriptor[] descriptors;
PropertyDescriptor descriptor;
Throwable next = null;
int i;
Object value;
Method method;
ExceptionProperty[] properties;
ExceptionDescription description;
String stringValue;
String message;
String[] stackTrace = null;
propertyDescriptions.clear();
message = exception.getMessage();
exceptionClass = exception.getClass();
// Get properties, ignoring those in Throwable and higher
// (including the 'message' property).
try
{
info = Introspector.getBeanInfo(exceptionClass, Throwable.class);
}
catch (IntrospectionException e)
{
return null;
}
descriptors = info.getPropertyDescriptors();
for (i = 0; i < descriptors.length; i++)
{
descriptor = descriptors[i];
method = descriptor.getReadMethod();
if (method == null)
continue;
try
{
value = method.invoke(exception, null);
}
catch (Exception e)
{
continue;
}
if (value == null)
continue;
// Some annoying exceptions duplicate the message property
// (I'm talking to YOU SAXParseException), so just edit that out.
if (message != null && message.equals(value))
continue;
// Skip Throwables ... but the first non-null
// found is the next exception. We kind of count
// on there being no more than one Throwable
// property per Exception.
if (value instanceof Throwable)
{
if (next == null)
next = (Throwable) value;
continue;
}
stringValue = value.toString().trim();
if (stringValue.length() == 0)
continue;
property = new ExceptionProperty(descriptor.getDisplayName(), value.toString());
propertyDescriptions.add(property);
}
// If exhaustive, or in the deepest exception (where there's no next)
// the extract the stack trace.
if (next == null || exhaustive)
stackTrace = getStackTrace(exception);
// Would be nice to sort the properties here.
properties = new ExceptionProperty[propertyDescriptions.size()];
ExceptionProperty[] propArray =
(ExceptionProperty[]) propertyDescriptions.toArray(properties);
description =
new ExceptionDescription(
exceptionClass.getName(),
message,
propArray,
stackTrace);
exceptionDescriptions.add(description);
return next;
}