1 22 package org.jboss.ejb3.stateful; 23 24 import java.lang.reflect.Method ; 25 import javax.ejb.EJBMetaData ; 26 import javax.ejb.HomeHandle ; 27 import org.jboss.aop.Dispatcher; 28 import org.jboss.aop.advice.Interceptor; 29 import org.jboss.aop.util.MethodHashing; 30 import org.jboss.aop.util.PayloadKey; 31 import org.jboss.aspects.remoting.InvokeRemoteInterceptor; 32 import org.jboss.ejb3.ProxyUtils; 33 import org.jboss.logging.Logger; 34 import org.jboss.remoting.InvokerLocator; 35 36 42 public class StatefulHomeRemoteProxy extends org.jboss.ejb3.session.BaseSessionRemoteProxy 43 { 44 private static final Logger log = Logger.getLogger(StatefulHomeRemoteProxy.class); 45 46 protected InvokerLocator uri; 47 private HomeHandle homeHandle; 48 private EJBMetaData ejbMetaData; 49 50 public StatefulHomeRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri) 51 { 52 super(containerId, interceptors); 53 this.uri = uri; 54 } 55 56 public StatefulHomeRemoteProxy(Object containerId, Interceptor[] interceptors, InvokerLocator uri, Object id) 57 { 58 super(containerId, interceptors); 59 this.uri = uri; 60 this.id = id; 61 } 62 63 protected StatefulHomeRemoteProxy() 64 { 65 } 66 67 public void setHandle(StatefulHandleImpl handle) 68 { 69 this.handle = handle; 70 handle.id = id; 71 } 72 73 public void setHomeHandle(HomeHandle homeHandle) 74 { 75 this.homeHandle = homeHandle; 76 } 77 78 public void setEjbMetaData(EJBMetaData ejbMetaData) 79 { 80 this.ejbMetaData = ejbMetaData; 81 } 82 83 public Object invoke(Object proxy, Method method, Object [] args) 84 throws Throwable 85 { 86 long hash = MethodHashing.calculateHash(method); 87 Object ret = ProxyUtils.handleCallLocally(hash, proxy, this, method, args); 88 if (ret != null) 89 { 90 return ret; 91 } 92 93 ret = handleEjb21CallLocally(method, args); 94 if (ret != null) 95 { 96 return ret; 97 } 98 99 StatefulRemoteInvocation sri = new StatefulRemoteInvocation(interceptors, hash, method, method, null, null); 100 sri.setArguments(args); 101 sri.setInstanceResolver(metadata); 102 sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS); 103 sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS); 104 sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS); 105 106 return sri.invokeNext(); 107 } 108 109 public Object getAsynchronousProxy(Object proxy) 110 { 111 throw new RuntimeException ("NOT IMPLEMENTED"); 112 } 113 114 public String toString() 115 { 116 return containerId.toString() + ":Home"; 117 } 118 119 private Object handleEjb21CallLocally(Method method, Object [] args) 120 { 121 if (method.equals(ProxyUtils.GET_HOME_HANDLE)) 122 { 123 return homeHandle; 124 } 125 else if (method.equals(ProxyUtils.GET_EJB_METADATA)) 126 { 127 return ejbMetaData; 128 } 129 130 return null; 131 } 132 } 133 | Popular Tags |