1 23 package com.sun.enterprise.webservice; 24 25 import java.lang.UnsupportedOperationException ; 26 27 import java.lang.reflect.Method ; 28 import java.lang.reflect.Proxy ; 29 import java.lang.reflect.InvocationHandler ; 30 import java.lang.reflect.InvocationTargetException ; 31 32 import java.util.logging.Logger ; 33 import java.util.logging.Level ; 34 import com.sun.logging.LogDomains; 35 36 42 public class ServletImplInvocationHandler implements InvocationHandler { 43 44 private static Logger logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 45 46 private Object servletImplDelegate; 47 private Class servletImplClass; 48 49 public ServletImplInvocationHandler(Object delegate) { 50 servletImplDelegate = delegate; 51 servletImplClass = delegate.getClass(); 52 } 53 54 public Object invoke(Object proxy, Method method, Object [] args) 55 throws Throwable { 56 57 60 Class methodClass = method.getDeclaringClass(); 61 if( methodClass == java.lang.Object .class ) { 62 return invokeJavaObjectMethod(this, method, args); 63 } 64 65 Object returnValue = null; 66 67 try { 68 Method implMethod = servletImplClass.getMethod 71 (method.getName(), method.getParameterTypes()); 72 returnValue = implMethod.invoke(servletImplDelegate, args); 73 } catch(InvocationTargetException ite) { 74 logger.log(Level.FINE, "", ite); 75 throw ite.getCause(); 76 } catch(Throwable t) { 77 logger.log(Level.INFO, "Error invoking servlet impl", t); 78 throw t; 79 } 80 81 return returnValue; 82 } 83 84 private Object invokeJavaObjectMethod(InvocationHandler handler, 85 Method method, Object [] args) 86 throws Throwable { 87 88 Object returnValue = null; 89 90 97 switch( method.getName().charAt(0) ) { 98 case 'e' : 99 Object other = Proxy.isProxyClass(args[0].getClass()) ? 100 Proxy.getInvocationHandler(args[0]) : args[0]; 101 returnValue = new Boolean (handler.equals(other)); 102 break; 103 case 'h' : 104 returnValue = new Integer (handler.hashCode()); 105 break; 106 case 't' : 107 returnValue = handler.toString(); 108 break; 109 default : 110 throw new Throwable ("Object method " + method.getName() + 111 "not found"); 112 } 113 114 return returnValue; 115 } 116 117 } 118 | Popular Tags |