1 22 package org.jboss.proxy.ejb; 23 24 import java.lang.reflect.Method ; 25 26 import org.jboss.invocation.Invocation; 27 import org.jboss.invocation.InvocationContext; 28 import org.jboss.invocation.InvocationKey; 29 import org.jboss.invocation.InvocationType; 30 import org.jboss.proxy.ejb.handle.EntityHandleImpl; 31 32 37 public class EntityInterceptor 38 extends GenericEJBInterceptor 39 { 40 41 private static final long serialVersionUID = 4399705304832568350L; 42 43 46 public EntityInterceptor() 47 {} 48 49 51 60 public Object invoke(Invocation invocation) 61 throws Throwable 62 { 63 InvocationContext ctx = invocation.getInvocationContext(); 64 65 Method m = invocation.getMethod(); 66 67 if (m.equals(TO_STRING)) 69 { 70 return toString(ctx); 71 } 72 else if (m.equals(EQUALS)) 73 { 74 Object [] args = invocation.getArguments(); 75 String argsString = args[0] != null ? args[0].toString() : ""; 76 String thisString = toString(ctx); 77 return new Boolean (thisString.equals(argsString)); 78 } 79 else if (m.equals(HASH_CODE)) 80 { 81 return new Integer (ctx.getCacheId().hashCode()); 82 } 83 else if (m.equals(GET_HANDLE)) 85 { 86 String jndiName = (String ) ctx.getValue(InvocationKey.JNDI_NAME); 87 Object id = ctx.getCacheId(); 88 return new EntityHandleImpl(jndiName, id); 89 } 90 else if (m.equals(GET_PRIMARY_KEY)) 91 { 92 return ctx.getCacheId(); 93 } 94 else if (m.equals(GET_EJB_HOME)) 95 { 96 return getEJBHome(invocation); 97 } 98 else if (m.equals(IS_IDENTICAL)) 99 { 100 Object [] args = invocation.getArguments(); 101 String argsString = args[0].toString(); 102 String thisString = toString(ctx); 103 return new Boolean (thisString.equals(argsString)); 104 } 105 else 107 { 108 invocation.setType(InvocationType.REMOTE); 110 invocation.setId(ctx.getCacheId()); 112 return getNext().invoke(invocation); 113 } 114 } 115 116 118 private String toString(InvocationContext ctx) 120 { 121 return ctx.getValue(InvocationKey.JNDI_NAME) + ":" + 122 ctx.getCacheId().toString(); 123 } 124 125 } 126 | Popular Tags |