1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sourceforge.servletspy.handler.container;
22
23 import java.lang.reflect.Field;
24 import java.lang.reflect.Modifier;
25 import java.lang.reflect.Proxy;
26
27 import net.sourceforge.servletspy.IContext;
28 import net.sourceforge.servletspy.handler.base.AbstractHandler;
29
30 /***
31 * @author arno schumacher
32 */
33 public final class BeanTransformer extends AbstractHandler {
34
35
36
37
38
39 public void handle(final IContext context) throws Exception {
40 final Object obj = context.getSubject();
41 final Class clazz = obj.getClass();
42
43 if (Proxy.isProxyClass(clazz)) {
44 return;
45 }
46
47 final Field[] fields = clazz.getDeclaredFields();
48 for (int i = 0; fields != null && i < fields.length; i++) {
49 final Field current = fields[i];
50 if (Modifier.isStatic(current.getModifiers())) {
51 continue;
52 }
53 final String key = current.getName();
54 current.setAccessible(true);
55 final Object prop = current.get(obj);
56 context.add(key, prop);
57 }
58 }
59 }