Coverage Report - org.kuali.rice.core.proxy.BaseInvocationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseInvocationHandler
0%
0/18
0%
0/8
3.25
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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  
 package org.kuali.rice.core.proxy;
 18  
 
 19  
 import java.lang.reflect.InvocationHandler;
 20  
 import java.lang.reflect.Method;
 21  
 
 22  
 import org.kuali.rice.core.util.ExceptionUtils;
 23  
 
 24  
 /**
 25  
  * An abstract base class for InvocationHanlders which can be used to implement
 26  
  * an InvocationHandler that delegates hashCode and equals methods to the proxied
 27  
  *
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  */
 30  0
 public abstract class BaseInvocationHandler implements InvocationHandler {
 31  
 
 32  
         // preloaded Method objects for the methods in java.lang.Object
 33  
     private static Method hashCodeMethod;
 34  
     private static Method equalsMethod;
 35  
     static {
 36  
         try {
 37  0
             hashCodeMethod = Object.class.getMethod("hashCode", (Class[])null);
 38  0
             equalsMethod = Object.class.getMethod("equals", new Class[] { Object.class });
 39  0
             } catch (NoSuchMethodException e) {
 40  0
                     throw new NoSuchMethodError(e.getMessage());
 41  0
             }
 42  0
     }
 43  
 
 44  
         public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable {
 45  0
                 Class declaringClass = method.getDeclaringClass();
 46  0
                 if (declaringClass == Object.class) {
 47  0
                     if (method.equals(hashCodeMethod)) {
 48  0
                             return proxyHashCode(proxy);
 49  0
                     } else if (method.equals(equalsMethod)) {
 50  0
                             return proxyEquals(proxy, arguments[0]);
 51  
                     } /*else if (m.equals(toStringMethod)) {
 52  
                         return proxyToString(proxy);
 53  
                     } else {
 54  
                         throw new InternalError(
 55  
                             "unexpected Object method dispatched: " + m);
 56  
                     }*/
 57  
                 }
 58  
                 try {
 59  0
                         return invokeInternal(proxy, method, arguments);
 60  0
                 } catch (Throwable t) {
 61  0
                         throw ExceptionUtils.unwrapActualCause(t);
 62  
                 }
 63  
         }
 64  
 
 65  
         protected abstract Object invokeInternal(Object proxy, Method method, Object[] arguments) throws Throwable;
 66  
 
 67  
         protected Integer proxyHashCode(Object proxy) {
 68  0
                 return new Integer(System.identityHashCode(proxy));
 69  
         }
 70  
 
 71  
         protected Boolean proxyEquals(Object proxy, Object other) {
 72  0
                 return (proxy == other ? Boolean.TRUE : Boolean.FALSE);
 73  
         }
 74  
 
 75  
 }