1 22 package org.jboss.proxy; 23 24 import java.io.Externalizable ; 25 import java.lang.reflect.Method ; 26 27 import org.jboss.invocation.Invocation; 28 import org.jboss.invocation.Invoker; 29 import org.jboss.proxy.Interceptor; 30 31 38 public class ClientMethodInterceptor extends Interceptor 39 implements Externalizable 40 { 41 42 private static final long serialVersionUID = 6010013004557885014L; 43 44 50 public Object invoke(Invocation mi) throws Throwable 51 { 52 Method m = mi.getMethod(); 53 String methodName = m.getName(); 54 if (methodName.equals("toString")) 56 { 57 Object obj = getObject(mi); 58 return obj.toString(); 59 } 60 if (methodName.equals("equals")) 61 { 62 Object obj = getObject(mi); 63 Object [] args = mi.getArguments(); 64 String thisString = obj.toString(); 65 String argsString = args[0] == null ? "" : args[0].toString(); 66 return new Boolean (thisString.equals(argsString)); 67 } 68 if( methodName.equals("hashCode") ) 69 { 70 Object obj = getObject(mi); 71 return new Integer (obj.hashCode()); 72 } 73 74 return getNext().invoke(mi); 75 } 76 77 83 protected Object getObject(Invocation mi) 84 { 85 Object cacheId = mi.getInvocationContext().getCacheId(); 86 if (cacheId != null) 87 return cacheId; 88 else 89 return mi.getInvocationContext().getInvoker(); 90 } 91 92 } 93 | Popular Tags |