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.Map ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 34 import java.util.logging.Logger ; 35 import java.util.logging.Level ; 36 37 import javax.ejb.EJBException ; 38 import javax.ejb.EJBLocalHome ; 39 import com.sun.ejb.Invocation; 40 import com.sun.ejb.InvocationInfo; 41 import com.sun.ejb.Container; 42 import com.sun.ejb.codegen.HomeGenerator; 43 import com.sun.enterprise.deployment.EjbDescriptor; 44 import com.sun.enterprise.deployment.EjbSessionDescriptor; 45 import com.sun.ejb.containers.util.MethodMap; 46 import com.sun.ejb.spi.io.IndirectlySerializable; 47 48 import com.sun.enterprise.util.LocalStringManagerImpl; 49 import com.sun.logging.LogDomains; 50 51 56 57 final class EJBLocalHomeInvocationHandler 58 extends ReadOnlyEJBLocalHomeImpl implements InvocationHandler { 59 60 private static Logger logger = 61 LogDomains.getLogger(LogDomains.EJB_LOGGER); 62 63 private static LocalStringManagerImpl localStrings = 64 new LocalStringManagerImpl(EJBLocalHomeInvocationHandler.class); 65 66 private boolean isStatelessSession_; 67 private boolean isEntity_; 68 69 private EJBLocalHome proxy_; 72 73 private Class localHomeIntfClass_; 74 75 private MethodMap invocationInfoMap_; 81 82 EJBLocalHomeInvocationHandler(EjbDescriptor ejbDescriptor, 83 Class localHomeIntf, 84 MethodMap invocationInfoMap) 85 throws Exception { 86 87 if( ejbDescriptor instanceof EjbSessionDescriptor ) { 88 isEntity_ = false; 89 isStatelessSession_ = 90 ((EjbSessionDescriptor)ejbDescriptor).isStateless(); 91 } else { 92 isStatelessSession_ = false; 93 isEntity_ = true; 94 } 95 96 invocationInfoMap_ = invocationInfoMap; 97 98 localHomeIntfClass_ = localHomeIntf; 99 100 } 103 104 public void setProxy(EJBLocalHome proxy) { 105 proxy_ = proxy; 106 } 107 108 protected EJBLocalHome getEJBLocalHome() { 109 return proxy_; 110 } 111 112 115 public Object invoke(Object proxy, Method method, Object [] args) 116 throws Throwable { 117 118 try { 121 ((BaseContainer) getContainer()).onEnteringContainer(); 122 123 Class methodClass = method.getDeclaringClass(); 124 125 if( methodClass == java.lang.Object .class ) { 126 return InvocationHandlerUtil.invokeJavaObjectMethod 127 (this, method, args); 128 } else if( methodClass == IndirectlySerializable.class ) { 129 return this.getSerializableObjectFactory(); 130 } else if( methodClass == ReadOnlyEJBLocalHome.class ) { 131 return super.getReadOnlyBeanLocalNotifier(); 133 } 134 135 InvocationInfo invInfo = (InvocationInfo) 137 invocationInfoMap_.get(method, ((args != null) ? args.length : 0) ); 138 139 if( invInfo == null ) { 140 throw new IllegalStateException ("Unknown method :" + method); 141 } 142 143 if( (methodClass == javax.ejb.EJBLocalHome .class) || 144 invInfo.ejbIntfOverride ) { 145 super.remove(args[0]); 147 return null; 148 149 } else if(methodClass == GenericEJBLocalHome.class) { 150 151 EJBLocalObjectImpl localImpl = 155 createEJBLocalBusinessObjectImpl(); 156 return localImpl.getClientObject((String ) args[0]); 157 158 } 159 160 EJBLocalObjectImpl localObjectImpl = null; 162 Object returnValue = null; 163 164 if( !isEntity_ && invInfo.startsWithCreate ) { 165 localObjectImpl = createEJBLocalObjectImpl(); 166 returnValue = localObjectImpl.getClientObject(); 167 } 168 169 if( !isStatelessSession_ ) { 170 171 if( invInfo.targetMethod1 == null ) { 172 173 Object [] params = new Object [] 174 { invInfo.ejbName, "LocalHome", 175 invInfo.method.toString() }; 176 String errorMsg = localStrings.getLocalString 177 ("ejb.bean_class_method_not_found", "", params); 178 logger.log(Level.SEVERE, "ejb.bean_class_method_not_found", 179 params); 180 throw new EJBException (errorMsg); 181 } 182 183 Invocation inv = new Invocation(); 184 185 inv.isLocal = true; 186 inv.isHome = true; 187 inv.method = method; 188 189 inv.clientInterface = localHomeIntfClass_; 190 191 inv.transactionAttribute = invInfo.txAttr; 194 inv.securityPermissions = invInfo.securityPermissions; 195 inv.invocationInfo = invInfo; 196 197 if( !isEntity_ && invInfo.startsWithCreate ) { 198 inv.ejbObject = (EJBLocalRemoteObject) localObjectImpl; 199 } 200 201 try { 202 203 container.preInvoke(inv); 204 205 if( invInfo.startsWithCreate ) { 206 207 Object ejbCreateReturnValue = container.invokeTargetBeanMethod( 208 invInfo.targetMethod1, inv, inv.ejb, args, null); 209 if( isEntity_ ) { 210 container.postCreate(inv, ejbCreateReturnValue); 211 container.invokeTargetBeanMethod(invInfo.targetMethod2, 212 inv, inv.ejb, args, null); 213 } 214 if( inv.ejbObject != null ) { 215 returnValue = ((EJBLocalObjectImpl)inv.ejbObject) 216 .getClientObject(); 217 } 218 } else if (invInfo.startsWithFindByPrimaryKey) { 219 EntityContainer entityContainer = (EntityContainer) container; 220 returnValue = entityContainer.invokeFindByPrimaryKey( 221 invInfo.targetMethod1, inv, args); 222 } else if ( invInfo.startsWithFind ) { 223 224 Object pKeys = container.invokeTargetBeanMethod(invInfo.targetMethod1, 225 inv, inv.ejb, args, null); 226 returnValue = container.postFind(inv, pKeys, null); 227 } else { 228 229 returnValue = container.invokeTargetBeanMethod(invInfo.targetMethod1, 230 inv, inv.ejb, args, null); 231 232 } 233 } catch(InvocationTargetException ite) { 234 inv.exception = ite.getCause(); 235 } catch(Throwable c) { 236 inv.exception = c; 237 } finally { 238 container.postInvoke(inv); 239 } 240 241 if (inv.exception != null) { 242 InvocationHandlerUtil.throwLocalException 243 (inv.exception, method.getExceptionTypes()); 244 } 245 } 246 247 return returnValue; 248 } finally { 249 ((BaseContainer) getContainer()).onLeavingContainer(); 250 } 251 } 252 } 253 | Popular Tags |