Clover coverage report - CRISPY - 1.1.1
Coverage timestamp: Mi Nov 15 2006 13:09:46 CET
file stats: LOC: 111   Methods: 4
NCLOC: 60   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InvocationHandler.java 100% 100% 100% 100%
coverage
 1    /*
 2    * Created on 17.05.2005 from Linke
 3    *
 4    */
 5    package net.sf.crispy.proxy;
 6   
 7    import java.lang.reflect.Method;
 8   
 9    import net.sf.crispy.Executor;
 10    import net.sf.crispy.InterceptorContext;
 11    import net.sf.crispy.InterceptorHandler;
 12   
 13    /**
 14    *
 15    * Handel Invocation from the DynamicProxy-implementation.
 16    * Intern call the InvocationHandler all registered Interceptors before and after the doInvoke-Method.
 17    *
 18    * @author Linke
 19    *
 20    */
 21    public final class InvocationHandler {
 22   
 23    /**
 24    *
 25    * This method must call from the DynamicProy-implementation.
 26    * The method invoke the <code>invokeIfExecutorIsNull</code> method from DynamicProxy-implementation.
 27    *
 28    * @param pvDynamicProxy Implementation of DynamicProxy
 29    * @param pvProxy the Proxy-Object
 30    * @param pvMethod the called Method
 31    * @param pvArgs the Args from called Method
 32    * @param pvElseObject implementation specific Object.
 33    * For example the Param-Object: MethodProxy bei @see net.sf.crispy.impl.DynamicCglibProxy Implementation.
 34    * Or <code>null</code>
 35    *
 36    * @return Result from the method-call
 37    *
 38    * @throws Throwable Error by the method-call
 39    *
 40    */
 41  845 public static Object doInvoke(DynamicProxy pvDynamicProxy, Object pvProxy, Method pvMethod, Object[] pvArgs,
 42    Object pvElseObject, final InterceptorHandler pvInterceptorHandler) throws Exception {
 43  845 Object ret = null;
 44  845 InterceptorContext lvInterceptorContext = new InterceptorContext(pvDynamicProxy, pvMethod, pvArgs, pvElseObject);
 45   
 46  845 if (pvInterceptorHandler == null) {
 47  1 throw new IllegalArgumentException ("The InvocationHandler has no InterceptorHandler (is null)!");
 48    }
 49   
 50    // modify the parameter or method
 51  844 InterceptorContext lvInterceptorContextModify = pvInterceptorHandler.fireBeforeModifyInvocation(lvInterceptorContext);
 52  844 boolean lvInterruptInvocationModifier = lvInterceptorContextModify.getInterruptInvocation();
 53    // end modify
 54  844 Method lvNewMethod = lvInterceptorContextModify.getMethod();
 55  844 Object lvNewArgs[] = lvInterceptorContextModify.getArgs();
 56  844 Object lvNewElseObject = lvInterceptorContextModify.getElseObject();
 57  844 DynamicProxy lvNewDynamicProxy = lvInterceptorContextModify.getDynamicProxy();
 58   
 59    // fire Method Invocation AFTER modifier
 60  844 boolean lvInterruptInvocationInterceptor = pvInterceptorHandler.fireBeforeMethodInvocation(lvInterceptorContext);
 61  844 try {
 62  844 boolean lvInterruptInvocation = false;
 63  844 if ((lvInterruptInvocationModifier == true) || (lvInterruptInvocationInterceptor == true)) {
 64  7 lvInterruptInvocation = true;
 65    }
 66   
 67    // !!! if interrupt true, then don't make the invocation !!!
 68  844 if (lvInterruptInvocation == true) {
 69  7 ret = lvInterceptorContext.getResult();
 70  7 if (ret instanceof Exception) {
 71  1 throw (Exception) ret;
 72    }
 73    } else {
 74   
 75  837 Executor lvExecutor = lvNewDynamicProxy.getExecutor();
 76  837 if (lvExecutor == null) {
 77  480 ret = lvNewDynamicProxy.invokeIfExecutorIsNull(pvProxy, lvNewMethod, lvNewArgs, lvNewElseObject);
 78    } else {
 79  357 ret = lvExecutor.execute(lvNewDynamicProxy.getProxyClass(), lvNewDynamicProxy.getProxyObject(), lvNewMethod, lvNewArgs);
 80    }
 81   
 82    }
 83   
 84    } catch (Exception e) {
 85  33 pvInterceptorHandler.fireOnError(e);
 86  33 throw e;
 87    }
 88    finally {
 89  844 lvInterceptorContext.setResult(ret);
 90    // modify the result
 91  844 InterceptorContext lvInterceptorContext2 = pvInterceptorHandler.fireAfterModifyInvocation(lvInterceptorContext);
 92  844 ret = lvInterceptorContext2.getResult();
 93   
 94  844 pvInterceptorHandler.fireAfterMethodInvocation(lvInterceptorContext);
 95    }
 96  810 return ret;
 97    }
 98   
 99  1 public static Object doInvoke(DynamicProxy pvDynamicProxy, Object pvProxy, Method pvMethod, Object[] pvArgs, Object pvElseObject) throws Exception {
 100  1 return doInvoke(pvDynamicProxy, pvProxy, pvMethod, pvArgs, pvElseObject, new InterceptorHandler());
 101    }
 102   
 103  842 public static Object doInvoke(DynamicProxy pvDynamicProxy, Object pvProxy, Method pvMethod, Object[] pvArgs, InterceptorHandler pvInterceptorHandler) throws Exception {
 104  842 return doInvoke(pvDynamicProxy, pvProxy, pvMethod, pvArgs, null, pvInterceptorHandler);
 105    }
 106   
 107  2 public static Object doInvoke(DynamicProxy pvDynamicProxy, Object pvProxy, Method pvMethod, Object[] pvArgs) throws Exception {
 108  2 return doInvoke(pvDynamicProxy, pvProxy, pvMethod, pvArgs, null, new InterceptorHandler());
 109    }
 110   
 111    }