Coverage Report - org.apache.ojb.broker.util.interceptor.Interceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
Interceptor
N/A
N/A
1
 
 1  
 package org.apache.ojb.broker.util.interceptor;
 2  
 
 3  
 /* Copyright 2002-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 import java.lang.reflect.Method;
 19  
 
 20  
 //#ifdef JDK13
 21  
 import java.lang.reflect.InvocationHandler;
 22  
 //#else
 23  
 /*
 24  
 import com.develop.java.lang.reflect.InvocationHandler; 
 25  
 */
 26  
 //#endif
 27  
 /**
 28  
  * @author Thomas Mahler
 29  
  */
 30  
 public abstract class Interceptor implements InvocationHandler
 31  
 {
 32  
 
 33  
         private Object realSubject = null;
 34  
 
 35  
         /**
 36  
          * @see com.develop.java.lang.reflect.InvocationHandler#invoke(Object, Method, Object[])
 37  
          */
 38  
         public Object invoke(Object proxy, Method methodToBeInvoked, Object[] args) throws Throwable
 39  
         {
 40  
                 beforeInvoke(proxy, methodToBeInvoked, args);
 41  
                 Object result = null;
 42  
                 result = doInvoke(proxy, methodToBeInvoked, args);
 43  
                 afterInvoke(proxy, methodToBeInvoked, args);
 44  
                 return result;
 45  
         }
 46  
 
 47  
         /**
 48  
          * this method will be invoked before methodToBeInvoked is invoked
 49  
          */
 50  
         protected abstract void beforeInvoke(Object proxy, Method methodToBeInvoked, Object[] args)
 51  
                 throws Throwable;
 52  
 
 53  
         /**
 54  
          * this method will be invoked after methodToBeInvoked is invoked
 55  
          */
 56  
         protected abstract void afterInvoke(Object proxy, Method methodToBeInvoked, Object[] args)
 57  
                 throws Throwable;
 58  
 
 59  
         /**
 60  
          * this method will be invoked after methodToBeInvoked is invoked
 61  
          */
 62  
         protected Object doInvoke(Object proxy, Method methodToBeInvoked, Object[] args)
 63  
                 throws Throwable
 64  
         {
 65  
                 Method m =
 66  
                         getRealSubject().getClass().getMethod(
 67  
                                 methodToBeInvoked.getName(),
 68  
                                 methodToBeInvoked.getParameterTypes());
 69  
                 return m.invoke(getRealSubject(), args);
 70  
         }
 71  
 
 72  
         /**
 73  
          * Returns the realSubject.
 74  
          * @return Object
 75  
          */
 76  
         public Object getRealSubject()
 77  
         {
 78  
                 return realSubject;
 79  
         }
 80  
 
 81  
         /**
 82  
          * Sets the realSubject.
 83  
          * @param realSubject The realSubject to set
 84  
          */
 85  
         public void setRealSubject(Object realSubject)
 86  
         {
 87  
                 this.realSubject = realSubject;
 88  
         }
 89  
 
 90  
 }