2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind-examples release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:34:25 PST
file stats: LOC: 75   Methods: 2
NCLOC: 41   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ProxyLoggingInvocationHandler.java 0% 0% 0% 0%
coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.examples.impl;
 16   
 17    import java.lang.reflect.InvocationHandler;
 18    import java.lang.reflect.InvocationTargetException;
 19    import java.lang.reflect.Method;
 20   
 21    import org.apache.commons.logging.Log;
 22    import org.apache.hivemind.service.impl.LoggingUtils;
 23   
 24    /**
 25    * An invocation handler used by {@link org.apache.examples.impl.ProxyLoggingInterceptorFactory}.
 26    * Logs all method invocations, return values and exceptions. Note that, unlike the real
 27    * LoggingInterceptor, <code>toString()</code> will just pass through to the delegate service object
 28    * (typically, the core service implementation).
 29    *
 30    * @author Howard Lewis Ship
 31    */
 32    public class ProxyLoggingInvocationHandler implements InvocationHandler
 33    {
 34    private Log _log;
 35    private Object _delegate;
 36   
 37  0 public ProxyLoggingInvocationHandler(Log log, Object delegate)
 38    {
 39  0 _log = log;
 40  0 _delegate = delegate;
 41    }
 42   
 43  0 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
 44    {
 45  0 boolean debug = _log.isDebugEnabled();
 46   
 47  0 if (debug)
 48  0 LoggingUtils.entry(_log, method.getName(), args);
 49   
 50  0 try
 51    {
 52  0 Object result = method.invoke(_delegate, args);
 53   
 54  0 if (debug)
 55    {
 56  0 if (method.getReturnType() == void.class)
 57  0 LoggingUtils.voidExit(_log, method.getName());
 58    else
 59  0 LoggingUtils.exit(_log, method.getName(), result);
 60    }
 61   
 62  0 return result;
 63    }
 64    catch (InvocationTargetException ex)
 65    {
 66  0 Throwable targetException = ex.getTargetException();
 67   
 68  0 if (debug)
 69  0 LoggingUtils.exception(_log, method.getName(), targetException);
 70   
 71  0 throw targetException;
 72    }
 73    }
 74   
 75    }