01: /*
02: * Copyright 2003 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package net.sf.cglib.proxy;
17:
18: import java.io.Serializable;
19: import java.lang.reflect.Method;
20: import java.lang.reflect.Modifier;
21:
22: /**
23: *@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">baliuka@mwm.lt</a>
24: *@version $Id: TestInterceptor.java,v 1.3 2004/06/24 21:15:16 herbyderby Exp $
25: */
26: public class TestInterceptor implements MethodInterceptor, Serializable {
27: String value;
28:
29: public String getValue() {
30: return value;
31: }
32:
33: public TestInterceptor(String ser) {
34: value = ser;
35: }
36:
37: public TestInterceptor() {
38: }
39:
40: public Object intercept(Object obj, Method method, Object[] args,
41: MethodProxy proxy) throws Throwable {
42: System.out.println(method);
43: Throwable e = null;
44: boolean invokedSuper = false;
45: Object retValFromSuper = null;
46: if (!Modifier.isAbstract(method.getModifiers())
47: && invokeSuper(obj, method, args)) {
48: invokedSuper = true;
49: try {
50: retValFromSuper = proxy.invokeSuper(obj, args);
51: } catch (Throwable t) {
52: e = t;
53: }
54: }
55: return afterReturn(obj, method, args, invokedSuper,
56: retValFromSuper, e);
57: }
58:
59: public boolean invokeSuper(Object obj, Method method, Object[] args)
60: throws Throwable {
61: return true;
62: }
63:
64: public Object afterReturn(Object obj, Method method, Object[] args,
65: boolean invokedSuper, Object retValFromSuper, Throwable e)
66: throws Throwable {
67: if (e != null)
68: throw e.fillInStackTrace();
69: return retValFromSuper;
70: }
71: }
|