KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > reflection > ReflectionAspectTester


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.aop.reflection;
23
24 import org.jboss.aop.joinpoint.Invocation;
25 import org.jboss.aop.reflection.ReflectionAspect;
26
27 import java.lang.reflect.Constructor JavaDoc;
28 import java.lang.reflect.Field JavaDoc;
29
30 /**
31  * @author <a HREF="mailto:kabirkhan@bigfoot.com">Kabir Khan</a>
32  */

33
34 public class ReflectionAspectTester extends ReflectionAspect
35 {
36
37    public static Constructor JavaDoc constructor;
38    public static Field JavaDoc field;
39    public static Object JavaDoc[] args;
40    public static Object JavaDoc retObj;
41
42    public static void clear()
43    {
44       ReflectionAspectTester.constructor = null;
45       ReflectionAspectTester.field = null;
46       ReflectionAspectTester.args = null;
47       ReflectionAspectTester.retObj = null;
48    }
49
50    protected Object JavaDoc interceptConstructor(Invocation invocation,
51                                          Constructor JavaDoc constructor,
52                                          Object JavaDoc[] args)
53            throws Throwable JavaDoc
54    {
55
56       clear();
57       ReflectionAspectTester.constructor = constructor;
58       ReflectionAspectTester.args = args;
59
60       ReflectionAspectTester.retObj = super.interceptConstructor(invocation, constructor, args);
61       return ReflectionAspectTester.retObj;
62    }
63
64    protected Object JavaDoc interceptFieldRead(Invocation invocation,
65                                        Field JavaDoc field,
66                                        Object JavaDoc instance)
67            throws Throwable JavaDoc
68    {
69
70       clear();
71       ReflectionAspectTester.field = field;
72       ReflectionAspectTester.retObj = super.interceptFieldRead(invocation, field, instance);
73       return ReflectionAspectTester.retObj;
74    }
75
76    protected Object JavaDoc interceptFieldWrite(Invocation invocation,
77                                         Field JavaDoc field,
78                                         Object JavaDoc instance,
79                                         Object JavaDoc arg)
80            throws Throwable JavaDoc
81    {
82
83       clear();
84       ReflectionAspectTester.field = field;
85       ReflectionAspectTester.args = new Object JavaDoc[]{arg};
86       ReflectionAspectTester.retObj = super.interceptFieldWrite(invocation, field, instance, arg);
87       return ReflectionAspectTester.retObj;
88    }
89 }
90
Popular Tags