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 java.util.Iterator ; 31 import java.util.HashMap ; 32 import java.util.Map ; 33 import java.util.logging.Logger ; 34 import java.util.logging.Level ; 35 36 import javax.ejb.EJBContext ; 37 import javax.ejb.EJBException ; 38 import javax.ejb.EJBLocalObject ; 39 import com.sun.ejb.Invocation; 40 import com.sun.ejb.InvocationInfo; 41 import com.sun.ejb.Container; 42 import com.sun.ejb.codegen.WrapperGenerator; 43 import com.sun.ejb.containers.util.MethodMap; 44 import com.sun.enterprise.util.LocalStringManagerImpl; 45 import com.sun.logging.LogDomains; 46 import com.sun.ejb.spi.io.IndirectlySerializable; 47 48 54 55 public final class EJBLocalObjectInvocationHandler 56 extends EJBLocalObjectImpl implements InvocationHandler { 57 58 private static Logger logger = LogDomains.getLogger(LogDomains.EJB_LOGGER); 59 60 private static LocalStringManagerImpl localStrings = 61 new LocalStringManagerImpl(EJBLocalObjectInvocationHandler.class); 62 63 private Object proxy_; 66 67 private MethodMap invocationInfoMap_; 73 74 private Class localIntf_; 75 76 79 public EJBLocalObjectInvocationHandler(MethodMap invocationInfoMap, 80 Class localIntf) 81 throws Exception { 82 83 invocationInfoMap_ = invocationInfoMap; 84 85 localIntf_ = localIntf; 86 setIsLocalHomeView(true); 87 88 } 91 92 95 96 public EJBLocalObjectInvocationHandler(MethodMap invocationInfoMap) 97 throws Exception { 98 99 invocationInfoMap_ = invocationInfoMap; 100 101 setIsLocalHomeView(false); 102 103 } 106 107 public void setProxy(Object proxy) { 108 proxy_ = proxy; 109 } 110 111 public Object getClientObject() { 112 return proxy_; 113 } 114 115 118 public Object invoke(Object proxy, Method method, Object [] args) 119 throws Throwable { 120 121 return invoke(localIntf_, method, args); 122 } 123 124 Object invoke(Class clientInterface, Method method, Object [] args) 125 throws Throwable { 126 127 try { 130 container.onEnteringContainer(); 131 Class methodClass = method.getDeclaringClass(); 132 if( methodClass == java.lang.Object .class ) { 133 return InvocationHandlerUtil.invokeJavaObjectMethod(this, method, args); 134 } else if( methodClass == IndirectlySerializable.class ) { 135 return this.getSerializableObjectFactory(); 136 } 137 138 InvocationInfo invInfo = (InvocationInfo) 140 invocationInfoMap_.get(method, ((args != null) ? args.length : 0)); 141 142 if( invInfo == null ) { 143 throw new IllegalStateException ("Unknown method :" + method); 144 } 145 146 if( (methodClass == javax.ejb.EJBLocalObject .class) || 147 invInfo.ejbIntfOverride ) { 148 return invokeEJBLocalObjectMethod(method.getName(), args); 149 } else if( invInfo.targetMethod1 == null ) { 150 Object [] params = new Object [] 151 { invInfo.ejbName, "Local", invInfo.method.toString() }; 152 String errorMsg = localStrings.getLocalString 153 ("ejb.bean_class_method_not_found", "", params); 154 logger.log(Level.SEVERE, "ejb.bean_class_method_not_found", 155 params); 156 throw new EJBException (errorMsg); 157 } 158 159 161 Object returnValue = null; 162 163 Invocation inv = new Invocation(); 164 165 inv.isLocal = true; 166 inv.isBusinessInterface = !isLocalHomeView(); 167 inv.isHome = false; 168 inv.ejbObject = this; 169 inv.method = method; 170 inv.methodParams = args; 171 172 inv.clientInterface = clientInterface; 173 174 inv.transactionAttribute = invInfo.txAttr; 177 inv.securityPermissions = invInfo.securityPermissions; 178 inv.invocationInfo = invInfo; 179 inv.beanMethod = invInfo.targetMethod1; 180 181 try { 182 container.preInvoke(inv); 183 184 returnValue = container.intercept(inv); 185 186 } catch(InvocationTargetException ite) { 187 inv.exception = ite.getCause(); 188 inv.exceptionFromBeanMethod = inv.exception; 189 } catch(Throwable t) { 190 inv.exception = t; 191 } finally { 192 container.postInvoke(inv); 193 } 194 if (inv.exception != null) { 195 InvocationHandlerUtil.throwLocalException 196 (inv.exception, method.getExceptionTypes()); 197 } 198 199 return returnValue; 200 } finally { 201 container.onLeavingContainer(); 202 } 203 } 204 205 206 private Object invokeEJBLocalObjectMethod(String methodName, Object [] args) 207 throws Exception 208 { 209 Object returnValue = null; 211 212 switch(methodName.charAt(0)) { 215 case 'r' : 216 217 219 super.remove(); 220 break; 221 222 case 'i' : 223 224 226 EJBLocalObject other = (EJBLocalObject ) args[0]; 230 EJBLocalObjectImpl otherImpl = 231 EJBLocalObjectImpl.toEJBLocalObjectImpl(other); 232 233 returnValue = new Boolean (super.isIdentical(otherImpl)); 234 break; 235 236 case 'g' : 237 238 if( methodName.charAt(3) == 'E' ) { 239 returnValue = super.getEJBLocalHome(); 241 } else { 242 returnValue = super.getPrimaryKey(); 244 } 245 break; 246 247 default : 248 249 throw new EJBException ("unknown method = " + methodName); 250 } 251 252 return returnValue; 253 } 254 255 } 256 | Popular Tags |