1 /*
2 * Copyright (C) 2005 by Arno Schumacher
3 *
4 * This file is part of net.sourceforge.servletspy
5 *
6 * net.sourceforge.servletspy is free software; you can redistribute
7 * it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2, or (at your option) any later version.
10 *
11 * net.sourceforge.servletspy is distributed in the hope that it will
12 * be useful, but WITHOUT ANY WARRANTY; without even the implied
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
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 * (non-Javadoc)
36 *
37 * @see net.sourceforge.servletspy.IContextHandler#handle(net.sourceforge.servletspy.IContext)
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 }