1 22 package org.jboss.proxy.ejb; 23 24 import java.lang.reflect.Method ; 25 import java.rmi.RemoteException ; 26 27 import org.jboss.invocation.Invocation; 28 import org.jboss.invocation.InvocationContext; 29 import org.jboss.invocation.InvocationKey; 30 import org.jboss.invocation.InvocationType; 31 import org.jboss.invocation.Invoker; 32 import org.jboss.proxy.ejb.handle.StatefulHandleImpl; 33 34 39 public class StatefulSessionInterceptor 40 extends GenericEJBInterceptor 41 { 42 43 private static final long serialVersionUID = -4333233488946091285L; 44 45 48 public StatefulSessionInterceptor() 49 { 50 } 51 52 54 59 public Object invoke(Invocation invocation) 60 throws Throwable 61 { 62 InvocationContext ctx = invocation.getInvocationContext(); 63 64 Method m = invocation.getMethod(); 65 66 if (m.equals(TO_STRING)) 68 { 69 return toString(ctx); 70 } 71 else if (m.equals(EQUALS)) 72 { 73 Object [] args = invocation.getArguments(); 74 String argsString = args[0] != null ? args[0].toString() : ""; 75 String thisString = toString(ctx); 76 return new Boolean (thisString.equals(argsString)); 77 } 78 else if (m.equals(HASH_CODE)) 79 { 80 return new Integer (ctx.getCacheId().hashCode()); 81 } 82 else if (m.equals(GET_HANDLE)) 84 { 85 int objectName = ((Integer ) ctx.getObjectName()).intValue(); 86 String jndiName = (String ) ctx.getValue(InvocationKey.JNDI_NAME); 87 Invoker invoker = ctx.getInvoker(); 88 Object id = ctx.getCacheId(); 89 return new StatefulHandleImpl( 90 objectName, 91 jndiName, 92 invoker, 93 ctx.getInvokerProxyBinding(), 94 id, 95 ctx.getValue("InvokerID")); 96 } 97 else if (m.equals(GET_EJB_HOME)) 98 { 99 return getEJBHome(invocation); 100 } 101 else if (m.equals(GET_PRIMARY_KEY)) 102 { 103 throw new RemoteException ("Call to getPrimaryKey not allowed on session bean"); 104 } 105 else if (m.equals(IS_IDENTICAL)) 106 { 107 Object [] args = invocation.getArguments(); 108 String argsString = args[0].toString(); 109 String thisString = toString(ctx); 110 return new Boolean (thisString.equals(argsString)); 111 } 112 else 114 { 115 invocation.setType(InvocationType.REMOTE); 117 118 invocation.setId(ctx.getCacheId()); 120 121 return getNext().invoke(invocation); 122 } 123 } 124 125 private String toString(InvocationContext ctx) 126 { 127 return ctx.getValue(InvocationKey.JNDI_NAME) + ":" + 128 ctx.getCacheId().toString(); 129 } 130 } 131 | Popular Tags |