1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oness.common.all;
17
18 import java.lang.reflect.Field;
19 import java.text.DateFormat;
20 import java.util.Calendar;
21
22 import org.apache.commons.lang.builder.ToStringStyle;
23
24 /***
25 * Customized ReflectionToStringBuilder
26 *
27 * @see org.apache.commons.lang.builder.ReflectionToStringBuilder
28 *
29 * @author Carlos Sanchez
30 * @version $Revision: 1.1 $
31 */
32 public class ReflectionToStringBuilder extends
33 org.apache.commons.lang.builder.ReflectionToStringBuilder {
34
35 private static DateFormat formatter = DateFormat.getDateTimeInstance();
36
37 public ReflectionToStringBuilder(Object object) {
38 super(object, ToStringStyle.MULTI_LINE_STYLE);
39 }
40
41 /***
42 * Calendar fields are formatted with DateFormat.getDateTimeInstance()
43 * instead of using Calendar.toString().
44 *
45 * @see org.apache.commons.lang.builder.ReflectionToStringBuilder#getValue(java.lang.reflect.Field)
46 */
47 protected Object getValue(Field f) throws IllegalArgumentException,
48 IllegalAccessException {
49 Object value = super.getValue(f);
50
51 if (Calendar.class.isInstance(value)) {
52 Calendar c = (Calendar) value;
53 return formatter.format(c.getTime());
54 } else
55 return value;
56 }
57
58 }