| | 199 | /** |
| | 200 | * Tries to read additional property like information from this throwable |
| | 201 | * and fills it in a map suitable for detailed information output. |
| | 202 | * @param thr the throwable to analyze. |
| | 203 | * @return a Map pointing from String property names to the value. |
| | 204 | */ |
| | 205 | public static Map/*<String, Object>*/ getProperties(Throwable thr) |
| | 206 | { |
| | 207 | final Map/*<String, Object>*/ result = new HashMap(); |
| | 208 | final Method[] methods = thr.getClass().getMethods(); |
| | 209 | for (int i = 0; i < methods.length; i++) |
| | 210 | { |
| | 211 | final int modifier = methods[i].getModifiers(); |
| | 212 | if (methods[i].getDeclaringClass() != Throwable.class |
| | 213 | && methods[i].getDeclaringClass() != Object.class |
| | 214 | && methods[i].getParameterTypes().length == 0 |
| | 215 | && Modifier.isPublic(modifier) |
| | 216 | && !Modifier.isStatic(modifier) |
| | 217 | && !methods[i].getReturnType().equals(Void.TYPE)) |
| | 218 | { |
| | 219 | try |
| | 220 | { |
| | 221 | if (methods[i].getName().startsWith(GETTER_METHOD_PREFIX)) |
| | 222 | { |
| | 223 | final Object value |
| | 224 | = methods[i].invoke(thr, (Object[]) null); |
| | 225 | final String key |
| | 226 | = methods[i].getName().substring( |
| | 227 | GETTER_METHOD_PREFIX_LENGTH); |
| | 228 | result.put(key, value); |
| | 229 | } |
| | 230 | else if (methods[i].getName().startsWith( |
| | 231 | BOOLEAN_GETTER_METHOD_PREFIX) |
| | 232 | && (methods[i].getReturnType().equals(Boolean.class) |
| | 233 | || methods[i].getReturnType().equals( |
| | 234 | java.lang.Boolean.TYPE))) |
| | 235 | { |
| | 236 | final Object value |
| | 237 | = methods[i].invoke(thr, (Object[]) null); |
| | 238 | final String key |
| | 239 | = methods[i].getName().substring( |
| | 240 | BOOLEAN_GETTER_METHOD_PREFIX_LENGTH); |
| | 241 | result.put(key, value); |
| | 242 | } |
| | 243 | } |
| | 244 | catch (InvocationTargetException e) |
| | 245 | { |
| | 246 | // Ignore this property, continue with next |
| | 247 | } |
| | 248 | catch (IllegalArgumentException e) |
| | 249 | { |
| | 250 | // Ignore this property, continue with next |
| | 251 | } |
| | 252 | catch (IllegalAccessException e) |
| | 253 | { |
| | 254 | // Ignore this property, continue with next |
| | 255 | } |
| | 256 | } |
| | 257 | } |
| | 258 | return result; |
| | 259 | } |
| | 260 | |