KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > proxy > TestInterceptor


1 /*
2  * Copyright 2003 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.lang.reflect.Method JavaDoc;
20 import java.lang.reflect.Modifier JavaDoc;
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 JavaDoc {
27     String JavaDoc value;
28     
29     public String JavaDoc getValue() {
30         return value;
31     }
32      
33     public TestInterceptor(String JavaDoc ser) {
34         value = ser;
35     }
36    
37     public TestInterceptor() {
38     }
39
40     public Object JavaDoc intercept(Object JavaDoc obj, Method JavaDoc method, Object JavaDoc[] args, MethodProxy proxy) throws Throwable JavaDoc {
41         System.out.println( method );
42         Throwable JavaDoc e = null;
43         boolean invokedSuper = false;
44         Object JavaDoc retValFromSuper = null;
45         if (!Modifier.isAbstract(method.getModifiers()) &&
46             invokeSuper(obj, method, args)) {
47             invokedSuper = true;
48             try {
49                 retValFromSuper = proxy.invokeSuper(obj, args);
50             } catch (Throwable JavaDoc t) {
51                 e = t;
52             }
53         }
54         return afterReturn(obj, method, args, invokedSuper, retValFromSuper, e);
55     }
56     
57     public boolean invokeSuper(Object JavaDoc obj, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc {
58         return true;
59     }
60
61     public Object JavaDoc afterReturn(Object JavaDoc obj, Method JavaDoc method, Object JavaDoc[] args,
62                               boolean invokedSuper, Object JavaDoc retValFromSuper,
63                               Throwable JavaDoc e) throws Throwable JavaDoc {
64         if (e != null)
65             throw e.fillInStackTrace();
66         return retValFromSuper;
67     }
68 }
69
Popular Tags