1 23 package com.sun.ejb.containers.util; 24 25 import java.lang.reflect.InvocationHandler ; 26 import java.lang.reflect.InvocationTargetException ; 27 import java.lang.reflect.Proxy ; 28 import java.lang.reflect.Method ; 29 30 import javax.ejb.EJBException ; 31 32 public final class InvocationHandlerUtil { 33 34 InvocationHandlerUtil() {} 35 36 public static Object invokeJavaObjectMethod(InvocationHandler handler, 37 Method method, Object [] args) 38 throws EJBException { 39 40 Object returnValue = null; 41 42 49 switch( method.getName().charAt(0) ) { 50 case 'e' : 51 Object other = Proxy.isProxyClass(args[0].getClass()) ? 52 Proxy.getInvocationHandler(args[0]) : args[0]; 53 returnValue = new Boolean (handler.equals(other)); 54 break; 55 case 'h' : 56 returnValue = new Integer (handler.hashCode()); 57 break; 58 case 't' : 59 returnValue = handler.toString(); 60 break; 61 default : 62 throw new EJBException (method.getName()); 63 } 64 65 return returnValue; 66 } 67 68 public static Throwable handleInvocationException(Throwable invException) { 69 70 Throwable toThrow = invException; 71 72 if (invException instanceof java.lang.RuntimeException ) { 73 toThrow = invException; 74 } else if (invException instanceof Exception ) { 75 toThrow = invException; 76 } else { 77 toThrow = new EJBException (invException.getMessage()); 78 } 79 80 return toThrow; 81 } 82 } 83 | Popular Tags |