1 23 package com.sun.ejb.containers; 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 import java.rmi.RemoteException ; 32 33 public final class InvocationHandlerUtil { 34 35 InvocationHandlerUtil() {} 36 37 static Object invokeJavaObjectMethod(InvocationHandler handler, 38 Method method, Object [] args) 39 throws EJBException { 40 41 Object returnValue = null; 42 43 50 switch( method.getName().charAt(0) ) { 51 case 'e' : 52 boolean result = false; 53 if (args[0] != null) { 54 Object other = Proxy.isProxyClass(args[0].getClass()) ? 55 Proxy.getInvocationHandler(args[0]) : args[0]; 56 result = handler.equals(other); 57 } 58 returnValue = new Boolean (result); 59 break; 60 case 'h' : 61 returnValue = new Integer (handler.hashCode()); 62 break; 63 case 't' : 64 returnValue = handler.toString(); 65 break; 66 default : 67 throw new EJBException (method.getName()); 68 } 69 70 return returnValue; 71 } 72 73 static boolean isDeclaredException(Throwable t, 74 Class [] declaredExceptions) 75 { 76 boolean declaredException = false; 77 78 for(int i = 0; i < declaredExceptions.length; i++) { 79 Class next = declaredExceptions[i]; 80 if( next.isAssignableFrom(t.getClass()) ) { 81 declaredException = true; 82 break; 83 } 84 } 85 86 return declaredException; 87 } 88 89 static void throwLocalException(Throwable t, 90 Class [] declaredExceptions) 91 throws Throwable 92 { 93 Throwable toThrow = t; 94 95 if( (t instanceof java.lang.RuntimeException ) || 96 (isDeclaredException(t, declaredExceptions)) ) { 97 toThrow = t; 98 } else { 99 toThrow = new EJBException (); 100 toThrow.initCause(t); 101 } 102 103 throw toThrow; 104 105 } 106 107 static void throwRemoteException(Throwable t, 108 Class [] declaredExceptions) 109 throws Throwable 110 { 111 Throwable toThrow = t; 112 113 if( (t instanceof java.lang.RuntimeException ) || 114 (t instanceof java.rmi.RemoteException ) || 115 (isDeclaredException(t, declaredExceptions)) ) { 116 toThrow = t; 117 } else { 118 toThrow = new RemoteException ("", t); 119 } 120 121 throw toThrow; 122 } 123 } 124 | Popular Tags |